diff options
author | jinichu <jinnybyun@gmail.com> | 2018-06-18 16:13:20 -0400 |
---|---|---|
committer | jinichu <jinnybyun@gmail.com> | 2018-06-18 16:15:11 -0400 |
commit | d364e8b0e681260d251079f5755aeaabcb924198 (patch) | |
tree | e41ee9d450b24a82bbef06c935d1ac916a529588 /src/mongo/db/single_transaction_stats.h | |
parent | b1dc7108c14d3103c4650db4584515408a4dd0c4 (diff) | |
download | mongo-d364e8b0e681260d251079f5755aeaabcb924198.tar.gz |
SERVER-35300 Added startTime field to TxnStats to store the start time of a transaction
Diffstat (limited to 'src/mongo/db/single_transaction_stats.h')
-rw-r--r-- | src/mongo/db/single_transaction_stats.h | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/mongo/db/single_transaction_stats.h b/src/mongo/db/single_transaction_stats.h index 300afb99007..0bcae54d07f 100644 --- a/src/mongo/db/single_transaction_stats.h +++ b/src/mongo/db/single_transaction_stats.h @@ -33,6 +33,67 @@ namespace mongo { /** * Tracks metrics for a single multi-document transaction. */ -class SingleTransactionStats {}; +class SingleTransactionStats { +public: + /** + * Returns the start time of the transaction in microseconds. + * + * This method cannot be called until setStartTime() has been called. + */ + unsigned long long getStartTime() const { + invariant(_startTime > 0); + + return _startTime; + } + + /** + * Sets the transaction's start time, only if it hasn't already been set. + * + * This method must only be called once. + */ + void setStartTime(unsigned long long time) { + invariant(_startTime == 0); + + _startTime = time; + } + + /** + * If the transaction is currently in progress, this method returns the duration + * the transaction has been running for in microseconds. + * + * For a completed transaction, this method returns the total duration of the + * transaction in microseconds. + * + * This method cannot be called until setStartTime() has been called. + */ + unsigned long long getDuration() const { + invariant(_startTime > 0); + + // The transaction hasn't ended yet, so we return how long it has currently + // been running for. + if (_endTime == 0) { + return curTimeMicros64() - _startTime; + } + return _endTime - _startTime; + } + + /** + * Sets the transaction's end time, only if the start time has already been set. + * + * This method cannot be called until setStartTime() has been called. + */ + void setEndTime(unsigned long long time) { + invariant(_startTime > 0); + + _endTime = time; + } + +private: + // The start time of the transaction in microseconds. + unsigned long long _startTime{0}; + + // The end time of the transaction in microseconds. + unsigned long long _endTime{0}; +}; } // namespace mongo |