summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2017-04-17 17:59:05 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2017-04-17 17:59:05 -0400
commit2d15e1d82feefaada7c422c37c21da3bfb9dc1a0 (patch)
treea04fc5ba3099dba17be7f66d60c63413e51924b5
parent587cb82bb403ec6a71dfac69375e1184b34087ac (diff)
downloadmongo-2d15e1d82feefaada7c422c37c21da3bfb9dc1a0.tar.gz
SERVER-25405 Remove redundant Windows system metrics
(cherry picked from commit 3ff1a9ac7cbfdfcb2149523d2c055bd41d356dc6)
-rw-r--r--src/mongo/db/ftdc/ftdc_system_stats_windows.cpp4
-rw-r--r--src/mongo/util/perfctr_collect.cpp48
-rw-r--r--src/mongo/util/perfctr_collect.h18
-rw-r--r--src/mongo/util/perfctr_collect_test.cpp73
4 files changed, 79 insertions, 64 deletions
diff --git a/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp
index 401e6776523..e684ebcf326 100644
--- a/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp
+++ b/src/mongo/db/ftdc/ftdc_system_stats_windows.cpp
@@ -83,12 +83,8 @@ const std::vector<StringData> kMemoryCounters = {
const std::vector<StringData> kDiskCounters = {
"\\PhysicalDisk(*)\\% Disk Read Time",
"\\PhysicalDisk(*)\\% Disk Write Time",
- "\\PhysicalDisk(*)\\Avg. Disk Bytes/Read",
- "\\PhysicalDisk(*)\\Avg. Disk Bytes/Write",
"\\PhysicalDisk(*)\\Avg. Disk Read Queue Length",
"\\PhysicalDisk(*)\\Avg. Disk Write Queue Length",
- "\\PhysicalDisk(*)\\Avg. Disk sec/Read",
- "\\PhysicalDisk(*)\\Avg. Disk sec/Write",
"\\PhysicalDisk(*)\\Disk Read Bytes/sec",
"\\PhysicalDisk(*)\\Disk Write Bytes/sec",
"\\PhysicalDisk(*)\\Disk Reads/sec",
diff --git a/src/mongo/util/perfctr_collect.cpp b/src/mongo/util/perfctr_collect.cpp
index 3a0790cffb7..89ac6694a60 100644
--- a/src/mongo/util/perfctr_collect.cpp
+++ b/src/mongo/util/perfctr_collect.cpp
@@ -264,15 +264,10 @@ StatusWith<PerfCounterCollector::CounterInfo> PerfCounterCollector::addCounter(S
bool hasSecondValue = false;
- // Rate counters need time as a base
- if ((counterInfo->dwType & PERF_COUNTER_DELTA) == PERF_COUNTER_DELTA ||
- (counterInfo->dwType & PERF_COUNTER_FRACTION) == PERF_COUNTER_FRACTION ||
- (counterInfo->dwType & PERF_ELAPSED_TIME) == PERF_ELAPSED_TIME) {
+ // Only include base for counters that need it
+ if ((counterInfo->dwType & PERF_COUNTER_PRECISION) == PERF_COUNTER_PRECISION) {
secondName += " Base";
hasSecondValue = true;
- } else {
- invariant(counterInfo->dwType == PERF_COUNTER_RAWCOUNT ||
- counterInfo->dwType == PERF_COUNTER_LARGE_RAWCOUNT);
}
// InstanceName is null for counters without instance names
@@ -393,21 +388,36 @@ Status PerfCounterCollector::collectCounters(const std::vector<CounterInfo>& cou
BSONObjBuilder* builder) {
for (const auto& counterInfo : counters) {
DWORD dwType = 0;
- PDH_RAW_COUNTER rawCounter = {0};
- PDH_STATUS status = PdhGetRawCounterValue(counterInfo.handle, &dwType, &rawCounter);
- if (status != ERROR_SUCCESS) {
- return {ErrorCodes::WindowsPdhError,
- formatFunctionCallError("PdhGetRawCounterValue", status)};
- }
+ // Elapsed Time is an unusual counter in that being able to control the sample period for
+ // the counter is uninteresting even though it is computed from two values. Just return the
+ // computed value instead.
+ if (counterInfo.type == PERF_ELAPSED_TIME) {
+ PDH_FMT_COUNTERVALUE counterValue = {0};
+ PDH_STATUS status = PdhGetFormattedCounterValue(
+ counterInfo.handle, PDH_FMT_DOUBLE, &dwType, &counterValue);
+ if (status != ERROR_SUCCESS) {
+ return {ErrorCodes::WindowsPdhError,
+ formatFunctionCallError("PdhGetFormattedCounterValue", status)};
+ }
+
+ builder->append(counterInfo.firstName, counterValue.doubleValue);
- if (counterInfo.hasSecondValue) {
- // Delta, Rate, and Elapsed Time counters require the second value in the raw counter
- // information
- builder->append(counterInfo.firstName, rawCounter.FirstValue);
- builder->append(counterInfo.secondName, rawCounter.SecondValue);
} else {
- builder->append(counterInfo.firstName, rawCounter.FirstValue);
+ PDH_RAW_COUNTER rawCounter = {0};
+ PDH_STATUS status = PdhGetRawCounterValue(counterInfo.handle, &dwType, &rawCounter);
+ if (status != ERROR_SUCCESS) {
+ return {ErrorCodes::WindowsPdhError,
+ formatFunctionCallError("PdhGetRawCounterValue", status)};
+ }
+
+ if (counterInfo.hasSecondValue) {
+ // Precise counters require the second value in the raw counter information
+ builder->append(counterInfo.firstName, rawCounter.FirstValue);
+ builder->append(counterInfo.secondName, rawCounter.SecondValue);
+ } else {
+ builder->append(counterInfo.firstName, rawCounter.FirstValue);
+ }
}
}
diff --git a/src/mongo/util/perfctr_collect.h b/src/mongo/util/perfctr_collect.h
index abfd3cefd97..5cf42409ff5 100644
--- a/src/mongo/util/perfctr_collect.h
+++ b/src/mongo/util/perfctr_collect.h
@@ -158,11 +158,13 @@ public:
static StatusWith<std::unique_ptr<PerfCounterCollector>> create(PerfCounterCollection builder);
/**
- * Collect the counters from PDH, and output their raw values into builder.
+ * Collect the counters from PDH, and output their raw values into builder. The exception is
+ * elapsed time counters which returns computed values instead of raw values.
*
- * For each counters, if the counter is a delta, rate, or fraction counter, the second value is
- * output under the name "<counter> Base". Also, a single field is output called "timebase" if
- * any counter depends on system ticks per second.
+ * For each counters, if the counter is a precision counter (see PERF_COUNTER_PRECISION), the
+ * second value is output under the name "<counter> Base". Also, a single field is output called
+ * "timebase" if any counter depends on system ticks per second. See counterHasTickBasedTimeBase
+ * for more details about timebase.
*/
Status collect(BSONObjBuilder* builder);
@@ -179,14 +181,14 @@ private:
std::string firstName;
/**
- * The name of the second value of a counter if the counter is a delta, rate, or fraction
- * counter. This is output as: "\<Object Name>\<Counter Name> Base".
+ * The name of the second value of a counter if the counter is a precision counter. This is
+ * output as: "\<Object Name>\<Counter Name> Base".
*/
std::string secondName;
/**
- * True if the counter is a delta, rate, or fraction counter, and its value should be output
- * in the output BSON document.
+ * True if the counter is a precision counter, and its value should be output in the output
+ * BSON document.
*/
bool hasSecondValue;
diff --git a/src/mongo/util/perfctr_collect_test.cpp b/src/mongo/util/perfctr_collect_test.cpp
index 3542913ac3f..516754a440a 100644
--- a/src/mongo/util/perfctr_collect_test.cpp
+++ b/src/mongo/util/perfctr_collect_test.cpp
@@ -90,6 +90,14 @@ StringMap toNestedStringMap(BSONObj& obj) {
ASSERT_KEY(g "." c); \
ASSERT_KEY(g "." c " Base");
+#define ASSERT_NESTED_GROUP_AND_RAW_COUNTER(g, p, c) \
+ ASSERT_KEY(g "." p "." c); \
+ ASSERT_NO_KEY(g "." p "." c " Base");
+
+#define ASSERT_NO_NESTED_GROUP_AND_RAW_COUNTER(g, p, c) \
+ ASSERT_NO_KEY(g "." p "." c); \
+ ASSERT_NO_KEY(g "." p "." c " Base");
+
#define ASSERT_NESTED_GROUP_AND_NON_RAW_COUNTER(g, p, c) \
ASSERT_KEY(g "." p "." c); \
ASSERT_KEY(g "." p "." c " Base");
@@ -132,7 +140,7 @@ TEST(FTDCPerfCollector, TestSingleCounter) {
COLLECT_COUNTERS;
ASSERT_NO_TIMEBASE;
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
}
}
@@ -248,15 +256,15 @@ TEST(FTDCPerfCollector, TestCounterTypes) {
COLLECT_COUNTERS;
ASSERT_TIMEBASE
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\Processor\\% Idle Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\Processor\\% Processor Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\System\\System Up Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\Processor\\% Idle Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\Processor\\% Processor Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\System\\System Up Time");
ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\% Disk Write Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk Bytes/Write");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk Read Queue Length");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk sec/Write");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\Disk Write Bytes/sec");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("misc", "\\PhysicalDisk\\Disk Writes/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk Bytes/Write");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk Read Queue Length");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\PhysicalDisk\\Avg. Disk sec/Write");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\PhysicalDisk\\Disk Write Bytes/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\PhysicalDisk\\Disk Writes/sec");
ASSERT_GROUP_AND_RAW_COUNTER("misc", "\\System\\Processes");
}
@@ -278,9 +286,9 @@ TEST(FTDCPerfCollector, TestMultipleCounterGroups) {
COLLECT_COUNTERS;
ASSERT_TIMEBASE
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Processor Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("sys", "\\System\\System Up Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Processor Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("sys", "\\System\\System Up Time");
ASSERT_GROUP_AND_RAW_COUNTER("sys", "\\System\\Processes");
}
@@ -303,17 +311,16 @@ TEST(FTDCPerfCollector, TestMultipleNestedCounterGroups) {
ASSERT_TIMEBASE
// We boldly assume that machines we test on have at least two processors
- ASSERT_NESTED_GROUP_AND_NON_RAW_COUNTER("cpu", "0", "\\Processor\\% Idle Time");
- ASSERT_NESTED_GROUP_AND_NON_RAW_COUNTER("cpu", "0", "\\Processor\\% Processor Time");
+ ASSERT_NESTED_GROUP_AND_RAW_COUNTER("cpu", "0", "\\Processor\\% Idle Time");
+ ASSERT_NESTED_GROUP_AND_RAW_COUNTER("cpu", "0", "\\Processor\\% Processor Time");
- ASSERT_NESTED_GROUP_AND_NON_RAW_COUNTER("cpu", "1", "\\Processor\\% Idle Time");
- ASSERT_NESTED_GROUP_AND_NON_RAW_COUNTER("cpu", "1", "\\Processor\\% Processor Time");
+ ASSERT_NESTED_GROUP_AND_RAW_COUNTER("cpu", "1", "\\Processor\\% Idle Time");
+ ASSERT_NESTED_GROUP_AND_RAW_COUNTER("cpu", "1", "\\Processor\\% Processor Time");
- ASSERT_NO_NESTED_GROUP_AND_NON_RAW_COUNTER("cpu", "_Total", "\\Processor\\% Idle Time");
- ASSERT_NO_NESTED_GROUP_AND_NON_RAW_COUNTER(
- "cpu", "_Total", "\\Processor\\% Processor Time");
+ ASSERT_NO_NESTED_GROUP_AND_RAW_COUNTER("cpu", "_Total", "\\Processor\\% Idle Time");
+ ASSERT_NO_NESTED_GROUP_AND_RAW_COUNTER("cpu", "_Total", "\\Processor\\% Processor Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("sys", "\\System\\System Up Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("sys", "\\System\\System Up Time");
ASSERT_GROUP_AND_RAW_COUNTER("sys", "\\System\\Processes");
}
}
@@ -381,28 +388,28 @@ TEST(FTDCPerfCollector, TestLocalCounters) {
COLLECT_COUNTERS;
ASSERT_TIMEBASE
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Interrupt Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Privileged Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% Processor Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\% User Time");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\Processor\\Interrupts/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Idle Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Interrupt Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Privileged Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% Processor Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\% User Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\Processor\\Interrupts/sec");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\System\\Context Switches/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\System\\Context Switches/sec");
ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\System\\Processes");
ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\System\\Processor Queue Length");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("cpu", "\\System\\System Up Time");
+ ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\System\\System Up Time");
ASSERT_GROUP_AND_RAW_COUNTER("cpu", "\\System\\Threads");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Available Bytes");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Cache Bytes");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("memory", "\\Memory\\Cache Faults/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Cache Faults/sec");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Commit Limit");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Committed Bytes");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("memory", "\\Memory\\Page Reads/sec");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("memory", "\\Memory\\Page Writes/sec");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("memory", "\\Memory\\Pages Input/sec");
- ASSERT_GROUP_AND_NON_RAW_COUNTER("memory", "\\Memory\\Pages Output/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Page Reads/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Page Writes/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Pages Input/sec");
+ ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Pages Output/sec");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\Pool Paged Resident Bytes");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\System Cache Resident Bytes");
ASSERT_GROUP_AND_RAW_COUNTER("memory", "\\Memory\\System Code Total Bytes");