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