diff --git a/src/commands/dump.cc b/src/commands/dump.cc index 623fc67..e4b5598 100644 --- a/src/commands/dump.cc +++ b/src/commands/dump.cc @@ -16,6 +16,7 @@ #include "v8.h" namespace xprofiler { +using nlohmann::json; using std::make_pair; using std::string; using std::to_string; @@ -318,9 +319,9 @@ static string CreateFilepath(string prefix, string ext) { func; \ if (err.Fail()) return result; -template -static json DoDumpAction(json command, DumpAction action, string prefix, - string ext, T* data, bool profiling, XpfError& err) { +template +static json DoDumpAction(json command, string prefix, string ext, T* data, + XpfError& err) { json result; // get traceid @@ -419,19 +420,18 @@ static json DoDumpAction(json command, DumpAction action, string prefix, return result; } -#define V(func, data_type, action, profiling, prefix, ext) \ - COMMAND_CALLBACK(func) { \ - /* TODO(legendecas): smart pointers */ \ - data_type* data = new data_type; \ - XpfError err; \ - json result = DoDumpAction(command, action, #prefix, #ext, \ - data, profiling, err); \ - if (err.Fail()) { \ - error(format("%s", err.GetErrMessage())); \ - delete data; \ - return; \ - } \ - success(result); \ +#define V(func, data_type, action, profiling, prefix, ext) \ + COMMAND_CALLBACK(func) { \ + data_type* data = new data_type; \ + XpfError err; \ + json result = DoDumpAction(command, #prefix, \ + #ext, data, err); \ + if (err.Fail()) { \ + error(format("%s", err.GetErrMessage())); \ + delete data; \ + return; \ + } \ + success(result); \ } // cpu profiling diff --git a/src/library/utils.h b/src/library/utils.h index 7b08088..3412331 100644 --- a/src/library/utils.h +++ b/src/library/utils.h @@ -6,8 +6,6 @@ #include "logger.h" namespace xprofiler { -using nlohmann::json; - void Sleep(int seconds); std::string FmtMessage(const char* format, ...); @@ -15,11 +13,11 @@ std::string FmtMessage(const char* format, ...); std::string ConvertTime(std::string format); template -T GetJsonValue(json data, std::string key, XpfError& err) { +T GetJsonValue(nlohmann::json data, std::string key, XpfError& err) { T result = T(); try { result = data[key].get(); - } catch (json::exception& e) { + } catch (nlohmann::json::exception& e) { // format error message // ref: https://en.cppreference.com/w/cpp/error/exception/what char error_message[256];