harmony 鸿蒙HiDebug

  • 2025-06-12
  • 浏览 (5)

HiDebug

Overview

Provides APIs for debugging.

Provides definitions for the HiDebug module.

The functions of this module can be used to obtain information such as the CPU usage, memory, heap, and capture trace.

Since: 12

Summary

Files

Name Description
hidebug.h Defines the APIs for debugging.
hidebug_type.h Defines the structs of the HiDebug module.

Structs

Name Description
struct  HiDebug_ThreadCpuUsage Defines the CPU usage of all threads of an application.
struct  HiDebug_SystemMemInfo Defines the system memory information.
struct  HiDebug_NativeMemInfo Defines the local memory information of an application process.
struct  HiDebug_MemoryLimit Defines the memory limit of an application process.

Macros

Name Description
HIDEBUG_TRACE_TAG_FFRT   (1ULL << 13) Indicates the FFRT task.
HIDEBUG_TRACE_TAG_COMMON_LIBRARY   (1ULL << 16) Indicates the common library subsystem.
HIDEBUG_TRACE_TAG_HDF   (1ULL << 18) Indicates the HDF subsystem.
HIDEBUG_TRACE_TAG_NET   (1ULL << 23) Indicates the network.
HIDEBUG_TRACE_TAG_NWEB   (1ULL << 24) Indicates the NWeb.
HIDEBUG_TRACE_TAG_DISTRIBUTED_AUDIO   (1ULL << 27) Indicates the distributed audio.
HIDEBUG_TRACE_TAG_FILE_MANAGEMENT   (1ULL << 29) Indicates the file management.
HIDEBUG_TRACE_TAG_OHOS   (1ULL << 30) Indicates the OpenHarmony OS.
HIDEBUG_TRACE_TAG_ABILITY_MANAGER   (1ULL << 31) Indicates the ability manager.
HIDEBUG_TRACE_TAG_CAMERA   (1ULL << 32) Indicates the camera module.
HIDEBUG_TRACE_TAG_MEDIA   (1ULL << 33) Indicates the media module.
HIDEBUG_TRACE_TAG_IMAGE   (1ULL << 34) Indicates the image module.
HIDEBUG_TRACE_TAG_AUDIO   (1ULL << 35) Indicates the audio module.
HIDEBUG_TRACE_TAG_DISTRIBUTED_DATA   (1ULL << 36) Indicates the distributed data management.
HIDEBUG_TRACE_TAG_GRAPHICS   (1ULL << 38) Indicates the graphics module.
HIDEBUG_TRACE_TAG_ARKUI   (1ULL << 39) Indicates the ArkUI development framework.
HIDEBUG_TRACE_TAG_NOTIFICATION   (1ULL << 40) Indicates the notification module.
HIDEBUG_TRACE_TAG_MISC   (1ULL << 41) Indicates the MISC module.
HIDEBUG_TRACE_TAG_MULTIMODAL_INPUT   (1ULL << 42) Indicates the multimodal input module.
HIDEBUG_TRACE_TAG_RPC   (1ULL << 46) Indicates the RPC.
HIDEBUG_TRACE_TAG_ARK   (1ULL << 47) Indicates the JSVM.
HIDEBUG_TRACE_TAG_WINDOW_MANAGER   (1ULL << 48) Indicates the window manager.
HIDEBUG_TRACE_TAG_DISTRIBUTED_SCREEN   (1ULL << 50) Indicates the distributed screen.
HIDEBUG_TRACE_TAG_DISTRIBUTED_CAMERA   (1ULL << 51) Indicates the distributed camera.
HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_FRAMEWORK   (1ULL << 52) Indicates the distributed hardware framework.
HIDEBUG_TRACE_TAG_GLOBAL_RESOURCE_MANAGER   (1ULL << 53) Indicates the global resource manager.
HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_DEVICE_MANAGER   (1ULL << 54) Indicates the distributed hardware device manager.
HIDEBUG_TRACE_TAG_SAMGR   (1ULL << 55) Indicates the service ability manager (SAMGR).
HIDEBUG_TRACE_TAG_POWER_MANAGER   (1ULL << 56) Indicates the power manager.
HIDEBUG_TRACE_TAG_DISTRIBUTED_SCHEDULER   (1ULL << 57) Indicates the distributed scheduler.
HIDEBUG_TRACE_TAG_DISTRIBUTED_INPUT   (1ULL << 59) Indicates the distributed input.
HIDEBUG_TRACE_TAG_BLUETOOTH   (1ULL << 60) Indicates the Bluetooth.

