Skip to content

Commit

Permalink
fix perf_counter_info::timestamp (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyifan27 authored and qinzuoyan committed Apr 1, 2019
1 parent ca636f2 commit c475299
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/dsn/perf_counter/perf_counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class perf_counters : public dsn::utils::singleton<perf_counters>
bool updated_recently{false};
};
std::unordered_map<std::string, counter_snapshot> _snapshots;

// timestamp in seconds when take snapshot of current counters
int64_t _timestamp;
};

} // end namespace dsn::utils
4 changes: 3 additions & 1 deletion src/core/perf_counter/perf_counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ std::string perf_counters::list_snapshot_by_regexp(const std::vector<std::string
}

std::stringstream ss;
info.timestamp = dsn_now_ms() / 1000;
info.timestamp = _timestamp;
char buf[20];
utils::time_ms_to_date_time(info.timestamp * 1000, buf, sizeof(buf));
info.timestamp_str = buf;
Expand Down Expand Up @@ -236,6 +236,8 @@ void perf_counters::take_snapshot()
}
}

_timestamp = dsn_now_ms() / 1000;

// delete old counters
std::vector<std::string> old_counters;
for (auto &p : _snapshots)
Expand Down

0 comments on commit c475299

Please sign in to comment.