Skip to content

Commit

Permalink
fix: set the tracer type when init (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverneverer authored Sep 10, 2020
1 parent 8ec8ba6 commit 7868d64
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion include/dsn/utils/latency_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 4 additions & 2 deletions src/replica/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dsn::utils::latency_tracer>(
fmt::format("{}[{}]", "mutation", _tid), FLAGS_abnormal_write_trace_latency_threshold);
tracer =
std::make_shared<dsn::utils::latency_tracer>(fmt::format("{}[{}]", "mutation", _tid),
false,
FLAGS_abnormal_write_trace_latency_threshold);
}

mutation_ptr mutation::copy_no_reply(const mutation_ptr &old_mu)
Expand Down
6 changes: 3 additions & 3 deletions src/utils/latency_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -56,7 +56,7 @@ void latency_tracer::set_sub_tracer(const std::shared_ptr<latency_tracer> &trace
if (!FLAGS_enable_latency_tracer) {
return;
}
tracer->_is_sub = true;

_sub_tracer = tracer;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/test/latency_tracer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class latency_tracer_test : public testing::Test

void init_trace_points()
{
_tracer1 = std::make_shared<latency_tracer>("name1", true);
_tracer1 = std::make_shared<latency_tracer>("name1");
for (int i = 0; i < _tracer1_stage_count; i++) {
ADD_CUSTOM_POINT(_tracer1, fmt::format("stage{}", i));
}

_tracer2 = std::make_shared<latency_tracer>("name2", true);
_tracer2 = std::make_shared<latency_tracer>("name2");

for (int i = 0; i < _tracer2_stage_count; i++) {
ADD_CUSTOM_POINT(_tracer2, fmt::format("stage{}", i));
Expand Down

0 comments on commit 7868d64

Please sign in to comment.