Skip to content

Commit 35cbda4

Browse files
zhao liweiwutao1
authored andcommitted
feat: add a interface to get perf-counters info of all partitions of all apps (#417)
1 parent 44a5293 commit 35cbda4

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

src/shell/command_helper.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,70 @@ inline bool decode_node_perf_counter_info(const dsn::rpc_address &node_addr,
657657
return true;
658658
}
659659

660+
// rows: key-app name, value-perf counters for each partition
661+
inline bool get_app_partition_stat(shell_context *sc,
662+
std::map<std::string, std::vector<row_data>> &rows)
663+
{
664+
// get apps and nodes
665+
std::vector<::dsn::app_info> apps;
666+
std::vector<node_desc> nodes;
667+
if (!get_apps_and_nodes(sc, apps, nodes)) {
668+
return false;
669+
}
670+
671+
// get app_id --> app_name
672+
std::map<int32_t, std::string> app_id_name;
673+
for (::dsn::app_info &app : apps) {
674+
app_id_name[app.app_id] = app.app_name;
675+
rows[app.app_name].resize(app.partition_count);
676+
}
677+
678+
// get app_id --> partitions
679+
std::map<int32_t, std::vector<dsn::partition_configuration>> app_partitions;
680+
if (!get_app_partitions(sc, apps, app_partitions)) {
681+
return false;
682+
}
683+
684+
// get all of the perf counters with format ".*@.*"
685+
::dsn::command command;
686+
command.cmd = "perf-counters";
687+
char tmp[256];
688+
sprintf(tmp, ".*@.*");
689+
command.arguments.emplace_back(tmp);
690+
std::vector<std::pair<bool, std::string>> results;
691+
call_remote_command(sc, nodes, command, results);
692+
693+
for (int i = 0; i < nodes.size(); ++i) {
694+
// decode info of perf-counters on node i
695+
dsn::perf_counter_info info;
696+
if (!decode_node_perf_counter_info(nodes[i].address, results[i], info)) {
697+
return false;
698+
}
699+
700+
for (dsn::perf_counter_metric &m : info.counters) {
701+
// get app_id/partition_id/counter_name from the name of perf-counter
702+
int32_t app_id_x, partition_index_x;
703+
std::string counter_name;
704+
if (!parse_app_pegasus_perf_counter_name(
705+
m.name, app_id_x, partition_index_x, counter_name)) {
706+
continue;
707+
}
708+
709+
// only on primary partition will be counted
710+
auto find = app_partitions.find(app_id_x);
711+
if (find != app_partitions.end() &&
712+
find->second[partition_index_x].primary == nodes[i].address) {
713+
const std::string &app_name = app_id_name[app_id_x];
714+
row_data &row = rows[app_name][partition_index_x];
715+
row.row_name = std::to_string(partition_index_x);
716+
row.app_id = app_id_x;
717+
update_app_pegasus_perf_counter(row, counter_name, m.value);
718+
}
719+
}
720+
}
721+
return true;
722+
}
723+
660724
inline bool
661725
get_app_stat(shell_context *sc, const std::string &app_name, std::vector<row_data> &rows)
662726
{

0 commit comments

Comments
 (0)