* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H
#define ECMASCRIPT_DFX_HPROF_HEAP_PROFILER_INTERFACE_H
#include <functional>
#include <memory>
#include "libpandabase/macros.h"
namespace panda::ecmascript {
class EcmaVM;
class TaggedObject;
class Progress;
class Stream;
struct SamplingInfo;
enum class DumpFormat { JSON, BINARY, OTHER };
enum class LanguageEnv : uint8_t { DYNAMIC = 0, STATIC = 1, HYBRID = 2 };
struct DumpSnapShotOption {
DumpFormat dumpFormat;
bool isVmMode = true;
bool isPrivate = false;
bool captureNumericValue = false;
int32_t nativeAddrToNodeIdMap = 0;
bool isFullGC = true;
bool isSimplify = false;
bool isSync = true;
bool isBeforeFill = true;
bool isDumpOOM = false;
bool isJSLeakWatcher = false;
bool isForSharedOOM = false;
bool isProcDump = false;
bool isClearNodeIdCache = false;
bool dumpDynamicHeap = false;
bool dumpStaticHeap = false;
std::string spaceType = "";
std::string heapType = "";
LanguageEnv languageEnv = LanguageEnv::DYNAMIC;
};
enum class RawHeapDumpCropLevel {
LEVEL_V1,
LEVEL_V2,
DEFAULT = LEVEL_V1
};
class HeapProfilerInterface {
public:
static HeapProfilerInterface *GetInstance(EcmaVM *vm);
static void Destroy(EcmaVM *vm);
static HeapProfilerInterface *CreateNewInstance(const EcmaVM *vm);
static void DestroyInstance(HeapProfilerInterface *heapProfiler);
static void DumpHeapSnapshotForCMCOOM(void *thread);
HeapProfilerInterface() = default;
virtual ~HeapProfilerInterface() = default;
virtual size_t GetIdCount() = 0;
virtual void AllocationEvent(TaggedObject *address, size_t size) = 0;
virtual void MoveEvent(uintptr_t address, TaggedObject *forwardAddress, size_t size)= 0;
virtual bool DumpHeapSnapshot(Stream *stream, const DumpSnapShotOption &dumpOption,
Progress *progress = nullptr,
std::function<void(uint8_t)> callback = [] (uint8_t) {}) = 0;
virtual void DumpHeapSnapshotForOOM(const DumpSnapShotOption &dumpOption, bool fromSharedGC = false) = 0;
virtual bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr,
bool traceAllocation = false, bool newThread = true) = 0;
virtual bool UpdateHeapTracking(Stream *stream) = 0;
virtual bool StopHeapTracking(Stream *stream, Progress *progress = nullptr, bool newThread = true) = 0;
virtual bool StartHeapSampling(uint64_t samplingInterval, int stackDepth = 128) = 0;
virtual void StopHeapSampling() = 0;
virtual const struct SamplingInfo *GetAllocationProfile() = 0;
NO_MOVE_SEMANTIC(HeapProfilerInterface);
NO_COPY_SEMANTIC(HeapProfilerInterface);
};
}
#endif