14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include <memory> 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_ci#include "libpandabase/macros.h" 224514f5e3Sopenharmony_ci 234514f5e3Sopenharmony_cinamespace panda::ecmascript { 244514f5e3Sopenharmony_ciclass EcmaVM; 254514f5e3Sopenharmony_ciclass TaggedObject; 264514f5e3Sopenharmony_ciclass Progress; 274514f5e3Sopenharmony_ciclass Stream; 284514f5e3Sopenharmony_cistruct SamplingInfo; 294514f5e3Sopenharmony_cienum class DumpFormat { JSON, BINARY, OTHER }; 304514f5e3Sopenharmony_cistruct DumpSnapShotOption { 314514f5e3Sopenharmony_ci DumpFormat dumpFormat; // dumpformat like JSON BINARY and OTHER 324514f5e3Sopenharmony_ci bool isVmMode = true; // vmMode do more dump. 334514f5e3Sopenharmony_ci bool isPrivate = false; 344514f5e3Sopenharmony_ci bool captureNumericValue = false; // heapdump add numeric object. 354514f5e3Sopenharmony_ci bool isFullGC = true; // whether do FullGC. 364514f5e3Sopenharmony_ci bool isSimplify = false; // whether trim heapdump snapshot. 374514f5e3Sopenharmony_ci bool isSync = true; // OOM and Ide dump need sync dump. 384514f5e3Sopenharmony_ci bool isBeforeFill = true; // whether do fillmap on main thread. 394514f5e3Sopenharmony_ci bool isDumpOOM = false; // whether dump oom heapdump. 404514f5e3Sopenharmony_ci}; 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_ciclass HeapProfilerInterface { 434514f5e3Sopenharmony_cipublic: 444514f5e3Sopenharmony_ci static HeapProfilerInterface *GetInstance(EcmaVM *vm); 454514f5e3Sopenharmony_ci static void Destroy(EcmaVM *vm); 464514f5e3Sopenharmony_ci 474514f5e3Sopenharmony_ci HeapProfilerInterface() = default; 484514f5e3Sopenharmony_ci virtual ~HeapProfilerInterface() = default; 494514f5e3Sopenharmony_ci 504514f5e3Sopenharmony_ci virtual size_t GetIdCount() = 0; 514514f5e3Sopenharmony_ci virtual void AllocationEvent(TaggedObject *address, size_t size) = 0; 524514f5e3Sopenharmony_ci virtual void MoveEvent(uintptr_t address, TaggedObject *forwardAddress, size_t size)= 0; 534514f5e3Sopenharmony_ci virtual bool DumpHeapSnapshot(Stream *stream, const DumpSnapShotOption &dumpOption, 544514f5e3Sopenharmony_ci Progress *progress = nullptr) = 0; 554514f5e3Sopenharmony_ci // Provide an internal interface for oom dump. 564514f5e3Sopenharmony_ci virtual void DumpHeapSnapshot(const DumpSnapShotOption &dumpOption) = 0; 574514f5e3Sopenharmony_ci virtual bool GenerateHeapSnapshot(std::string &inputFilePath, std::string &outputPath) = 0; 584514f5e3Sopenharmony_ci 594514f5e3Sopenharmony_ci virtual bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr, 604514f5e3Sopenharmony_ci bool traceAllocation = false, bool newThread = true) = 0; 614514f5e3Sopenharmony_ci virtual bool UpdateHeapTracking(Stream *stream) = 0; 624514f5e3Sopenharmony_ci virtual bool StopHeapTracking(Stream *stream, Progress *progress = nullptr, bool newThread = true) = 0; 634514f5e3Sopenharmony_ci virtual bool StartHeapSampling(uint64_t samplingInterval, int stackDepth = 128) = 0; 644514f5e3Sopenharmony_ci virtual void StopHeapSampling() = 0; 654514f5e3Sopenharmony_ci virtual const struct SamplingInfo *GetAllocationProfile() = 0; 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_ci NO_MOVE_SEMANTIC(HeapProfilerInterface); 684514f5e3Sopenharmony_ci NO_COPY_SEMANTIC(HeapProfilerInterface); 694514f5e3Sopenharmony_ci}; 704514f5e3Sopenharmony_ci} // namespace panda::ecmascript 714514f5e3Sopenharmony_ci#endif // ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 72