Types

Name Description
typedef enum HiDebug_ErrorCode HiDebug_ErrorCode Defines an enum for the error codes used in the HiDebug module.
typedef struct HiDebug_ThreadCpuUsage HiDebug_ThreadCpuUsage Defines a struct for the CPU usage of all threads of an application.
typedef HiDebug_ThreadCpuUsage * HiDebug_ThreadCpuUsagePtr Defines the pointer to HiDebug_ThreadCpuUsage.
typedef struct HiDebug_SystemMemInfo HiDebug_SystemMemInfo Defines a struct for the system memory information.
typedef struct HiDebug_NativeMemInfo HiDebug_NativeMemInfo Defines a struct for the local memory information of the application process.
typedef struct HiDebug_MemoryLimit HiDebug_MemoryLimit Defines a struct for the memory limit of an application process.
typedef enum HiDebug_TraceFlag HiDebug_TraceFlag Defines an enum for the thread types for trace collection.

Enums

Name Description
HiDebug_ErrorCode {
HIDEBUG_SUCCESS = 0, HIDEBUG_INVALID_ARGUMENT = 401, HIDEBUG_TRACE_CAPTURED_ALREADY = 11400102, HIDEBUG_NO_PERMISSION = 11400103,
HIDEBUG_TRACE_ABNORMAL = 11400104, HIDEBUG_NO_TRACE_RUNNING = 11400105
}
Enumerates the error codes used in the HiDebug module.
HiDebug_TraceFlag { HIDEBUG_TRACE_FLAG_MAIN_THREAD = 1, HIDEBUG_TRACE_FLAG_ALL_THREADS = 2 } Enumerates the thread types for trace collection.

Functions

Name Description
double OH_HiDebug_GetSystemCpuUsage () Obtains the CPU usage of the system.
double OH_HiDebug_GetAppCpuUsage () Obtains the CPU usage of an application.
HiDebug_ThreadCpuUsagePtr OH_HiDebug_GetAppThreadCpuUsage () Obtains the CPU usage of all threads of an application.
void OH_HiDebug_FreeThreadCpuUsage (HiDebug_ThreadCpuUsagePtr *threadCpuUsage) Releases the HiDebug_ThreadCpuUsagePtr.
void OH_HiDebug_GetSystemMemInfo (HiDebug_SystemMemInfo *systemMemInfo) Obtains system memory information.
void OH_HiDebug_GetAppNativeMemInfo (HiDebug_NativeMemInfo *nativeMemInfo) Obtains the memory information of an application process.
void OH_HiDebug_GetAppMemoryLimit (HiDebug_MemoryLimit *memoryLimit) Obtains the memory limit of an application process.
HiDebug_ErrorCode OH_HiDebug_StartAppTraceCapture (HiDebug_TraceFlag flag, uint64_t tags, uint32_t limitSize, char *fileName, uint32_t length) Starts application trace collection.
HiDebug_ErrorCode OH_HiDebug_StopAppTraceCapture () Stops application trace collection.
HiDebug_ErrorCode OH_HiDebug_GetGraphicsMemory (uint32_t *value) Obtains the size of the GPU memory.

Macro Description

HIDEBUG_TRACE_TAG_ABILITY_MANAGER

#define HIDEBUG_TRACE_TAG_ABILITY_MANAGER   (1ULL << 31)

Description Indicates the ability manager.

Since: 12

HIDEBUG_TRACE_TAG_ARK

#define HIDEBUG_TRACE_TAG_ARK   (1ULL << 47)

Description Indicates the JSVM.

Since: 12

HIDEBUG_TRACE_TAG_ARKUI

#define HIDEBUG_TRACE_TAG_ARKUI   (1ULL << 39)

Description Indicates the ArkUI development framework.

Since: 12

HIDEBUG_TRACE_TAG_AUDIO

