@@ -1116,8 +1116,8 @@ class aggregate_stats_calcs
11161116class total_aggregate_stats : public aggregate_stats
11171117{
11181118public:
1119- total_aggregate_stats (const std::string & entity_type, stat_var_map &&stat_vars)
1120- : _my_entity_type(entity_type), _my_stat_vars(std::move(stat_vars))
1119+ total_aggregate_stats (std::string entity_type, stat_var_map &&stat_vars)
1120+ : _my_entity_type(std::move( entity_type) ), _my_stat_vars(std::move(stat_vars))
11211121 {
11221122 }
11231123
@@ -1134,13 +1134,14 @@ class total_aggregate_stats : public aggregate_stats
11341134
11351135 void calc_rates (double duration_s) override
11361136 {
1137- for (auto &stat_var : _my_stat_vars) {
1138- *stat_var. second /= duration_s;
1137+ for (auto &[_, stat_var] : _my_stat_vars) {
1138+ *stat_var /= duration_s;
11391139 }
11401140 }
11411141
11421142private:
11431143 DISALLOW_COPY_AND_ASSIGN (total_aggregate_stats);
1144+ DISALLOW_MOVE_AND_ASSIGN (total_aggregate_stats);
11441145
11451146 const std::string _my_entity_type;
11461147 stat_var_map _my_stat_vars;
@@ -1160,10 +1161,10 @@ using table_stat_map = std::unordered_map<int32_t, stat_var_map>;
11601161class table_aggregate_stats : public aggregate_stats
11611162{
11621163public:
1163- table_aggregate_stats (const std::string & entity_type,
1164+ table_aggregate_stats (std::string entity_type,
11641165 table_stat_map &&table_stats,
1165- const std::unordered_set<dsn::gpid> & partitions)
1166- : _my_entity_type(entity_type),
1166+ std::unordered_set<dsn::gpid> partitions)
1167+ : _my_entity_type(std::move( entity_type) ),
11671168 _my_table_stats (std::move(table_stats)),
11681169 _my_partitions(std::move(partitions))
11691170 {
@@ -1178,21 +1179,21 @@ class table_aggregate_stats : public aggregate_stats
11781179 {
11791180 RETURN_NULL_STAT_VARS_IF (entity_type != _my_entity_type);
11801181
1181- int32_t metric_table_id;
1182+ int32_t metric_table_id{- 1 } ;
11821183 RETURN_NULL_STAT_VARS_IF_NOT_OK (dsn::parse_metric_table_id (entity_attrs, metric_table_id));
11831184
11841185 // Empty `_my_partitions` means there is no restriction; otherwise, the partition id
11851186 // should be found in `_my_partitions`.
11861187 if (!_my_partitions.empty ()) {
1187- int32_t metric_partition_id;
1188+ int32_t metric_partition_id{- 1 } ;
11881189 RETURN_NULL_STAT_VARS_IF_NOT_OK (
11891190 dsn::parse_metric_partition_id (entity_attrs, metric_partition_id));
11901191
11911192 dsn::gpid metric_pid (metric_table_id, metric_partition_id);
11921193 RETURN_NULL_STAT_VARS_IF (_my_partitions.find (metric_pid) == _my_partitions.end ());
11931194 }
11941195
1195- const auto & table_stat = _my_table_stats.find (metric_table_id);
1196+ const auto table_stat = _my_table_stats.find (metric_table_id);
11961197 CHECK_TRUE (table_stat != _my_table_stats.end ());
11971198
11981199 *stat_vars = &table_stat->second ;
@@ -1201,15 +1202,16 @@ class table_aggregate_stats : public aggregate_stats
12011202
12021203 void calc_rates (double duration_s) override
12031204 {
1204- for (auto &table_stats : _my_table_stats) {
1205- for (auto &stat_var : table_stats. second ) {
1206- *stat_var. second /= duration_s;
1205+ for (auto &[_, table_stat] : _my_table_stats) {
1206+ for (auto &[_, stat_var] : table_stat ) {
1207+ *stat_var /= duration_s;
12071208 }
12081209 }
12091210 }
12101211
12111212private:
12121213 DISALLOW_COPY_AND_ASSIGN (table_aggregate_stats);
1214+ DISALLOW_MOVE_AND_ASSIGN (table_aggregate_stats);
12131215
12141216 const std::string _my_entity_type;
12151217 table_stat_map _my_table_stats;
@@ -1225,8 +1227,8 @@ using partition_stat_map = std::unordered_map<dsn::gpid, stat_var_map>;
12251227class partition_aggregate_stats : public aggregate_stats
12261228{
12271229public:
1228- partition_aggregate_stats (const std::string & entity_type, partition_stat_map &&partition_stats)
1229- : _my_entity_type(entity_type), _my_partition_stats(std::move(partition_stats))
1230+ partition_aggregate_stats (std::string entity_type, partition_stat_map &&partition_stats)
1231+ : _my_entity_type(std::move( entity_type) ), _my_partition_stats(std::move(partition_stats))
12301232 {
12311233 }
12321234
@@ -1239,15 +1241,15 @@ class partition_aggregate_stats : public aggregate_stats
12391241 {
12401242 RETURN_NULL_STAT_VARS_IF (entity_type != _my_entity_type);
12411243
1242- int32_t metric_table_id;
1244+ int32_t metric_table_id{- 1 } ;
12431245 RETURN_NULL_STAT_VARS_IF_NOT_OK (dsn::parse_metric_table_id (entity_attrs, metric_table_id));
12441246
1245- int32_t metric_partition_id;
1247+ int32_t metric_partition_id{- 1 } ;
12461248 RETURN_NULL_STAT_VARS_IF_NOT_OK (
12471249 dsn::parse_metric_partition_id (entity_attrs, metric_partition_id));
12481250
12491251 dsn::gpid metric_pid (metric_table_id, metric_partition_id);
1250- const auto & partition_stat = _my_partition_stats.find (metric_pid);
1252+ const auto partition_stat = _my_partition_stats.find (metric_pid);
12511253 RETURN_NULL_STAT_VARS_IF (partition_stat == _my_partition_stats.end ());
12521254
12531255 *stat_vars = &partition_stat->second ;
@@ -1256,20 +1258,70 @@ class partition_aggregate_stats : public aggregate_stats
12561258
12571259 void calc_rates (double duration_s) override
12581260 {
1259- for (auto &partition_stats : _my_partition_stats) {
1260- for (auto &stat_var : partition_stats. second ) {
1261- *stat_var. second /= duration_s;
1261+ for (auto &[_, partition_stat] : _my_partition_stats) {
1262+ for (auto &[_, stat_var] : partition_stat ) {
1263+ *stat_var /= duration_s;
12621264 }
12631265 }
12641266 }
12651267
12661268private:
12671269 DISALLOW_COPY_AND_ASSIGN (partition_aggregate_stats);
1270+ DISALLOW_MOVE_AND_ASSIGN (partition_aggregate_stats);
12681271
12691272 const std::string _my_entity_type;
12701273 partition_stat_map _my_partition_stats;
12711274};
12721275
1276+ using profiler_stat_map = std::unordered_map<std::string, stat_var_map>;
1277+
1278+ // Profiler-level aggregation over the fetched metrics. There are 2 dimensions for the aggregation:
1279+ // * the task name, the name of the RPC task, from the attributes of the metric entity;
1280+ // * the metric name, which is also the key of `stat_var_map`.
1281+ class profiler_aggregate_stats : public aggregate_stats
1282+ {
1283+ public:
1284+ profiler_aggregate_stats (std::string entity_type, profiler_stat_map &&profiler_stats)
1285+ : _my_entity_type(std::move(entity_type)), _my_profiler_stats(std::move(profiler_stats))
1286+ {
1287+ }
1288+
1289+ ~profiler_aggregate_stats () override = default ;
1290+
1291+ protected:
1292+ dsn::error_s get_stat_vars (const std::string &entity_type,
1293+ const dsn::metric_entity::attr_map &entity_attrs,
1294+ stat_var_map **stat_vars) override
1295+ {
1296+ RETURN_NULL_STAT_VARS_IF (entity_type != _my_entity_type);
1297+
1298+ const auto attr = std::as_const (entity_attrs).find (" task_name" );
1299+ RETURN_NULL_STAT_VARS_IF (attr == entity_attrs.end ());
1300+
1301+ const auto profiler_stat = _my_profiler_stats.find (attr->second );
1302+ RETURN_NULL_STAT_VARS_IF (profiler_stat == _my_profiler_stats.end ());
1303+
1304+ *stat_vars = &profiler_stat->second ;
1305+ return dsn::error_s::ok ();
1306+ }
1307+
1308+ void calc_rates (double duration_s) override
1309+ {
1310+ for (auto &[_, profiler_stat] : _my_profiler_stats) {
1311+ for (auto &[_, stat_var] : profiler_stat) {
1312+ *stat_var /= duration_s;
1313+ }
1314+ }
1315+ }
1316+
1317+ private:
1318+ DISALLOW_COPY_AND_ASSIGN (profiler_aggregate_stats);
1319+ DISALLOW_MOVE_AND_ASSIGN (profiler_aggregate_stats);
1320+
1321+ const std::string _my_entity_type;
1322+ profiler_stat_map _my_profiler_stats;
1323+ };
1324+
12731325inline std::vector<std::pair<bool , std::string>>
12741326call_remote_command (shell_context *sc,
12751327 const std::vector<node_desc> &nodes,
0 commit comments