From 4e7918288698647a5c950ad923901d285e1e66ab Mon Sep 17 00:00:00 2001 From: Sarath Lakshman Date: Wed, 3 Apr 2024 08:57:10 -0700 Subject: [PATCH] debugging: Add stats latency printing thread in magma_bench Change-Id: I8fbc5317191c840c19aedf6dd4648be6664b3e0a --- magma/kvstore/kvstore.cc | 5 +++++ magma/kvstore/write.cc | 3 +++ tools/magma_bench/magma_engine.cc | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/magma/kvstore/kvstore.cc b/magma/kvstore/kvstore.cc index 0bc1aa06..5789519e 100644 --- a/magma/kvstore/kvstore.cc +++ b/magma/kvstore/kvstore.cc @@ -645,6 +645,9 @@ Status KVStore::flushMemTables(WAL* wal, sFlush->Reset(); lFlush->Reset(); + std::this_thread::sleep_for(std::chrono::seconds(10)); // Adjust + // time interval as needed + if (!memoryOptimisedWrite) { releaseFlushBarrier(); } @@ -656,6 +659,8 @@ Status KVStore::flushMemTables(WAL* wal, }); setStatus(executeFlush(kFlush, sFlush, lFlush, batch)); + std::this_thread::sleep_for( + std::chrono::seconds(10)); // Adjust time interval as needed bool committed = false; // Perform persistence diff --git a/magma/kvstore/write.cc b/magma/kvstore/write.cc index 2328ce8a..a1dac054 100644 --- a/magma/kvstore/write.cc +++ b/magma/kvstore/write.cc @@ -350,6 +350,9 @@ Status KVStore::WriteDocs( tryUpdateHistoryMode(historyMode, batchLowSeqno); + std::this_thread::sleep_for(std::chrono::seconds(5)); // Adjust time + // interval as needed + // At this point, the batch is safely stored in the WAL and // (written to the write cache or to sstables) so we can create a snaphsot. createSnapshot(); diff --git a/tools/magma_bench/magma_engine.cc b/tools/magma_bench/magma_engine.cc index 9f37440c..20def712 100644 --- a/tools/magma_bench/magma_engine.cc +++ b/tools/magma_bench/magma_engine.cc @@ -202,6 +202,31 @@ public: const_cast(value.Data())); } } + + auto statsThreadFunc = [this]() { + while (true) { + Magma::MagmaStats stats; + auto start = std::chrono::steady_clock::now(); // Start time + db->GetStats(stats); + auto end = std::chrono::steady_clock::now(); // End time + auto elapsed = + std::chrono::duration_cast( + end - start); // Time taken in milliseconds + + // Print stats along with time taken + std::cout << "Stats: " + << ", Time taken: " << elapsed.count() << " ms" + << std::endl; + + // Sleep for some time before next call + std::this_thread::sleep_for(std::chrono::seconds( + 1)); // Adjust time interval as needed + } + }; + + // Spawn a thread to periodically call db->GetStats() + std::thread statsThread(statsThreadFunc); + statsThread.detach(); } void* CreateContext() override { -- 2.39.2 (Apple Git-143)