@@ -36,6 +36,8 @@ namespace mongo {
3636
3737/* *
3838 * Tracks metrics for a single multi-document transaction.
39+ *
40+ * For all timing related stats, a TickSource with at least microsecond resolution must be used.
3941 */
4042class SingleTransactionStats {
4143public:
@@ -64,19 +66,19 @@ class SingleTransactionStats {
6466 SingleTransactionStats () : _txnNumber(kUninitializedTxnNumber ){};
6567 SingleTransactionStats (TxnNumber txnNumber) : _txnNumber(txnNumber){};
6668
67- /* *
68- * Returns the start time of the transaction in microseconds.
69- *
70- * This method cannot be called until setStartTime() has been called.
71- */
72- unsigned long long getStartTime () const ;
73-
7469 /* *
7570 * Sets the transaction's start time, only if it hasn't already been set.
7671 *
72+ * This method takes two sources of input for the current time. The 'curTick' argument should be
73+ * the current time as measured by a TickSource, which is a high precision interface for
74+ * measuring the passage of time that should provide at least microsecond resolution. The given
75+ * 'curWallClockTime' need only be a millisecond resolution time point that serves as a close
76+ * approximation to the true start time. This millisecond resolution time point is not used for
77+ * measuring transaction durations. The given tick value, however, is.
78+ *
7779 * This method must only be called once.
7880 */
79- void setStartTime (unsigned long long time );
81+ void setStartTime (TickSource::Tick curTick, Date_t curWallClockTime );
8082
8183 /* *
8284 * If the transaction is currently in progress, this method returns the duration
@@ -87,42 +89,42 @@ class SingleTransactionStats {
8789 *
8890 * This method cannot be called until setStartTime() has been called.
8991 */
90- unsigned long long getDuration (unsigned long long curTime ) const ;
92+ Microseconds getDuration (TickSource* tickSource, TickSource::Tick curTick ) const ;
9193
9294 /* *
9395 * Sets the transaction's end time, only if the start time has already been set.
9496 *
9597 * This method cannot be called until setStartTime() has been called.
9698 */
97- void setEndTime (unsigned long long time);
99+ void setEndTime (TickSource::Tick time);
98100
99101 /* *
100102 * Returns the total active time of the transaction, given the current time value. A transaction
101103 * is active when there is a running operation that is part of the transaction.
102104 */
103- Microseconds getTimeActiveMicros (unsigned long long curTime ) const ;
105+ Microseconds getTimeActiveMicros (TickSource* tickSource, TickSource::Tick curTick ) const ;
104106
105107 /* *
106108 * Returns the total inactive time of the transaction, given the current time value. A
107109 * transaction is inactive when it is idly waiting for a new operation to occur.
108110 */
109- Microseconds getTimeInactiveMicros (unsigned long long curTime ) const ;
111+ Microseconds getTimeInactiveMicros (TickSource* tickSource, TickSource::Tick curTick ) const ;
110112
111113 /* *
112114 * Marks the transaction as active and sets the start of the transaction's active time.
113115 *
114116 * This method cannot be called if the transaction is currently active. A call to setActive()
115117 * must be followed by a call to setInactive() before calling setActive() again.
116118 */
117- void setActive (unsigned long long time );
119+ void setActive (TickSource::Tick curTick );
118120
119121 /* *
120122 * Marks the transaction as inactive and sets the total active time of the transaction. The
121123 * total active time will only be set if the transaction was active prior to this call.
122124 *
123125 * This method cannot be called if the transaction is currently not active.
124126 */
125- void setInactive (unsigned long long time );
127+ void setInactive (TickSource* tickSource, TickSource::Tick curTick );
126128
127129 /* *
128130 * Returns whether or not the transaction is currently active.
@@ -192,7 +194,10 @@ class SingleTransactionStats {
192194 /* *
193195 * Append the stats to the builder.
194196 */
195- void report (BSONObjBuilder* builder, const repl::ReadConcernArgs& readConcernArgs) const ;
197+ void report (BSONObjBuilder* builder,
198+ const repl::ReadConcernArgs& readConcernArgs,
199+ TickSource* tickSource,
200+ TickSource::Tick curTick) const ;
196201
197202private:
198203 // The transaction number of the transaction.
@@ -202,18 +207,23 @@ class SingleTransactionStats {
202207 // for future use.
203208 boost::optional<bool > _autoCommit;
204209
205- // The start time of the transaction in microseconds.
206- unsigned long long _startTime{0 };
210+ // The start time of the transaction in millisecond resolution. Used only for diagnostics
211+ // reporting. Not used for measuring transaction durations.
212+ Date_t _startWallClockTime;
213+
214+ // The start time of the transaction. Note that tick values should only ever be used to measure
215+ // distance from other tick values, not for reporting absolute wall clock time.
216+ TickSource::Tick _startTime{0 };
207217
208- // The end time of the transaction in microseconds .
209- unsigned long long _endTime{0 };
218+ // The end time of the transaction.
219+ TickSource::Tick _endTime{0 };
210220
211221 // The total amount of active time spent by the transaction.
212222 Microseconds _timeActiveMicros = Microseconds{0 };
213223
214- // The time at which the transaction was last marked as active in microseconds . The transaction
215- // is considered active if this value is not equal to 0.
216- unsigned long long _lastTimeActiveStart{0 };
224+ // The time at which the transaction was last marked as active. The transaction is considered
225+ // active if this value is not equal to 0.
226+ TickSource::Tick _lastTimeActiveStart{0 };
217227
218228 // The expiration date of the transaction.
219229 Date_t _expireDate = Date_t::max();
0 commit comments