#define HIDEBUG_TRACE_TAG_AUDIO   (1ULL << 35)

Description Indicates the audio module.

Since: 12

HIDEBUG_TRACE_TAG_BLUETOOTH

#define HIDEBUG_TRACE_TAG_BLUETOOTH   (1ULL << 60)

Description Indicates the Bluetooth.

Since: 12

HIDEBUG_TRACE_TAG_CAMERA

#define HIDEBUG_TRACE_TAG_CAMERA   (1ULL << 32)

Description Indicates the camera module.

Since: 12

HIDEBUG_TRACE_TAG_COMMON_LIBRARY

#define HIDEBUG_TRACE_TAG_COMMON_LIBRARY   (1ULL << 16)

Description Indicates the common library subsystem.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_AUDIO

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_AUDIO   (1ULL << 27)

Description Indicates the distributed audio.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_CAMERA

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_CAMERA   (1ULL << 51)

Description Indicates the distributed camera.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_DATA

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_DATA   (1ULL << 36)

Description Indicates the distributed data management.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_DEVICE_MANAGER

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_DEVICE_MANAGER   (1ULL << 54)

Description Indicates the distributed hardware device manager.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_FRAMEWORK

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_HARDWARE_FRAMEWORK   (1ULL << 52)

Description Indicates the distributed hardware framework.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_INPUT

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_INPUT   (1ULL << 59)

Description Indicates the distributed input.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_SCHEDULER

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_SCHEDULER   (1ULL << 57)

Description Indicates the distributed scheduler.

Since: 12

HIDEBUG_TRACE_TAG_DISTRIBUTED_SCREEN

#define HIDEBUG_TRACE_TAG_DISTRIBUTED_SCREEN   (1ULL << 50)

Description Indicates the distributed screen.

Since: 12

HIDEBUG_TRACE_TAG_FFRT

#define HIDEBUG_TRACE_TAG_FFRT   (1ULL << 13)

Description Indicates the FFRT task.

Since: 12

HIDEBUG_TRACE_TAG_FILE_MANAGEMENT

#define HIDEBUG_TRACE_TAG_FILE_MANAGEMENT   (1ULL << 29)

Description Indicates the file management.

Since: 12

HIDEBUG_TRACE_TAG_GLOBAL_RESOURCE_MANAGER

#define HIDEBUG_TRACE_TAG_GLOBAL_RESOURCE_MANAGER   (1ULL << 53)

Description Indicates the global resource manager.

Since: 12

HIDEBUG_TRACE_TAG_GRAPHICS

#define HIDEBUG_TRACE_TAG_GRAPHICS   (1ULL << 38)

Description Indicates the graphics module.

Since: 12

HIDEBUG_TRACE_TAG_HDF

#define HIDEBUG_TRACE_TAG_HDF   (1ULL << 18)

Description Indicates the HDF subsystem.

Since: 12

HIDEBUG_TRACE_TAG_IMAGE

#define HIDEBUG_TRACE_TAG_IMAGE   (1ULL << 34)

Description Indicates the image module.

Since: 12

HIDEBUG_TRACE_TAG_MEDIA

#define HIDEBUG_TRACE_TAG_MEDIA   (1ULL << 33)

Description Indicates the media module.

Since: 12

HIDEBUG_TRACE_TAG_MISC

#define HIDEBUG_TRACE_TAG_MISC   (1ULL << 41)

Description Indicates the MISC module.

Since: 12

HIDEBUG_TRACE_TAG_MULTIMODAL_INPUT

#define HIDEBUG_TRACE_TAG_MULTIMODAL_INPUT   (1ULL << 42)

Description Indicates the multimodal input module.

Since: 12

HIDEBUG_TRACE_TAG_NET

#define HIDEBUG_TRACE_TAG_NET   (1ULL << 23)

Description Indicates the network.

Since: 12

HIDEBUG_TRACE_TAG_NOTIFICATION

#define HIDEBUG_TRACE_TAG_NOTIFICATION   (1ULL << 40)

Description Indicates the notification module.

Since: 12

HIDEBUG_TRACE_TAG_NWEB

#define HIDEBUG_TRACE_TAG_NWEB   (1ULL << 24)

Description Indicates the NWeb.

