mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-11-23 15:00:17 +00:00
commit
9430666530
@ -39,6 +39,7 @@ ohos_shared_library("hidebug") {
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hiappevent:hiappevent_innerapi",
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
|
@ -447,7 +447,6 @@ napi_value DumpJsHeapData(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value GetPss(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ApiInvokeRecorder apiInvokeRecorder("getPss");
|
||||
napi_value pss;
|
||||
std::shared_ptr<UCollectUtil::MemoryCollector> collector = UCollectUtil::MemoryCollector::Create();
|
||||
if (collector != nullptr) {
|
||||
@ -506,7 +505,6 @@ napi_value GetCpuUsage(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value GetNativeHeapSize(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ApiInvokeRecorder apiInvokeRecorder("getNativeHeapSize");
|
||||
struct mallinfo mi = mallinfo();
|
||||
napi_value nativeHeapSize;
|
||||
napi_create_bigint_uint64(env, uint64_t(mi.uordblks + mi.fordblks), &nativeHeapSize);
|
||||
@ -1121,6 +1119,7 @@ napi_value GetGraphicsMemorySync(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value DeclareHiDebugInterface(napi_env env, napi_value exports)
|
||||
{
|
||||
ApiInvokeRecorder::InitProcessor();
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("startProfiling", StartProfiling),
|
||||
DECLARE_NAPI_FUNCTION("stopProfiling", StopProfiling),
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "app_event.h"
|
||||
#include "app_event_processor_mgr.h"
|
||||
#include "ffrt.h"
|
||||
#include "hidebug_util.h"
|
||||
#include "hilog/log.h"
|
||||
|
||||
@ -30,25 +31,32 @@ namespace HiviewDFX {
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "HIAPPEVENT_UTIL"
|
||||
|
||||
int64_t ApiInvokeRecorder::processId_ = -1;
|
||||
|
||||
ApiInvokeRecorder::ApiInvokeRecorder(std::string apiName) : apiName_(std::move(apiName)),
|
||||
beginTime_(GetNanoSecondsTimestamp()) {}
|
||||
|
||||
ApiInvokeRecorder::~ApiInvokeRecorder()
|
||||
{
|
||||
static int64_t processId = AddProcessor();
|
||||
if (processId < 0) {
|
||||
if (processId_ < 0) {
|
||||
return;
|
||||
}
|
||||
std::string apiName(std::move(apiName_));
|
||||
int64_t beginTime(beginTime_);
|
||||
int errorCode(errorCode_);
|
||||
auto task = [apiName, beginTime, errorCode] {
|
||||
HiAppEvent::Event event("api_diagnostic", "api_exec_end", HiAppEvent::BEHAVIOR);
|
||||
event.AddParam("trans_id", std::string("transId_") + std::to_string(beginTime_));
|
||||
event.AddParam("api_name", apiName_);
|
||||
event.AddParam("trans_id", std::string("transId_") + std::to_string(beginTime));
|
||||
event.AddParam("api_name", apiName);
|
||||
event.AddParam("sdk_name", std::string("PerformanceAnalysisKit"));
|
||||
constexpr int milliSecondsToNanoseconds = 1000 * 1000;
|
||||
event.AddParam("begin_time", beginTime_ / milliSecondsToNanoseconds);
|
||||
event.AddParam("begin_time", beginTime / milliSecondsToNanoseconds);
|
||||
event.AddParam("end_time", GetNanoSecondsTimestamp() / milliSecondsToNanoseconds);
|
||||
event.AddParam("result", static_cast<int>(errorCode_ == 0));
|
||||
event.AddParam("error_code", errorCode_);
|
||||
event.AddParam("result", static_cast<int>(errorCode == 0));
|
||||
event.AddParam("error_code", errorCode);
|
||||
Write(event);
|
||||
};
|
||||
ffrt::submit(task, {}, {});
|
||||
}
|
||||
|
||||
void ApiInvokeRecorder::SetErrorCode(int errorCode)
|
||||
@ -56,7 +64,7 @@ void ApiInvokeRecorder::SetErrorCode(int errorCode)
|
||||
errorCode_ = errorCode;
|
||||
}
|
||||
|
||||
int64_t ApiInvokeRecorder::AddProcessor()
|
||||
void ApiInvokeRecorder::InitProcessor()
|
||||
{
|
||||
using namespace HiAppEvent;
|
||||
ReportConfig config;
|
||||
@ -83,11 +91,10 @@ int64_t ApiInvokeRecorder::AddProcessor()
|
||||
.name = "api_called_stat_cnt",
|
||||
.isRealTime = true,
|
||||
});
|
||||
int64_t processId = AppEventProcessorMgr::AddProcessor(config);
|
||||
if (processId < 0) {
|
||||
HILOG_ERROR(LOG_CORE, "failed to init processor and ret: %{public}" PRId64, processId);
|
||||
}
|
||||
return processId;
|
||||
processId_ = AppEventProcessorMgr::AddProcessor(config);
|
||||
if (processId_ < 0) {
|
||||
HILOG_ERROR(LOG_CORE, "failed to init processor and ret: %{public}" PRId64, processId_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -24,11 +24,12 @@ public:
|
||||
explicit ApiInvokeRecorder(std::string apiName);
|
||||
~ApiInvokeRecorder();
|
||||
void SetErrorCode(int errorCode);
|
||||
static void InitProcessor();
|
||||
private:
|
||||
int64_t AddProcessor();
|
||||
std::string apiName_;
|
||||
int errorCode_{0};
|
||||
int64_t beginTime_;
|
||||
static int64_t processId_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user