diff options
Diffstat (limited to 'src/mongo/util/tick_source.h')
-rw-r--r-- | src/mongo/util/tick_source.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/util/tick_source.h b/src/mongo/util/tick_source.h index 134f4d05737..1aef0e478dc 100644 --- a/src/mongo/util/tick_source.h +++ b/src/mongo/util/tick_source.h @@ -50,5 +50,18 @@ public: * Returns the conversion ratio from ticks to seconds. */ virtual Tick getTicksPerSecond() = 0; + + /** + * Convert the given tick count into a duration, specified by the type parameter. + * + * e.g. tickSource->ticksTo<Milliseconds>(ticks); + */ + template <typename D> + D ticksTo(Tick ticks) { + // The number of ticks per 1 duration unit. + double ticksPerD = + static_cast<double>(getTicksPerSecond()) * D::period::num / D::period::den; + return D(static_cast<int64_t>(ticks / ticksPerD)); + } }; } // namespace mongo |