Skip to content

Commit 446326c

Browse files
uvdn7meta-codesync[bot]
authored andcommitted
Use millisecond clock in ServiceData
Summary: There are multiple read paths and write paths for fb303 stats. This change only affects the clock used in writing to ServiceData (e.g. `ServiceData::addStatValue`). Publishing stats (write path) from `ThreadCachedServiceData` remains using the clock of second granularity (https://fburl.com/code/rwec2dnp). This means, only writing through the global ServiceData will see benefits of sub-second buckets. This is OK because use cases that need high precision should write through the global ServiceData directly anyway, as the default publish interval for `ThreadCachedServiceData` is 1s. Reading stats (e.g. via `TimeSeriesExporter::getStatValue`) remains using the clock of second granularity https://fburl.com/code/6boz3i79. All of the precision improvement is coming from the write path, putting values in finer buckets. There is no clear incentive to changing the read clock to millisecond granularity for now. Reviewed By: ot Differential Revision: D86692761 fbshipit-source-id: fedf475bfd70eddf2fefd22f4bb3c7a8241aebfa
1 parent 84707e1 commit 446326c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

fb303/ServiceData.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@
4141

4242
namespace facebook::fb303 {
4343

44+
/*
45+
* Get current time with millisecond granularity via CLOCK_REALTIME_COARSE.
46+
*/
4447
inline TimePoint get_current_time() {
45-
return TimePoint(std::chrono::seconds(get_legacy_stats_time()));
48+
return TimePoint(
49+
std::chrono::duration_cast<std::chrono::milliseconds>(
50+
folly::chrono::coarse_system_clock::now().time_since_epoch()));
4651
}
4752

4853
/**

0 commit comments

Comments
 (0)