Since: 12

HIDEBUG_TRACE_TAG_OHOS

#define HIDEBUG_TRACE_TAG_OHOS   (1ULL << 30)

Description Indicates the OpenHarmony OS.

Since: 12

HIDEBUG_TRACE_TAG_POWER_MANAGER

#define HIDEBUG_TRACE_TAG_POWER_MANAGER   (1ULL << 56)

Description Indicates the power manager.

Since: 12

HIDEBUG_TRACE_TAG_RPC

#define HIDEBUG_TRACE_TAG_RPC   (1ULL << 46)

Description Indicates the RPC.

Since: 12

HIDEBUG_TRACE_TAG_SAMGR

#define HIDEBUG_TRACE_TAG_SAMGR   (1ULL << 55)

Description Indicates the service ability manager (SAMGR).

Since: 12

HIDEBUG_TRACE_TAG_WINDOW_MANAGER

#define HIDEBUG_TRACE_TAG_WINDOW_MANAGER   (1ULL << 48)

Description Indicates the window manager.

Since: 12

Type Description

HiDebug_ErrorCode

typedef enum HiDebug_ErrorCodeHiDebug_ErrorCode

Description Defines an enum for the error codes used in the HiDebug module.

Since: 12

HiDebug_MemoryLimit

typedef struct HiDebug_MemoryLimitHiDebug_MemoryLimit

Description Defines a struct for the memory limit of an application process.

Since: 12

HiDebug_NativeMemInfo

typedef struct HiDebug_NativeMemInfoHiDebug_NativeMemInfo

Description Defines a struct for the local memory information of the application process.

Since: 12

HiDebug_SystemMemInfo

typedef struct HiDebug_SystemMemInfoHiDebug_SystemMemInfo

Description Defines a struct for the system memory information.

Since: 12

HiDebug_ThreadCpuUsage

typedef struct HiDebug_ThreadCpuUsageHiDebug_ThreadCpuUsage

Description Defines a struct for the CPU usage of all threads of an application.

Since: 12

HiDebug_ThreadCpuUsagePtr

typedef HiDebug_ThreadCpuUsage* HiDebug_ThreadCpuUsagePtr

Description Defines the pointer to HiDebug_ThreadCpuUsage.

Since: 12

HiDebug_TraceFlag

typedef enum HiDebug_TraceFlagHiDebug_TraceFlag

Description Defines an enum for the thread types for trace collection.

Since: 12

Enum Description

HiDebug_ErrorCode

enum HiDebug_ErrorCode

Description Enumerates the error codes used in the HiDebug module.

Since: 12

Value Description
HIDEBUG_SUCCESS The operation is successful.&nbsp;&nbsp;
HIDEBUG_INVALID_ARGUMENT The parameter is invalid. Possible causes: 1. The parameter value is incorrect. 2. The parameter type is incorrect.&nbsp;&nbsp;
HIDEBUG_TRACE_CAPTURED_ALREADY Repeated collection.&nbsp;&nbsp;
HIDEBUG_NO_PERMISSION No file write permission.&nbsp;&nbsp;
HIDEBUG_TRACE_ABNORMAL Abnormal trace status&nbsp;&nbsp;
HIDEBUG_NO_TRACE_RUNNING No trace collection is running.&nbsp;&nbsp;

HiDebug_TraceFlag

enum HiDebug_TraceFlag

Description Enumerates the thread types for trace collection.

Since: 12

Value Description
HIDEBUG_TRACE_FLAG_MAIN_THREAD Only the main thread of the current application.&nbsp;&nbsp;
HIDEBUG_TRACE_FLAG_ALL_THREADS All threads of the application.&nbsp;&nbsp;

Function Description

OH_HiDebug_FreeThreadCpuUsage()

void OH_HiDebug_FreeThreadCpuUsage (HiDebug_ThreadCpuUsagePtr * threadCpuUsage)

Description Releases the HiDebug_ThreadCpuUsagePtr.

Since: 12

Parameters

Name Description
threadCpuUsage Pointer to the buffer that stores the available CPU for all threads of the application. For details, see HiDebug_ThreadCpuUsagePtr. The input parameter is obtained by OH_HiDebug_GetAppThreadCpuUsage().

