From 7ca1a1f0d8a3edde5c50292599b98e883bd66247 Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Wed, 10 Oct 2018 09:58:15 -0700 Subject: [PATCH] Fix trace_analyzer potential huge memory wasting due to no valid query analyzed (#4473) Summary: If the query types being analyzed do not appear in the trace, the current trace_analyzer will use 0 as the begin time, which create the time duration from 1970/01/01 to the now time. It will waste huge memory. Fixed by adding the trace_create_time to limit the duration. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4473 Differential Revision: D10246204 Pulled By: zhichao-cao fbshipit-source-id: 42850b080b2e62f586fe73afd7737c2246d1a8c8 --- tools/trace_analyzer_tool.cc | 5 +++++ tools/trace_analyzer_tool.h | 1 + 2 files changed, 6 insertions(+) diff --git a/tools/trace_analyzer_tool.cc b/tools/trace_analyzer_tool.cc index 7915322f0..e6ec48cd1 100644 --- a/tools/trace_analyzer_tool.cc +++ b/tools/trace_analyzer_tool.cc @@ -276,6 +276,7 @@ TraceAnalyzer::TraceAnalyzer(std::string& trace_path, std::string& output_path, total_access_keys_ = 0; total_gets_ = 0; total_writes_ = 0; + trace_create_time_ = 0; begin_time_ = 0; end_time_ = 0; time_series_start_ = 0; @@ -422,6 +423,7 @@ Status TraceAnalyzer::StartProcessing() { fprintf(stderr, "Cannot read the header\n"); return s; } + trace_create_time_ = header.ts; if (FLAGS_output_time_series) { time_series_start_ = header.ts; } @@ -740,6 +742,9 @@ Status TraceAnalyzer::MakeStatisticCorrelation(TraceStats& stats, // Process the statistics of QPS Status TraceAnalyzer::MakeStatisticQPS() { + if(begin_time_ == 0) { + begin_time_ = trace_create_time_; + } uint32_t duration = static_cast((end_time_ - begin_time_) / 1000000); int ret; diff --git a/tools/trace_analyzer_tool.h b/tools/trace_analyzer_tool.h index ac9f42f1c..b171ef22c 100644 --- a/tools/trace_analyzer_tool.h +++ b/tools/trace_analyzer_tool.h @@ -204,6 +204,7 @@ class TraceAnalyzer { uint64_t total_access_keys_; uint64_t total_gets_; uint64_t total_writes_; + uint64_t trace_create_time_; uint64_t begin_time_; uint64_t end_time_; uint64_t time_series_start_;