From c2fa24b43a598f7f8c432d28054f932e4a7bc001 Mon Sep 17 00:00:00 2001 From: QinZuoyan Date: Fri, 22 Feb 2019 11:44:49 +0800 Subject: [PATCH] shell: improve app_stat to add app_id and partition_count column (#285) --- scripts/pegasus_stat_available.sh | 5 +++-- src/shell/command_helper.h | 4 ++++ src/shell/commands/table_management.cpp | 12 +++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/pegasus_stat_available.sh b/scripts/pegasus_stat_available.sh index 2929093fa8..1ef67b447e 100755 --- a/scripts/pegasus_stat_available.sh +++ b/scripts/pegasus_stat_available.sh @@ -29,8 +29,9 @@ fi app_count=`cat $app_stat_result | wc -l` app_count=$((app_count-2)) -data_size=`cat $app_stat_result | tail -n 1 | awk '{print $(NF-3)}' | sed 's/\.00$//'` -data_size=$(((data_size+1024)/1024)) +data_size_column=`cat $app_stat_result | awk '/file_mb/{ for(i = 1; i <= NF; i++) { if ($i == "file_mb") print i; } }'` +data_size=`cat $app_stat_result | tail -n 1 | awk '{print $'$data_size_column'}' | sed 's/\.00$//'` +data_size=$(((data_size+1023)/1024)) all_result="/tmp/$UID.$PID.pegasus.stat_available.all_result" rm -f $all_result diff --git a/src/shell/command_helper.h b/src/shell/command_helper.h index 7420c47b75..b624978a65 100644 --- a/src/shell/command_helper.h +++ b/src/shell/command_helper.h @@ -466,6 +466,8 @@ inline bool parse_app_pegasus_perf_counter_name(const std::string &name, struct row_data { std::string row_name; + int32_t app_id = 0; + int32_t partition_count = 0; double get_qps = 0; double multi_get_qps = 0; double put_qps = 0; @@ -603,6 +605,8 @@ get_app_stat(shell_context *sc, const std::string &app_name, std::vector app_row_idx; // app_id --> row_idx for (::dsn::app_info &app : apps) { rows[idx].row_name = app.app_name; + rows[idx].app_id = app.app_id; + rows[idx].partition_count = app.partition_count; app_row_idx[app.app_id] = idx; idx++; } diff --git a/src/shell/commands/table_management.cpp b/src/shell/commands/table_management.cpp index e0c15faf1e..2ca32d6af7 100644 --- a/src/shell/commands/table_management.cpp +++ b/src/shell/commands/table_management.cpp @@ -428,8 +428,10 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args) rows.resize(rows.size() + 1); row_data &sum = rows.back(); + sum.row_name = "(sum)"; for (int i = 0; i < rows.size() - 1; ++i) { row_data &row = rows[i]; + sum.partition_count += row.partition_count; sum.get_qps += row.get_qps; sum.multi_get_qps += row.multi_get_qps; sum.put_qps += row.put_qps; @@ -465,7 +467,11 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args) std::ostream out(buf); ::dsn::utils::table_printer tp; - tp.add_title(app_name.empty() ? "app" : "pidx"); + tp.add_title(app_name.empty() ? "app_name" : "pidx"); + if (app_name.empty()) { + tp.add_column("app_id", tp_alignment::kRight); + tp.add_column("pcount", tp_alignment::kRight); + } tp.add_column("GET", tp_alignment::kRight); tp.add_column("MGET", tp_alignment::kRight); tp.add_column("PUT", tp_alignment::kRight); @@ -491,6 +497,10 @@ bool app_stat(command_executor *e, shell_context *sc, arguments args) for (row_data &row : rows) { tp.add_row(row.row_name); + if (app_name.empty()) { + tp.append_data(row.app_id); + tp.append_data(row.partition_count); + } tp.append_data(row.get_qps); tp.append_data(row.multi_get_qps); tp.append_data(row.put_qps);