/** * @file atrace_api.h * * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef ATRACE_API_H #define ATRACE_API_H #include "atrace_types.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Create trace handle. * @param [in] tracerType: trace type * @param [in] objName: object name * @return atrace handle */ TraHandle AtraceCreate(TracerType tracerType, const char *objName) __attribute((weak)); /** * @brief Create trace handle. * @param [in] tracerType: trace type * @param [in] objName: object name * @param [in] attr: object attribute * @return atrace handle */ TraHandle AtraceCreateWithAttr(TracerType tracerType, const char *objName, const TraceAttr *attr) __attribute((weak)); /** * @brief Get trace handle * @param [in] tracerType: trace type * @param [in] objName: object name * @return atrace handle */ TraHandle AtraceGetHandle(TracerType tracerType, const char *objName) __attribute((weak)); /** * @brief Submite trace info * @param [in] handle: trace handle * @param [in] buffer: trace info buffer * @param [in] bufSize: size of buffer * @return TraStatus */ TraStatus AtraceSubmit(TraHandle handle, const void *buffer, uint32_t bufSize) __attribute((weak)); /** * @brief Destroy trace handle * @param [in] handle: trace handle * @return NA */ void AtraceDestroy(TraHandle handle) __attribute((weak)); /** * @brief Save trace info for all handle of tracerType * @param [in] tracerType: trace type to be saved * @param [in] syncFlag: synchronize or asynchronizing * @return TraStatus */ TraStatus AtraceSave(TracerType tracerType, bool syncFlag) __attribute((weak)); void *AtraceStructEntryListInit(void); void AtraceStructEntryName(TraceStructEntry *entry, const char *name); void AtraceStructItemSet(TraceStructEntry *entry, const char *name, uint8_t type, uint8_t mode, uint8_t bytes, uint64_t length); void AtraceStructEntryExit(TraceStructEntry *entry); #define TRACE_STRUCT_INIT_ENTRY \ { \ .name = {0}, \ .list = AtraceStructEntryListInit() \ } /** * @brief trace struct define * @param [out] en: trace struct entry * @return NA */ #define TRACE_STRUCT_DEFINE_ENTRY(en) TraceStructEntry en = TRACE_STRUCT_INIT_ENTRY /** * @brief trace struct undefine * @param [in] en: trace struct entry * @return NA */ #define TRACE_STRUCT_UNDEFINE_ENTRY(en) AtraceStructEntryExit(&en) /** * @brief set trace struct entry name * @param [in/out] en: trace struct entry * @param [in] name: trace struct entry name * @return NA */ #define TRACE_STRUCT_DEFINE_ENTRY_NAME(en, name) AtraceStructEntryName(&en, name) /** * @brief define trace struct item of int * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_FIELD_INT(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_FIELD_TYPE_INT, mode, bytes, len) /** * @brief define trace struct item of uint * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_FIELD_UINT(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_FIELD_TYPE_UINT, mode, bytes, len) /** * @brief define trace struct item of char * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_FIELD_CHAR(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_FIELD_TYPE_CHAR, mode, bytes, len) /** * @brief define trace struct item of int array * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_ARRAY_INT(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_ARRAY_TYPE_INT, mode, bytes, len) /** * @brief define trace struct item of uint array * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_ARRAY_UINT(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_ARRAY_TYPE_UINT, mode, bytes, len) /** * @brief define trace struct item of char array * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_ARRAY_CHAR(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_ARRAY_TYPE_CHAR, mode, bytes, len) /** * @brief define trace struct item of string * @param [in/out] en: trace struct entry * @param [in] item: item name * @param [in] mode: item save mode * @param [in] bytes: bytes occupied by a single element * @param [in] len: bytes occupied by this item * @return NA */ #define TRACE_STRUCT_DEFINE_STRING(en, item, mode, bytes, len) \ AtraceStructItemSet(&en, #item, TRACE_STRUCT_ARRAY_TYPE_CHAR, mode, bytes, len) /** * @brief set trace struct to trace attribute * @param [in] en: trace struct entry * @param [in/out] attr: object attribute * @return NA */ #define TRACE_STRUCT_SET_ATTR(en, attr) ((attr)->handle = &(en)) /** * @brief create thread to recv device trace log * @param [in] devId: device id * @return TraStatus */ TraStatus AtraceReportStart(int32_t devId) __attribute((weak)); /** * @brief stop thread to recv device trace log * @param [in] devId: device id */ void AtraceReportStop(int32_t devId) __attribute((weak)); /** * @brief Create trace event. * @param [in] eventName: event name * @return event handle */ TraEventHandle AtraceEventCreate(const char *eventName); /** * @brief Get event handle * @param [in] eventName: event name * @return event handle */ TraEventHandle AtraceEventGetHandle(const char *eventName); /** * @brief Destroy event handle * @param [in] eventHandle: event handle * @return NA */ void AtraceEventDestroy(TraEventHandle eventHandle); /** * @brief Bind event handle with trace handle * @param [in] eventHandle: event handle * @param [in] handle: trace handle * @return TraStatus */ TraStatus AtraceEventBindTrace(TraEventHandle eventHandle, TraHandle handle); /** * @brief Set event attr * @param [in] eventHandle: event handle * @param [in] attr: event attribute * @return TraStatus */ TraStatus AtraceEventSetAttr(TraEventHandle eventHandle, const TraceEventAttr *attr); /** * @brief Report event and save the bound trace log to disk * @param [in] eventHandle: event handle * @return TraStatus */ TraStatus AtraceEventReport(TraEventHandle eventHandle); #ifdef __cplusplus } #endif // end of the 'extern "C"' block #endif