diff options
Diffstat (limited to 'src/mongo/db/stats/resource_consumption_metrics.h')
-rw-r--r-- | src/mongo/db/stats/resource_consumption_metrics.h | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/mongo/db/stats/resource_consumption_metrics.h b/src/mongo/db/stats/resource_consumption_metrics.h index 05b74c26043..a4c8e02b247 100644 --- a/src/mongo/db/stats/resource_consumption_metrics.h +++ b/src/mongo/db/stats/resource_consumption_metrics.h @@ -35,6 +35,7 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" +#include "mongo/db/operation_cpu_timer.h" #include "mongo/platform/mutex.h" namespace mongo { @@ -120,6 +121,8 @@ public: */ class OperationMetrics { public: + OperationMetrics() = default; + /** * Reports all metrics on a BSONObjBuilder. */ @@ -134,8 +137,8 @@ public: ReadMetrics readMetrics; WriteMetrics writeMetrics; - // Amount of CPU time consumed by an operation in milliseconds - long long cpuMillis = 0; + // Records CPU time consumed by this operation. + OperationCPUTimer* cpuTimer = nullptr; }; /** @@ -148,7 +151,7 @@ public: primaryReadMetrics += other.primaryReadMetrics; secondaryReadMetrics += other.secondaryReadMetrics; writeMetrics += other.writeMetrics; - cpuMillis += other.cpuMillis; + cpuNanos += other.cpuNanos; }; AggregatedMetrics& operator+=(const AggregatedMetrics& other) { @@ -170,8 +173,8 @@ public: // Write metrics recorded for all operations WriteMetrics writeMetrics; - // Amount of CPU time consumed by an operation in milliseconds - long long cpuMillis = 0; + // Amount of CPU time consumed by an operation in nanoseconds + Nanoseconds cpuNanos; }; /** @@ -185,12 +188,7 @@ public: /** * When called, resource consumption metrics should be recorded for this operation. */ - void beginScopedCollecting(const std::string& dbName) { - invariant(!isInScope()); - _dbName = dbName; - _collecting = ScopedCollectionState::kInScopeCollecting; - _hasCollectedMetrics = true; - } + void beginScopedCollecting(OperationContext* opCtx, const std::string& dbName); /** * When called, sets state that a ScopedMetricsCollector is in scope, but is not recording @@ -206,11 +204,7 @@ public: * When called, resource consumption metrics should not be recorded. Returns whether this * Collector was in a collecting state. */ - bool endScopedCollecting() { - bool wasCollecting = isCollecting(); - _collecting = ScopedCollectionState::kInactive; - return wasCollecting; - } + bool endScopedCollecting(); bool isCollecting() const { return _collecting == ScopedCollectionState::kInScopeCollecting; @@ -281,8 +275,6 @@ public: */ void incrementOneIdxEntryWritten(size_t idxEntryBytesWritten); - void incrementCpuMillis(size_t cpuMillis); - private: /** * Helper function that calls the Func when this collector is currently collecting metrics. |