diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2016-08-26 11:19:54 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2016-08-26 11:19:54 -0400 |
commit | 3ff1a9ac7cbfdfcb2149523d2c055bd41d356dc6 (patch) | |
tree | c9b04eabe831406edcd7af191ebca08e1e5dfd8e /src | |
parent | eb5283b46b7599e07793c8695c74880a10f3998e (diff) | |
download | mongo-3ff1a9ac7cbfdfcb2149523d2c055bd41d356dc6.tar.gz |
SERVER-25405 Remove redundant Windows system metrics
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/ftdc/ftdc_system_stats_windows.cpp | 4 | ||||
-rw-r--r-- | src/mongo/util/perfctr_collect.cpp | 49 | ||||
-rw-r--r-- | src/mongo/util/perfctr_collect.h | 18 | ||||
-rw-r--r-- | src/mongo/util/perfctr_collect_test.cpp | 73 |
4 files changed, 80 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 edbf1fcec03..87f1d8503be 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"_sd, "\\PhysicalDisk(*)\\% Disk Write Time"_sd, - "\\PhysicalDisk(*)\\Avg. Disk Bytes/Read"_sd, - "\\PhysicalDisk(*)\\Avg. Disk Bytes/Write"_sd, "\\PhysicalDisk(*)\\Avg. Disk Read Queue Length"_sd, "\\PhysicalDisk(*)\\Avg. Disk Write Queue Length"_sd, - "\\PhysicalDisk(*)\\Avg. Disk sec/Read"_sd, - "\\PhysicalDisk(*)\\Avg. Disk sec/Write"_sd, "\\PhysicalDisk(*)\\Disk Read Bytes/sec"_sd, "\\PhysicalDisk(*)\\Disk Write Bytes/sec"_sd, "\\PhysicalDisk(*)\\Disk Reads/sec"_sd, diff --git a/src/mongo/util/perfctr_collect.cpp b/src/mongo/util/perfctr_collect.cpp index 631588bcb9d..5702c0b1b8f 100644 --- a/src/mongo/util/perfctr_collect.cpp +++ b/src/mongo/util/perfctr_collect.cpp @@ -270,15 +270,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 @@ -403,21 +398,37 @@ Status PerfCounterCollector::collectCounters(const std::vector<CounterInfo>& cou 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 72c74f9833a..4c29fabd1cc 100644 --- a/src/mongo/util/perfctr_collect.h +++ b/src/mongo/util/perfctr_collect.h @@ -148,11 +148,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); @@ -169,14 +171,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 f9d6b2fda09..0d93bf957ef 100644 --- a/src/mongo/util/perfctr_collect_test.cpp +++ b/src/mongo/util/perfctr_collect_test.cpp @@ -92,6 +92,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"); @@ -135,7 +143,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"); } } @@ -254,15 +262,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"); } @@ -285,9 +293,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"); } @@ -311,17 +319,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"); } } @@ -390,28 +397,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"); |