mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
add window async trace template
Signed-off-by: xiahaiqin <xiahaiqin1@huawei.com> Change-Id: Iada573375a01f447c9ac03d95d704e65d647edda
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "noncopyable.h"
|
||||
|
||||
@@ -29,9 +30,12 @@
|
||||
#endif
|
||||
|
||||
#define WM_FUNCTION_TRACE() WM_SCOPED_TRACE(__func__)
|
||||
#define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__)
|
||||
#define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__)
|
||||
#define WM_SCOPED_TRACE_END() WmTraceEnd()
|
||||
|
||||
#define WM_SCOPED_ASYNC_TRACE_BEGIN(taskId, fmt, ...) WmAsyncTraceWithArgs(true, taskId, fmt, ##__VA_ARGS__)
|
||||
#define WM_SCOPED_ASYNC_END(taskId, fmt, ...) WmAsyncTraceWithArgs(false, taskId, fmt, ##__VA_ARGS__)
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
bool WmTraceEnabled();
|
||||
@@ -39,6 +43,11 @@ void WmTraceBegin(const char* name);
|
||||
bool WmTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2)));
|
||||
bool WmTraceBeginWithArgv(const char* format, va_list args);
|
||||
void WmTraceEnd();
|
||||
void WmAsyncTraceBegin(int32_t taskId, const char* name);
|
||||
void WmAsyncTraceEnd(int32_t taskId, const char* name);
|
||||
void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId,
|
||||
const char* format, ...) __attribute__((__format__(printf, 3, 4)));
|
||||
void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args);
|
||||
|
||||
class WmScopedTrace final {
|
||||
public:
|
||||
|
||||
@@ -48,6 +48,47 @@ void WmTraceEnd()
|
||||
}
|
||||
}
|
||||
|
||||
void WmAsyncTraceBegin(int32_t taskId, const char* name)
|
||||
{
|
||||
if (name == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string nameStr(name);
|
||||
StartAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId);
|
||||
}
|
||||
|
||||
void WmAsyncTraceEnd(int32_t taskId, const char* name)
|
||||
{
|
||||
if (name == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string nameStr(name);
|
||||
FinishAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId);
|
||||
}
|
||||
|
||||
void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId, const char* format, ...)
|
||||
{
|
||||
if (WmTraceEnabled()) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
WmAsyncTraceWithArgv(isBegin, taskId, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args)
|
||||
{
|
||||
char name[MAX_STRING_SIZE] = { 0 };
|
||||
if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) {
|
||||
return;
|
||||
}
|
||||
if (isBegin) {
|
||||
WmAsyncTraceBegin(taskId, name);
|
||||
} else {
|
||||
WmAsyncTraceEnd(taskId, name);
|
||||
}
|
||||
}
|
||||
|
||||
bool WmTraceBeginWithArgv(const char* format, va_list args)
|
||||
{
|
||||
char name[MAX_STRING_SIZE] = { 0 };
|
||||
|
||||
Reference in New Issue
Block a user