1 /* 2 * Copyright (c) 2021 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_HPROF_HEAP_PROFILER_INTERFACE_H 17 #define ECMASCRIPT_HPROF_HEAP_PROFILER_INTERFACE_H 18 19 #include "ecmascript/mem/c_string.h" 20 #include "ecmascript/js_thread.h" 21 22 namespace panda::ecmascript { 23 enum class DumpFormat { JSON, BINARY, OTHER }; 24 25 class HeapProfilerInterface { 26 public: 27 static HeapProfilerInterface *GetInstance(JSThread *thread); 28 static void DumpHeapSnapShot(JSThread *thread, DumpFormat dumpFormat, 29 const std::string &filePath, bool isVmMode = true); 30 31 static HeapProfilerInterface *CreateHeapProfiler(JSThread *thread); 32 static void Destroy(JSThread *thread, HeapProfilerInterface *heapProfiler); 33 34 HeapProfilerInterface() = default; 35 virtual ~HeapProfilerInterface() = default; 36 37 virtual bool StartHeapTracking(JSThread *thread, double timeInterval, bool isVmMode = true) = 0; 38 virtual bool StopHeapTracking(JSThread *thread, DumpFormat dumpFormat, const std::string &filePath) = 0; 39 40 NO_MOVE_SEMANTIC(HeapProfilerInterface); 41 NO_COPY_SEMANTIC(HeapProfilerInterface); 42 private: 43 static HeapProfilerInterface *heapProfile_; 44 }; 45 } // namespace panda::ecmascript 46 #endif // ECMASCRIPT_HPROF_HEAP_PROFILER_INTERFACE_H 47