diff --git a/include/dsn/utils/latency_tracer.h b/include/dsn/utils/latency_tracer.h index 573b5c10bd..f3b68e090d 100644 --- a/include/dsn/utils/latency_tracer.h +++ b/include/dsn/utils/latency_tracer.h @@ -69,10 +69,14 @@ DSN_DECLARE_bool(enable_latency_tracer); class latency_tracer { public: + //-is_sub: + // if `is_sub`=true means its points will be dumped by parent tracer and won't be dumped + // repeatedly in destructor + //-threshold: // threshold < 0: don't dump any trace points // threshold = 0: dump all trace points // threshold > 0: dump the trace point when time_used > threshold - latency_tracer(const std::string &name, uint64_t threshold = 0); + latency_tracer(const std::string &name, bool is_sub = false, uint64_t threshold = 0); ~latency_tracer(); diff --git a/src/replica/mutation.cpp b/src/replica/mutation.cpp index 30f84a1ead..f980b9ab8a 100644 --- a/src/replica/mutation.cpp +++ b/src/replica/mutation.cpp @@ -59,8 +59,10 @@ mutation::mutation() _appro_data_bytes = sizeof(mutation_header); _create_ts_ns = dsn_now_ns(); _tid = ++s_tid; - tracer = std::make_shared( - fmt::format("{}[{}]", "mutation", _tid), FLAGS_abnormal_write_trace_latency_threshold); + tracer = + std::make_shared(fmt::format("{}[{}]", "mutation", _tid), + false, + FLAGS_abnormal_write_trace_latency_threshold); } mutation_ptr mutation::copy_no_reply(const mutation_ptr &old_mu) diff --git a/src/utils/latency_tracer.cpp b/src/utils/latency_tracer.cpp index 1896d5cfd9..09d7c19ea4 100644 --- a/src/utils/latency_tracer.cpp +++ b/src/utils/latency_tracer.cpp @@ -25,8 +25,8 @@ namespace utils { DSN_DEFINE_bool("replication", enable_latency_tracer, false, "whether enable the latency tracer"); -latency_tracer::latency_tracer(const std::string &name, uint64_t threshold) - : _name(name), _threshold(threshold), _is_sub(false), _start_time(dsn_now_ns()) +latency_tracer::latency_tracer(const std::string &name, bool is_sub, uint64_t threshold) + : _name(name), _threshold(threshold), _is_sub(is_sub), _start_time(dsn_now_ns()) { } @@ -56,7 +56,7 @@ void latency_tracer::set_sub_tracer(const std::shared_ptr &trace if (!FLAGS_enable_latency_tracer) { return; } - tracer->_is_sub = true; + _sub_tracer = tracer; } diff --git a/src/utils/test/latency_tracer_test.cpp b/src/utils/test/latency_tracer_test.cpp index 88f15d730d..2a905b84b0 100644 --- a/src/utils/test/latency_tracer_test.cpp +++ b/src/utils/test/latency_tracer_test.cpp @@ -41,12 +41,12 @@ class latency_tracer_test : public testing::Test void init_trace_points() { - _tracer1 = std::make_shared("name1", true); + _tracer1 = std::make_shared("name1"); for (int i = 0; i < _tracer1_stage_count; i++) { ADD_CUSTOM_POINT(_tracer1, fmt::format("stage{}", i)); } - _tracer2 = std::make_shared("name2", true); + _tracer2 = std::make_shared("name2"); for (int i = 0; i < _tracer2_stage_count; i++) { ADD_CUSTOM_POINT(_tracer2, fmt::format("stage{}", i));