2020#include " net/src/worker_thread.h"
2121#include " src/pstd/include/scope_record_lock.h"
2222
23+ #include " rocksdb/perf_context.h"
24+ #include " rocksdb/iostats_context.h"
25+ #include " util/random.h"
26+
2327extern std::unique_ptr<PikaConf> g_pika_conf;
2428extern PikaServer* g_pika_server;
2529extern std::unique_ptr<PikaReplicaManager> g_pika_rm;
@@ -46,6 +50,7 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
4650 }
4751 return tmp_ptr;
4852 }
53+
4954 c_ptr->SetCacheMissedInRtc (cache_miss_in_rtc);
5055 c_ptr->SetConn (shared_from_this ());
5156 c_ptr->SetResp (resp_ptr);
@@ -202,21 +207,32 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
202207 }
203208 }
204209
210+
211+ // set rocksdb perflevel based on RocksDBPerfLevel and RocksDBPerfPercent
212+ int rocksdb_perf_level = 2 ;
213+ if (rocksdb::Random::GetTLSInstance ()->PercentTrue (g_pika_conf->RocksDBPerfPercent ())) {
214+ rocksdb_perf_level = g_pika_conf->RocksDBPerfLevel ();
215+ }
216+ rocksdb::SetPerfLevel (rocksdb::PerfLevel (rocksdb_perf_level));
217+
218+ // Perform some operations
219+ rocksdb::get_perf_context ()->Reset ();
205220 // Process Command
206221 c_ptr->Execute ();
222+
207223 time_stat_->process_done_ts_ = pstd::NowMicros ();
208224 auto cmdstat_map = g_pika_cmd_table_manager->GetCommandStatMap ();
209225 (*cmdstat_map)[opt].cmd_count .fetch_add (1 );
210226 (*cmdstat_map)[opt].cmd_time_consuming .fetch_add (time_stat_->total_time ());
211227
212228 if (g_pika_conf->slowlog_slower_than () >= 0 ) {
213- ProcessSlowlog (argv, c_ptr-> GetDoDuration () );
229+ ProcessSlowlog (argv, c_ptr);
214230 }
215231
216232 return c_ptr;
217233}
218234
219- void PikaClientConn::ProcessSlowlog (const PikaCmdArgsType& argv, uint64_t do_duration ) {
235+ void PikaClientConn::ProcessSlowlog (const PikaCmdArgsType& argv, std::shared_ptr<Cmd> c_ptr ) {
220236 if (time_stat_->total_time () > g_pika_conf->slowlog_slower_than ()) {
221237 g_pika_server->SlowlogPushEntry (argv, time_stat_->start_ts () / 1000000 , time_stat_->total_time ());
222238 if (g_pika_conf->slowlog_write_errorlog ()) {
@@ -241,7 +257,8 @@ void PikaClientConn::ProcessSlowlog(const PikaCmdArgsType& argv, uint64_t do_dur
241257 << " , before_queue_time(ms): " << time_stat_->before_queue_time () / 1000
242258 << " , queue_time(ms): " << time_stat_->queue_time () / 1000
243259 << " , process_time(ms): " << time_stat_->process_time () / 1000
244- << " , cmd_time(ms): " << do_duration / 1000 ;
260+ << " , " << c_ptr->StagesDurationSummary (true /* skip zero counter*/ )
261+ << " , " << rocksdb::get_perf_context ()->ToString (true );
245262 }
246263 }
247264}
0 commit comments