@@ -882,6 +882,8 @@ const std::string InfoCmd::kKeyspaceSection = "keyspace";
882882const std::string InfoCmd::kDataSection = " data" ;
883883const std::string InfoCmd::kRocksDBSection = " rocksdb" ;
884884const std::string InfoCmd::kDebugSection = " debug" ;
885+ const std::string InfoCmd::kCommandP99Section = " commandp99" ;
886+ const std::string InfoCmd::kSlowCommandSection = " slowcommand" ;
885887const std::string InfoCmd::kCommandStatsSection = " commandstats" ;
886888const std::string InfoCmd::kCacheSection = " cache" ;
887889
@@ -967,6 +969,10 @@ void InfoCmd::DoInitial() {
967969 info_section_ = kInfoDebug ;
968970 } else if (strcasecmp (argv_[1 ].data (), kCommandStatsSection .data ()) == 0 ) {
969971 info_section_ = kInfoCommandStats ;
972+ } else if (strcasecmp (argv_[1 ].data (), kCommandP99Section .data ()) == 0 ) {
973+ info_section_ = kInfoCommandP99 ;
974+ } else if (strcasecmp (argv_[1 ].data (), kSlowCommandSection .data ()) == 0 ) {
975+ info_section_ = kInfoSlowCommand ;
970976 } else if (strcasecmp (argv_[1 ].data (), kCacheSection .data ()) == 0 ) {
971977 info_section_ = kInfoCache ;
972978 } else {
@@ -1008,6 +1014,10 @@ void InfoCmd::Do() {
10081014 info.append (" \r\n " );
10091015 InfoCommandStats (info);
10101016 info.append (" \r\n " );
1017+ InfoCommandP99 (info);
1018+ info.append (" \r\n " );
1019+ InfoSlowCommand (info);
1020+ info.append (" \r\n " );
10111021 InfoCache (info, db_);
10121022 info.append (" \r\n " );
10131023 InfoCPU (info);
@@ -1051,6 +1061,12 @@ void InfoCmd::Do() {
10511061 case kInfoCommandStats :
10521062 InfoCommandStats (info);
10531063 break ;
1064+ case kInfoCommandP99 :
1065+ InfoCommandP99 (info);
1066+ break ;
1067+ case kInfoSlowCommand :
1068+ InfoSlowCommand (info);
1069+ break ;
10541070 case kInfoCache :
10551071 InfoCache (info, db_);
10561072 break ;
@@ -1499,6 +1515,73 @@ void InfoCmd::InfoCommandStats(std::string& info) {
14991515 info.append (tmp_stream.str ());
15001516}
15011517
1518+ void InfoCmd::InfoCommandP99 (std::string& info) {
1519+ std::stringstream tmp_stream;
1520+ tmp_stream.precision (2 );
1521+ tmp_stream.setf (std::ios::fixed);
1522+ tmp_stream << " # Commands P99" << " \r\n " ;
1523+ auto data = g_pika_cmd_table_manager->GetHistogramsData ();
1524+ auto * histogram_family = data->family ;
1525+ for (const auto & metric_family : histogram_family->Collect ()) {
1526+ for (const auto & metric : metric_family.metric ) {
1527+ std::string command_name;
1528+
1529+ for (const auto & label : metric.label ) {
1530+ if (label.name == " command" ) {
1531+ command_name = label.value ;
1532+ break ;
1533+ }
1534+ }
1535+
1536+ double total_count = metric.histogram .sample_count ;
1537+
1538+ if (command_name.empty ()) {
1539+ tmp_stream << " Command: UNKNOWN\r\n " ;
1540+ } else {
1541+ tmp_stream << " Command: " << command_name << " \r\n " ;
1542+ }
1543+
1544+ double tp99_threshold = total_count * 0.99 ;
1545+ double tp999_threshold = total_count * 0.999 ;
1546+ double tp9999_threshold = total_count * 0.9999 ;
1547+ double tp99 = 0 , tp999 = 0 , tp9999 = 0 ;
1548+
1549+ for (const auto & bucket : metric.histogram .bucket ) {
1550+ if (bucket.cumulative_count >= tp99_threshold && tp99 == 0 ) {
1551+ tp99 = bucket.upper_bound ;
1552+ }
1553+ if (bucket.cumulative_count >= tp999_threshold && tp999 == 0 ) {
1554+ tp999 = bucket.upper_bound ;
1555+ }
1556+ if (bucket.cumulative_count >= tp9999_threshold && tp9999 == 0 ) {
1557+ tp9999 = bucket.upper_bound ;
1558+ break ;
1559+ }
1560+ }
1561+ tmp_stream << " TP99 ms: " << tp99 << " \r\n " ;
1562+ tmp_stream << " TP999 ms: " << tp999 << " \r\n " ;
1563+ tmp_stream << " TP9999 ms: " << tp9999 << " \r\n " ;
1564+ tmp_stream << " ----------------------\r\n " ;
1565+ }
1566+ }
1567+
1568+ info.append (tmp_stream.str ());
1569+ }
1570+
1571+ void InfoCmd::InfoSlowCommand (std::string& info) {
1572+ std::stringstream tmp_stream;
1573+ tmp_stream.precision (2 );
1574+ tmp_stream.setf (std::ios::fixed);
1575+ auto stats = g_pika_cmd_table_manager->GetSlowCommandCount ();
1576+ tmp_stream << " # SlowCommand Count" << " \r\n " ;
1577+ for (auto iter : stats) {
1578+ if (iter.second .cmd_count != 0 ) {
1579+ tmp_stream << iter.first << " :slow_count=" << iter.second .cmd_count << " \r\n " ;
1580+ }
1581+ }
1582+ info.append (tmp_stream.str ());
1583+ }
1584+
15021585void InfoCmd::InfoCache (std::string& info, std::shared_ptr<DB> db) {
15031586 std::stringstream tmp_stream;
15041587 tmp_stream << " # Cache" << " \r\n " ;
0 commit comments