@@ -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 ;
@@ -1481,6 +1497,73 @@ void InfoCmd::InfoDebug(std::string& info) {
14811497 g_pika_server->ServerStatus (&info);
14821498}
14831499
1500+ void InfoCmd::InfoCommandP99 (std::string& info) {
1501+ std::stringstream tmp_stream;
1502+ tmp_stream.precision (2 );
1503+ tmp_stream.setf (std::ios::fixed);
1504+ tmp_stream << " # Commands P99" << " \r\n " ;
1505+ auto histogram_family = g_pika_cmd_table_manager->GetHistograms ();
1506+
1507+ for (const auto & metric_family : histogram_family->Collect ()) {
1508+ for (const auto & metric : metric_family.metric ) {
1509+ std::string command_name;
1510+
1511+ for (const auto & label : metric.label ) {
1512+ if (label.name == " command" ) {
1513+ command_name = label.value ;
1514+ break ;
1515+ }
1516+ }
1517+
1518+ double total_count = metric.histogram .sample_count ;
1519+
1520+ if (command_name.empty ()) {
1521+ tmp_stream << " Command: UNKNOWN\r\n " ;
1522+ } else {
1523+ tmp_stream << " Command: " << command_name << " \r\n " ;
1524+ }
1525+
1526+ double tp99_threshold = total_count * 0.99 ;
1527+ double tp999_threshold = total_count * 0.999 ;
1528+ double tp9999_threshold = total_count * 0.9999 ;
1529+ double tp99 = 0 , tp999 = 0 , tp9999 = 0 ;
1530+
1531+ for (const auto & bucket : metric.histogram .bucket ) {
1532+ if (bucket.cumulative_count >= tp99_threshold && tp99 == 0 ) {
1533+ tp99 = bucket.upper_bound ;
1534+ }
1535+ if (bucket.cumulative_count >= tp999_threshold && tp999 == 0 ) {
1536+ tp999 = bucket.upper_bound ;
1537+ }
1538+ if (bucket.cumulative_count >= tp9999_threshold && tp9999 == 0 ) {
1539+ tp9999 = bucket.upper_bound ;
1540+ break ;
1541+ }
1542+ }
1543+ tmp_stream << " TP99 ms: " << tp99 << " \r\n " ;
1544+ tmp_stream << " TP999 ms: " << tp999 << " \r\n " ;
1545+ tmp_stream << " TP9999 ms: " << tp9999 << " \r\n " ;
1546+ tmp_stream << " ----------------------\r\n " ;
1547+ }
1548+ }
1549+
1550+ info.append (tmp_stream.str ());
1551+ }
1552+
1553+ void InfoCmd::InfoSlowCommand (std::string& info) {
1554+ std::stringstream tmp_stream;
1555+ tmp_stream.precision (2 );
1556+ tmp_stream.setf (std::ios::fixed);
1557+ auto stats = g_pika_cmd_table_manager->GetSlowCommandCount ();
1558+ tmp_stream << " # SlowCommand Count" << " \r\n " ;
1559+ for (auto iter : stats) {
1560+ if (iter.second .cmd_count != 0 ) {
1561+ tmp_stream << iter.first << " :slow_count=" << iter.second .cmd_count << " \r\n " ;
1562+ }
1563+ }
1564+ info.append (tmp_stream.str ());
1565+ }
1566+
14841567void InfoCmd::InfoCommandStats (std::string& info) {
14851568 std::stringstream tmp_stream;
14861569 tmp_stream.precision (2 );
0 commit comments