mirror of
https://gitee.com/openharmony/hiviewdfx_hitrace
synced 2025-02-16 23:48:34 +00:00
fix: hitrace代码整改
Signed-off-by: jiangwei <jiangwei214@h-partners.com>
This commit is contained in:
parent
496d06164a
commit
16af2287b7
@ -43,7 +43,6 @@
|
||||
#include "securec.h"
|
||||
#include "trace_collector_client.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX::HitraceOsal;
|
||||
|
||||
namespace {
|
||||
@ -160,7 +159,7 @@ const int PAGE_SIZE_KB = 4; // 4 KB
|
||||
const int MIN_FILE_SIZE = 51200; // 50 MB
|
||||
const int MAX_FILE_SIZE = 512000; // 500 MB
|
||||
|
||||
string g_traceRootPath;
|
||||
std::string g_traceRootPath;
|
||||
|
||||
std::shared_ptr<OHOS::HiviewDFX::UCollectClient::TraceCollector> g_traceCollector;
|
||||
|
||||
@ -196,8 +195,8 @@ static std::string GetStateInfo(const RunningState state)
|
||||
|
||||
static bool IsTraceMounted()
|
||||
{
|
||||
const string debugfsPath = "/sys/kernel/debug/tracing/";
|
||||
const string tracefsPath = "/sys/kernel/tracing/";
|
||||
const std::string debugfsPath = "/sys/kernel/debug/tracing/";
|
||||
const std::string tracefsPath = "/sys/kernel/tracing/";
|
||||
|
||||
if (access((debugfsPath + TRACE_MARKER_PATH).c_str(), F_OK) != -1) {
|
||||
g_traceRootPath = debugfsPath;
|
||||
@ -210,12 +209,12 @@ static bool IsTraceMounted()
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool WriteStrToFile(const string& filename, const std::string& str)
|
||||
static bool WriteStrToFile(const std::string& filename, const std::string& str)
|
||||
{
|
||||
ofstream out;
|
||||
std::ofstream out;
|
||||
std::string inSpecPath =
|
||||
OHOS::HiviewDFX::Hitrace::CanonicalizeSpecPath((g_traceRootPath + filename).c_str());
|
||||
out.open(inSpecPath, ios::out);
|
||||
out.open(inSpecPath, std::ios::out);
|
||||
if (out.fail()) {
|
||||
ConsoleLog("error: open " + inSpecPath + " failed.");
|
||||
return false;
|
||||
@ -231,19 +230,19 @@ static bool WriteStrToFile(const string& filename, const std::string& str)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SetFtraceEnabled(const string& path, bool enabled)
|
||||
static bool SetFtraceEnabled(const std::string& path, bool enabled)
|
||||
{
|
||||
return WriteStrToFile(path, enabled ? "1" : "0");
|
||||
}
|
||||
|
||||
static bool SetProperty(const string& property, const string& value)
|
||||
static bool SetProperty(const std::string& property, const std::string& value)
|
||||
{
|
||||
return SetPropertyInner(property, value);
|
||||
}
|
||||
|
||||
static bool SetTraceTagsEnabled(uint64_t tags)
|
||||
{
|
||||
string value = std::to_string(tags);
|
||||
std::string value = std::to_string(tags);
|
||||
return SetProperty(TRACE_TAG_PROPERTY, value);
|
||||
}
|
||||
|
||||
@ -256,7 +255,7 @@ static void ShowListCategory()
|
||||
}
|
||||
}
|
||||
|
||||
static void ShowHelp(const string& cmd)
|
||||
static void ShowHelp(const std::string& cmd)
|
||||
{
|
||||
g_traceSysEventParams.opt = "ShowHelp";
|
||||
printf("usage: %s [options] [categories...]\n", cmd.c_str());
|
||||
@ -326,7 +325,7 @@ static bool CheckOutputFile(const char* path)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ParseLongOpt(const string& cmd, int optionIndex)
|
||||
static bool ParseLongOpt(const std::string& cmd, int optionIndex)
|
||||
{
|
||||
bool isTrue = true;
|
||||
if (!strcmp(LONG_OPTIONS[optionIndex].name, "buffer_size")) {
|
||||
@ -345,7 +344,7 @@ static bool ParseLongOpt(const string& cmd, int optionIndex)
|
||||
}
|
||||
g_traceArgs.bufferSize = bufferSizeKB / PAGE_SIZE_KB * PAGE_SIZE_KB;
|
||||
} else if (!strcmp(LONG_OPTIONS[optionIndex].name, "trace_clock")) {
|
||||
regex re("[a-zA-Z]{4,6}");
|
||||
std::regex re("[a-zA-Z]{4,6}");
|
||||
if (regex_match(optarg, re)) {
|
||||
g_traceArgs.clockType = optarg;
|
||||
} else {
|
||||
@ -491,7 +490,7 @@ static bool HandleOpt(int argc, char** argv)
|
||||
bool isTrue = true;
|
||||
int opt = 0;
|
||||
int optionIndex = 0;
|
||||
string shortOption = "b:c:hlo:t:z";
|
||||
std::string shortOption = "b:c:hlo:t:z";
|
||||
int argcSize = argc;
|
||||
while (isTrue && argcSize-- > 0) {
|
||||
opt = getopt_long(argc, argv, shortOption.c_str(), LONG_OPTIONS, &optionIndex);
|
||||
@ -586,7 +585,7 @@ static void DumpCompressedTrace(int traceFd, int outFd)
|
||||
static void DumpTrace()
|
||||
{
|
||||
std::string tracePath = g_traceRootPath + TRACE_PATH;
|
||||
string traceSpecPath = OHOS::HiviewDFX::Hitrace::CanonicalizeSpecPath(tracePath.c_str());
|
||||
std::string traceSpecPath = OHOS::HiviewDFX::Hitrace::CanonicalizeSpecPath(tracePath.c_str());
|
||||
int traceFd = open(traceSpecPath.c_str(), O_RDONLY);
|
||||
if (traceFd == -1) {
|
||||
ConsoleLog("error: opening " + tracePath + ", errno: " + std::to_string(errno));
|
||||
@ -595,7 +594,7 @@ static void DumpTrace()
|
||||
|
||||
int outFd = STDOUT_FILENO;
|
||||
if (g_traceArgs.output.size() > 0) {
|
||||
string outSpecPath = OHOS::HiviewDFX::Hitrace::CanonicalizeSpecPath(g_traceArgs.output.c_str());
|
||||
std::string outSpecPath = OHOS::HiviewDFX::Hitrace::CanonicalizeSpecPath(g_traceArgs.output.c_str());
|
||||
outFd = open(outSpecPath.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ bool SetPropertyInner(const std::string& property, const std::string& value)
|
||||
{
|
||||
bool result = OHOS::system::SetParameter(property, value);
|
||||
if (!result) {
|
||||
fprintf(stderr, "Error: Failed to set %s property.\n", value.c_str());
|
||||
fprintf(stderr, "Error: Failed to set %s property.\n", property.c_str());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -16,12 +16,10 @@
|
||||
#include "hitrace/hitracechain.h"
|
||||
#include "hitracechain_inner.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
|
||||
HiTraceId HiTraceChain::Begin(const string& name, int flags)
|
||||
HiTraceId HiTraceChain::Begin(const std::string& name, int flags)
|
||||
{
|
||||
return HiTraceId(::HiTraceChainBegin(name.c_str(), flags));
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ constexpr int ARGC_NUMBER_THREE = 3;
|
||||
#define LOG_TAG "HITRACE_METER_JS"
|
||||
|
||||
using STR_NUM_PARAM_FUNC = std::function<bool(std::string, napi_value&)>;
|
||||
std::map<std::string, uint64_t> g_tagsMap = {
|
||||
std::unordered_map<std::string, uint64_t> g_tagsMap = {
|
||||
{"ohos", HITRACE_TAG_OHOS}, {"ability", HITRACE_TAG_ABILITY_MANAGER}, {"camera", HITRACE_TAG_ZCAMERA},
|
||||
{"media", HITRACE_TAG_ZMEDIA}, {"image", HITRACE_TAG_ZIMAGE}, {"audio", HITRACE_TAG_ZAUDIO},
|
||||
{"distributeddatamgr", HITRACE_TAG_DISTRIBUTEDDATA}, {"graphic", HITRACE_TAG_GRAPHIC_AGP},
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "securec.h"
|
||||
#include "trace_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX::HitraceOsal;
|
||||
using OHOS::HiviewDFX::HiLog;
|
||||
|
||||
@ -902,6 +901,7 @@ bool DumpTraceLoop(const std::string &outputFileName, bool isLimited)
|
||||
if (!GenerateNewFile(outFd, outPath)) {
|
||||
HILOG_INFO(LOG_CORE, "DumpTraceLoop access file:%{public}s failed, errno: %{public}d.",
|
||||
outPath.c_str(), errno);
|
||||
close(outFd);
|
||||
return false;
|
||||
}
|
||||
} while (g_needGenerateNewTraceFile);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "securec.h"
|
||||
#include "hilog/log.h"
|
||||
@ -38,7 +39,6 @@
|
||||
#include "hitrace_meter.h"
|
||||
#include "hitrace/tracechain.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
#define EXPECTANTLY(exp) (__builtin_expect(!!(exp), true))
|
||||
@ -158,8 +158,8 @@ inline void UpdateSysParamTags()
|
||||
|
||||
bool IsAppspawnProcess()
|
||||
{
|
||||
string procName;
|
||||
ifstream cmdline("/proc/self/cmdline");
|
||||
std::string procName;
|
||||
std::ifstream cmdline("/proc/self/cmdline");
|
||||
if (cmdline.is_open()) {
|
||||
getline(cmdline, procName, '\0');
|
||||
cmdline.close();
|
||||
@ -182,7 +182,7 @@ void InitPid()
|
||||
}
|
||||
|
||||
HILOG_INFO(LOG_CORE, "pid[%{public}s] first get g_tagsProperty: %{public}s", pidStr.c_str(),
|
||||
to_string(g_tagsProperty.load()).c_str());
|
||||
std::to_string(g_tagsProperty.load()).c_str());
|
||||
}
|
||||
|
||||
void ReloadPid()
|
||||
@ -290,7 +290,7 @@ bool GetProcData(const char* file, char* buffer, const size_t bufferSize)
|
||||
FILE* fp = fopen(file, "r");
|
||||
if (fp == nullptr) {
|
||||
static bool isWriteLog = false;
|
||||
std::string errLogStr = std::string(__func__) + ": open " + std::string(file) + " falied";
|
||||
std::string errLogStr = std::string(__func__) + ": open " + std::string(file) + " failed";
|
||||
WriteOnceLog(LOG_ERROR, errLogStr, isWriteLog);
|
||||
return false;
|
||||
}
|
||||
@ -298,14 +298,14 @@ bool GetProcData(const char* file, char* buffer, const size_t bufferSize)
|
||||
if (fgets(buffer, bufferSize, fp) == nullptr) {
|
||||
(void)fclose(fp);
|
||||
static bool isWriteLog = false;
|
||||
std::string errLogStr = std::string(__func__) + ": fgets " + std::string(file) + " falied";
|
||||
std::string errLogStr = std::string(__func__) + ": fgets " + std::string(file) + " failed";
|
||||
WriteOnceLog(LOG_ERROR, errLogStr, isWriteLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
static bool isWriteLog = false;
|
||||
std::string errLogStr = std::string(__func__) + ": fclose " + std::string(file) + " falied";
|
||||
std::string errLogStr = std::string(__func__) + ": fclose " + std::string(file) + " failed";
|
||||
WriteOnceLog(LOG_ERROR, errLogStr, isWriteLog);
|
||||
return false;
|
||||
}
|
||||
@ -684,7 +684,7 @@ void SetAddTraceMarkerLarge(const std::string& name, const int64_t value)
|
||||
AddTraceMarkerLarge(name, MARKER_BEGIN, value);
|
||||
}
|
||||
|
||||
void SetAddHitraceMeterMarker(uint64_t label, const string& value)
|
||||
void SetAddHitraceMeterMarker(uint64_t label, const std::string& value)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_BEGIN, label, value, 0);
|
||||
}
|
||||
@ -775,12 +775,12 @@ void StartTraceWrapper(uint64_t label, const char *value)
|
||||
StartTrace(label, traceValue);
|
||||
}
|
||||
|
||||
void StartTrace(uint64_t label, const string& value, float limit UNUSED_PARAM)
|
||||
void StartTrace(uint64_t label, const std::string& value, float limit UNUSED_PARAM)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_BEGIN, label, value, 0);
|
||||
}
|
||||
|
||||
void StartTraceDebug(bool isDebug, uint64_t label, const string& value, float limit UNUSED_PARAM)
|
||||
void StartTraceDebug(bool isDebug, uint64_t label, const std::string& value, float limit UNUSED_PARAM)
|
||||
{
|
||||
if (!isDebug) {
|
||||
return;
|
||||
@ -838,7 +838,7 @@ void FinishTraceDebug(bool isDebug, uint64_t label)
|
||||
AddHitraceMeterMarker(MARKER_END, label, EMPTY_TRACE_NAME, 0);
|
||||
}
|
||||
|
||||
void StartAsyncTrace(uint64_t label, const string& value, int32_t taskId, float limit UNUSED_PARAM)
|
||||
void StartAsyncTrace(uint64_t label, const std::string& value, int32_t taskId, float limit UNUSED_PARAM)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_ASYNC_BEGIN, label, value, taskId);
|
||||
}
|
||||
@ -854,7 +854,7 @@ void StartTraceChain(uint64_t label, const struct HiTraceIdStruct* hiTraceId, co
|
||||
AddHitraceMeterMarker(MARKER_BEGIN, label, value, 0, hiTraceId);
|
||||
}
|
||||
|
||||
void StartAsyncTraceDebug(bool isDebug, uint64_t label, const string& value, int32_t taskId, float limit UNUSED_PARAM)
|
||||
void StartAsyncTraceDebug(bool isDebug, uint64_t label, const std::string& value, int32_t taskId, float limit UNUSED_PARAM)
|
||||
{
|
||||
if (!isDebug) {
|
||||
return;
|
||||
@ -900,7 +900,7 @@ void StartAsyncTraceArgsDebug(bool isDebug, uint64_t label, int32_t taskId, cons
|
||||
AddHitraceMeterMarker(MARKER_ASYNC_BEGIN, label, name, taskId);
|
||||
}
|
||||
|
||||
void FinishAsyncTrace(uint64_t label, const string& value, int32_t taskId)
|
||||
void FinishAsyncTrace(uint64_t label, const std::string& value, int32_t taskId)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_ASYNC_END, label, value, taskId);
|
||||
}
|
||||
@ -911,7 +911,7 @@ void FinishAsyncTraceWrapper(uint64_t label, const char *value, int32_t taskId)
|
||||
FinishAsyncTrace(label, traceValue, taskId);
|
||||
}
|
||||
|
||||
void FinishAsyncTraceDebug(bool isDebug, uint64_t label, const string& value, int32_t taskId)
|
||||
void FinishAsyncTraceDebug(bool isDebug, uint64_t label, const std::string& value, int32_t taskId)
|
||||
{
|
||||
if (!isDebug) {
|
||||
return;
|
||||
@ -957,13 +957,13 @@ void FinishAsyncTraceArgsDebug(bool isDebug, uint64_t label, int32_t taskId, con
|
||||
AddHitraceMeterMarker(MARKER_ASYNC_END, label, name, taskId);
|
||||
}
|
||||
|
||||
void MiddleTrace(uint64_t label, const string& beforeValue UNUSED_PARAM, const std::string& afterValue)
|
||||
void MiddleTrace(uint64_t label, const std::string& beforeValue UNUSED_PARAM, const std::string& afterValue)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_END, label, EMPTY_TRACE_NAME, 0);
|
||||
AddHitraceMeterMarker(MARKER_BEGIN, label, afterValue, 0);
|
||||
}
|
||||
|
||||
void MiddleTraceDebug(bool isDebug, uint64_t label, const string& beforeValue UNUSED_PARAM,
|
||||
void MiddleTraceDebug(bool isDebug, uint64_t label, const std::string& beforeValue UNUSED_PARAM,
|
||||
const std::string& afterValue)
|
||||
{
|
||||
if (!isDebug) {
|
||||
@ -973,12 +973,12 @@ void MiddleTraceDebug(bool isDebug, uint64_t label, const string& beforeValue UN
|
||||
AddHitraceMeterMarker(MARKER_BEGIN, label, afterValue, 0);
|
||||
}
|
||||
|
||||
void CountTrace(uint64_t label, const string& name, int64_t count)
|
||||
void CountTrace(uint64_t label, const std::string& name, int64_t count)
|
||||
{
|
||||
AddHitraceMeterMarker(MARKER_INT, label, name, count);
|
||||
}
|
||||
|
||||
void CountTraceDebug(bool isDebug, uint64_t label, const string& name, int64_t count)
|
||||
void CountTraceDebug(bool isDebug, uint64_t label, const std::string& name, int64_t count)
|
||||
{
|
||||
if (!isDebug) {
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user