OH_HiDebug_GetAppCpuUsage()

double OH_HiDebug_GetAppCpuUsage ()

Description Obtains the CPU usage of an application.

Since: 12

Returns

Returns the application CPU usage obtained if the operation is successful. Returns 0 if the CPU usage of the application is too low.

OH_HiDebug_GetAppMemoryLimit()

void OH_HiDebug_GetAppMemoryLimit (HiDebug_MemoryLimit * memoryLimit)

Description Obtains the memory limit of an application process.

Since: 12

Parameters

Name Description
memoryLimit Pointer to the HiDebug_MemoryLimit to obtain. If the struct is empty, the function call fails.

OH_HiDebug_GetAppNativeMemInfo()

void OH_HiDebug_GetAppNativeMemInfo (HiDebug_NativeMemInfo * nativeMemInfo)

Description Obtains the memory information of an application process.

Since: 12

Parameters

Name Description
nativeMemInfo Pointer to the HiDebug_NativeMemInfo to obtain. If the struct is empty, the function call fails.

OH_HiDebug_GetAppThreadCpuUsage()

HiDebug_ThreadCpuUsagePtr OH_HiDebug_GetAppThreadCpuUsage ()

Description Obtains the CPU usage of all threads of an application.

Since: 12

Returns

Returns the CPU usage of all threads. For details, see HiDebug_ThreadCpuUsagePtr. Returns null if the thread data is not obtained.

OH_HiDebug_GetGraphicsMemory()

HiDebug_ErrorCode OH_HiDebug_GetGraphicsMemory (uint32_t * value)

Description Obtains the size of the GPU memory.

Since: 14

Parameters

Name Description
value Pointer to the variable that stores the size (in KB) of the obtained GPU memory.

Returns

0 - The API is obtained successfully.

401 - The parameter is a null pointer, which is invalid.

11400104 - An internal system error occurs.

OH_HiDebug_GetSystemCpuUsage()

double OH_HiDebug_GetSystemCpuUsage ()

Description Obtains the CPU usage of the system.

Since: 12

Returns

Returns the system CPU usage if the operation is successful. Returns 0 if the operation fails.

OH_HiDebug_GetSystemMemInfo()

void OH_HiDebug_GetSystemMemInfo (HiDebug_SystemMemInfo * systemMemInfo)

Description Obtains system memory information.

Since: 12

Parameters

Name Description
systemMemInfo Pointer to the HiDebug_SystemMemInfo to obtain. If the struct is empty, the function call fails.

OH_HiDebug_StartAppTraceCapture()

HiDebug_ErrorCode OH_HiDebug_StartAppTraceCapture (HiDebug_TraceFlag flag, uint64_t tags, uint32_t limitSize, char * fileName, uint32_t length )

Description Starts application trace collection.

Since: 12

Parameters

Name Description
flag Type of the thread (the main thread or all threads of the application) to trace.
tags Modules or subsystems to trace.
limitSize Maximum size of the trace file (in bytes), which is 500 MB.
fileName Buffer for the output trace file.
length Length of the buffer for the output trace file.

Returns

0 - The operation is successful.

HIDEBUG_INVALID_ARGUMENT 401 - The fileName parameter is a null pointer, the input length parameter is too small, or the value of limitSize is less than or equal to 0.

11400102 - A trace is already started.

11400103 - You do not have the permission to start the trace function.

11400104 - An internal system error occurs.

OH_HiDebug_StopAppTraceCapture()

HiDebug_ErrorCode OH_HiDebug_StopAppTraceCapture ()

Description Stops application trace collection.

Since: 12

Returns

0 - The operation is successful.

11400104 - An internal system error occurs.

11400105 - No trace collection is running.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙Performance Analysis Kit

harmony 鸿蒙HiAppEvent

harmony 鸿蒙HiAppEvent_AppEventGroup

harmony 鸿蒙HiAppEvent_AppEventInfo

harmony 鸿蒙HiCollie

harmony 鸿蒙HiCollie_DetectionParam

harmony 鸿蒙HiCollie_SetTimerParam

harmony 鸿蒙HiDebug_MemoryLimit

harmony 鸿蒙HiDebug_NativeMemInfo

0  赞