1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 17 #define ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 18 19 #include <memory> 20 21 #include "libpandabase/macros.h" 22 23 namespace panda::ecmascript { 24 class EcmaVM; 25 class TaggedObject; 26 class Progress; 27 class Stream; 28 struct SamplingInfo; 29 30 enum class DumpFormat { JSON, BINARY, OTHER }; 31 32 class HeapProfilerInterface { 33 public: 34 static HeapProfilerInterface *GetInstance(EcmaVM *vm); 35 static void Destroy(EcmaVM *vm); 36 37 HeapProfilerInterface() = default; 38 virtual ~HeapProfilerInterface() = default; 39 40 virtual size_t GetIdCount() = 0; 41 virtual void AllocationEvent(TaggedObject *address, size_t size) = 0; 42 virtual void MoveEvent(uintptr_t address, TaggedObject *forwardAddress, size_t size)= 0; 43 virtual bool DumpHeapSnapshot(DumpFormat dumpFormat, Stream *stream, Progress *progress = nullptr, 44 bool isVmMode = true, bool isPrivate = false, bool captureNumericValue = false) = 0; 45 46 virtual bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr, 47 bool traceAllocation = false, bool newThread = true) = 0; 48 virtual bool UpdateHeapTracking(Stream *stream) = 0; 49 virtual bool StopHeapTracking(Stream *stream, Progress *progress = nullptr, bool newThread = true) = 0; 50 virtual bool StartHeapSampling(uint64_t samplingInterval, int stackDepth = 128) = 0; 51 virtual void StopHeapSampling() = 0; 52 virtual const struct SamplingInfo *GetAllocationProfile() = 0; 53 54 NO_MOVE_SEMANTIC(HeapProfilerInterface); 55 NO_COPY_SEMANTIC(HeapProfilerInterface); 56 }; 57 } // namespace panda::ecmascript 58 #endif // ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H 59