Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(perf_counter): remove static map from counter_info #735

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/runtime/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ std::unique_ptr<task_spec_profiler[]> s_spec_profilers;

int s_task_code_max = 0;

std::map<std::string, perf_counter_ptr_type> counter_info::pointer_type;

counter_info *counter_info_ptr[] = {
new counter_info({"queue.time", "qt"},
TASK_QUEUEING_TIME_NS,
Expand Down
34 changes: 17 additions & 17 deletions src/runtime/profiler_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ static dsn_perf_counter_percentile_type_t find_percentail_type(const std::string

static perf_counter_ptr_type find_counter_type(const std::string &name)
{
auto it = counter_info::pointer_type.find(std::string(name));
if (it == counter_info::pointer_type.end()) {
return PERF_COUNTER_INVALID;
for (int i = 0; i < PERF_COUNTER_COUNT; i++) {
const auto &keys = counter_info_ptr[i]->keys;
if (std::find(keys.begin(), keys.end(), name) != keys.end()) {
return counter_info_ptr[i]->counter_ptr_type;
}
}
return it->second;
return PERF_COUNTER_INVALID;
}

std::string profiler_output_handler(const std::vector<std::string> &args)
Expand Down Expand Up @@ -377,8 +379,7 @@ std::string query_data_handler(const std::vector<std::string> &args)
if (s_spec_profilers[task_id].ptr[counter_type].get() == NULL)
continue;

char name[20] = {0};
strcpy(name, counter_info_ptr[counter_type]->title);
const std::string &name = counter_info_ptr[counter_type]->title;

char name_suffix[10] = {0};
switch (task_spec::get(task_id)->type) {
Expand All @@ -393,7 +394,7 @@ std::string query_data_handler(const std::vector<std::string> &args)
break;
}

resp.name = std::string(name) + std::string(name_suffix);
resp.name = name + std::string(name_suffix);

// get samples
perf_counter::samples_t samples;
Expand Down Expand Up @@ -491,25 +492,25 @@ std::string query_data_handler(const std::vector<std::string> &args)

timeGet = ((timeGet < 0) ? 0 : timeGet);

if (strcmp(counter_info_ptr[counter_type]->title, "RPC.SERVER(ns)") == 0 &&
if (counter_info_ptr[counter_type]->title == "RPC.SERVER(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_REQUEST)
timeList[0] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "QUEUE(ns)") == 0 &&
else if (counter_info_ptr[counter_type]->title == "QUEUE(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_REQUEST)
timeList[1] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "EXEC(ns)") == 0 &&
else if (counter_info_ptr[counter_type]->title == "EXEC(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_REQUEST)
timeList[2] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "RPC.CLIENT(ns)") == 0 &&
else if (counter_info_ptr[counter_type]->title == "RPC.CLIENT(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_RESPONSE)
timeList[3] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "QUEUE(ns)") == 0 &&
else if (counter_info_ptr[counter_type]->title == "QUEUE(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_RESPONSE)
timeList[4] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "EXEC(ns)") == 0 &&
else if (counter_info_ptr[counter_type]->title == "EXEC(ns)" &&
task_spec::get(task_id)->type == TASK_TYPE_RPC_RESPONSE)
timeList[5] = timeGet;
else if (strcmp(counter_info_ptr[counter_type]->title, "AIO.LATENCY(ns)") == 0)
else if (counter_info_ptr[counter_type]->title == "AIO.LATENCY(ns)")
timeList[6] = timeGet;
}
}
Expand Down Expand Up @@ -554,8 +555,7 @@ std::string query_data_handler(const std::vector<std::string> &args)
if (s_spec_profilers[task_id].ptr[counter_type].get() == NULL)
continue;

char name[20] = {0};
strcpy(name, counter_info_ptr[counter_type]->title);
const std::string &name = counter_info_ptr[counter_type]->title;

char name_suffix[10] = {0};
switch (task_spec::get(task_id)->type) {
Expand All @@ -573,7 +573,7 @@ std::string query_data_handler(const std::vector<std::string> &args)
uint64_t sample =
s_spec_profilers[task_id].ptr[counter_type]->get_latest_sample();

data.push_back(nv_pair{std::string(name) + std::string(name_suffix), sample});
data.push_back(nv_pair{name + std::string(name_suffix), sample});
}
}
if (task_spec::get(task_id)->type == TASK_TYPE_RPC_RESPONSE ||
Expand Down
32 changes: 14 additions & 18 deletions src/runtime/profiler_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,24 @@ enum perf_counter_ptr_type
class counter_info
{
public:
counter_info(const std::vector<const char *> &command_keys,
perf_counter_ptr_type _index,
dsn_perf_counter_type_t _type,
const char *_title,
const char *_unit)
: type(_type), title(_title), unit_name(_unit)
counter_info(const std::vector<std::string> &command_keys,
perf_counter_ptr_type ptr_type,
dsn_perf_counter_type_t counter_type,
const std::string &title,
const std::string &unit)
: keys(command_keys),
counter_ptr_type(ptr_type),
type(counter_type),
title(title),
unit_name(unit)
{
for (auto key : command_keys) {
if (key != nullptr) {
keys.push_back(key);
auto it = pointer_type.find(std::string(key));
dassert(it == pointer_type.end(), "command '%s' already regisered", key);
pointer_type[std::string(key)] = _index;
}
}
}

static std::map<std::string, perf_counter_ptr_type> pointer_type;
std::vector<const char *> keys;
std::vector<std::string> keys;
perf_counter_ptr_type counter_ptr_type;
dsn_perf_counter_type_t type;
const char *title;
const char *unit_name;
std::string title;
std::string unit_name;
};

class profiler_output_data_type
Expand Down