1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
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
17 #include "napi_hidebug_gc.h"
18 #include "native_engine/native_engine.h"
19
20 namespace OHOS {
21 namespace HiviewDFX {
GetGcCount(napi_env env)22 napi_value GC::GetGcCount(napi_env env)
23 {
24 NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
25 napi_value gcCount;
26 napi_create_bigint_uint64(env, engine->GetGCCount(), &gcCount);
27 return gcCount;
28 }
29
GetGcTime(napi_env env)30 napi_value GC::GetGcTime(napi_env env)
31 {
32 NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
33 napi_value gcTime;
34 napi_create_bigint_uint64(env, engine->GetGCDuration(), &gcTime);
35 return gcTime;
36 }
37
GetGcBytesAllocated(napi_env env)38 napi_value GC::GetGcBytesAllocated(napi_env env)
39 {
40 NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
41 napi_value gcBytesAllocated;
42 napi_create_bigint_uint64(env, engine->GetAccumulatedAllocateSize(), &gcBytesAllocated);
43 return gcBytesAllocated;
44 }
45
GetGcBytesFreed(napi_env env)46 napi_value GC::GetGcBytesFreed(napi_env env)
47 {
48 NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
49 napi_value gcBytesFreed;
50 napi_create_bigint_uint64(env, engine->GetAccumulatedFreeSize(), &gcBytesFreed);
51 return gcBytesFreed;
52 }
53
GetFullGcLongTimeCount(napi_env env)54 napi_value GC::GetFullGcLongTimeCount(napi_env env)
55 {
56 NativeEngine *engine = reinterpret_cast<NativeEngine*>(env);
57 napi_value fullGcLongTimeCount;
58 napi_create_bigint_uint64(env, engine->GetFullGCLongTimeCount(), &fullGcLongTimeCount);
59 return fullGcLongTimeCount;
60 }
61
62 std::map<std::string, napi_value (*)(napi_env value)> GC::vmGcMap_ {
63 {"ark.gc.gc-count", GC::GetGcCount},
64 {"ark.gc.gc-time", GC::GetGcTime},
65 {"ark.gc.gc-bytes-allocated", GC::GetGcBytesAllocated},
66 {"ark.gc.gc-bytes-freed", GC::GetGcBytesFreed},
67 {"ark.gc.fullgc-longtime-count", GC::GetFullGcLongTimeCount},
68 };
69 }
70 }