summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats/resource_consumption_metrics.h
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2020-11-04 12:54:38 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-04 19:26:57 +0000
commit1e543176b20fba914f1992ce3804794cf4578ebc (patch)
treec1bd6e9b28010119654576a535837fa519fedf70 /src/mongo/db/stats/resource_consumption_metrics.h
parent3970e75445ca03958e86b71b6a2145486526c350 (diff)
downloadmongo-1e543176b20fba914f1992ce3804794cf4578ebc.tar.gz
SERVER-51667 Collect CPU time used per operation
Diffstat (limited to 'src/mongo/db/stats/resource_consumption_metrics.h')
-rw-r--r--src/mongo/db/stats/resource_consumption_metrics.h28
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.