1/*
2 * Copyright (c) 2024 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 HIDEBUG_FFI_H
17#define HIDEBUG_FFI_H
18
19#include <cstdint>
20#include "cj_ffi/cj_common_ffi.h"
21
22extern "C" {
23    struct CSystemMemInfo {
24        uint64_t totalMem;
25        uint64_t freeMem;
26        uint64_t availableMem;
27    };
28
29    struct CThreadCpuUsage {
30        uint32_t threadId;
31        double cpuUsage;
32    };
33
34    struct ThreadCpuUsageArr {
35        CThreadCpuUsage *head;
36        int64_t size;
37    };
38
39    struct CNativeMemInfo {
40        uint64_t pss;
41        uint64_t vss;
42        uint64_t rss;
43        uint64_t sharedDirty;
44        uint64_t privateDirty;
45        uint64_t sharedClean;
46        uint64_t privateClean;
47    };
48
49    struct CMemoryLimit {
50        uint64_t rssLimit;
51        uint64_t vssLimit;
52    };
53
54    FFI_EXPORT uint64_t FfiHidebugGetPss();
55    FFI_EXPORT uint64_t FfiHidebugGetVss();
56    FFI_EXPORT uint64_t FfiHidebugGetNativeHeapSize();
57    FFI_EXPORT uint64_t FfiHidebugGetNativeHeapAllocatedSize();
58    FFI_EXPORT uint64_t FfiHidebugGetNativeHeapFreeSize();
59    FFI_EXPORT uint64_t FfiHidebugGetSharedDirty();
60    FFI_EXPORT uint64_t FfiHidebugGetPrivateDirty();
61    FFI_EXPORT double FfiHidebugGetCpuUsage();
62    FFI_EXPORT double FfiHidebugGetSystemCpuUsage(int32_t &code);
63    FFI_EXPORT ThreadCpuUsageArr FfiHidebugGetAppThreadCpuUsage(int32_t &code);
64    FFI_EXPORT CSystemMemInfo FfiHidebugGetSystemMemInfo(int32_t &code);
65    FFI_EXPORT CNativeMemInfo FfiHidebugGetAppNativeMemInfo(int32_t &code);
66    FFI_EXPORT CMemoryLimit FfiHidebugGetAppMemoryLimit(int32_t &code);
67    FFI_EXPORT int32_t FfiHidebugGetServiceDump(int32_t serviceId, int32_t fd, CArrString args);
68    FFI_EXPORT char *FfiHidebugStartAppTraceCapture(CArrUnit tags, int32_t flag, uint32_t limitSize, int32_t &code);
69    FFI_EXPORT int32_t FfiHidebugStopAppTraceCapture();
70    FFI_EXPORT int32_t FfiHidebugSetAppResourceLimit(const char *type, int32_t value, bool enableDebugLog);
71    FFI_EXPORT bool FfiHidebugIsDebugState();
72}
73
74#endif // HIDEBUG_FFI_H
75