diff options
author | William Schultz <william.schultz@mongodb.com> | 2018-10-02 21:54:58 -0400 |
---|---|---|
committer | William Schultz <william.schultz@mongodb.com> | 2018-10-02 21:57:52 -0400 |
commit | 982ba21e0ffbdaaf766dc8fa060728ba9b5f4914 (patch) | |
tree | efc760c482e30bd70bfbaf5854779a89acf00ef3 /src/mongo/util/tick_source_mock.h | |
parent | 23d7c89e501d221a41f350b0b10a52a4f05bb2e2 (diff) | |
download | mongo-982ba21e0ffbdaaf766dc8fa060728ba9b5f4914.tar.gz |
SERVER-36697 Utilize TickSource for transactions timing metrics
This patch converts the existing transactions diagnostics timing related
metrics to use a TickSource to record transaction durations. The
TickSource is a high precision, mock-able time source for measuring
the passage of time. This patch also converts the existing unit tests
to use a mock TickSource, which allows the tests to fully virtualize
time, making them much faster and less flaky.
Diffstat (limited to 'src/mongo/util/tick_source_mock.h')
-rw-r--r-- | src/mongo/util/tick_source_mock.h | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/mongo/util/tick_source_mock.h b/src/mongo/util/tick_source_mock.h index 066bd3c9dcc..d0d16189e84 100644 --- a/src/mongo/util/tick_source_mock.h +++ b/src/mongo/util/tick_source_mock.h @@ -34,24 +34,38 @@ namespace mongo { /** - * Mock tick source with millisecond resolution that doesn't gives a fixed tick count - * until the advance method is called. + * Mock tick source that can be parameterized on a duration type. + * + * Its internal tick count will be tracked in the unit of the duration type parameter. For example, + * for TickSourceMock<Milliseconds>, 1 tick = 1 millisecond. It gives a fixed tick count until the + * advance method is called. */ +template <typename D = Milliseconds> class TickSourceMock final : public TickSource { public: - TickSource::Tick getTicks() override; + TickSource::Tick getTicks() override { + return _currentTicks; + }; - TickSource::Tick getTicksPerSecond() override; + TickSource::Tick getTicksPerSecond() override { + static_assert(D::period::num == 1, + "Cannot measure ticks per second for duration types larger than 1 second."); + return D::period::den; + }; /** * Advance the ticks by the given amount of milliseconds. */ - void advance(const Milliseconds& ms); + void advance(const D& duration) { + _currentTicks += duration.count(); + } /** - * Resets the tick count to the give value. + * Resets the tick count to the given value. */ - void reset(TickSource::Tick tick); + void reset(TickSource::Tick tick) { + _currentTicks = std::move(tick); + } private: TickSource::Tick _currentTicks = 0; |