master
c 83 lines 2.68 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "windows_plugin.h"
4 #include "windows-internals.h"
5
6 #define _COMMON_PLUGIN_NAME "windows.plugin"
7 #define _COMMON_PLUGIN_MODULE_NAME "PerflibProcesses"
8 #include "../common-contexts/common-contexts.h"
9
10 static void do_processor_queue(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
11 {
12 static RRDSET *st_queue = NULL;
13 static RRDDIM *rd_queue = NULL;
14 static COUNTER_DATA processorQueue = {.key = "Processor Queue Length"};
15 if (!perflibGetObjectCounter(pDataBlock, pObjectType, &processorQueue))
16 return;
17
18 if (!st_queue) {
19 st_queue = rrdset_create_localhost(
20 "system",
21 "processor_queue",
22 NULL,
23 "system",
24 "system.processor_queue_length",
25 "The number of threads in the processor queue.",
26 "threads",
27 _COMMON_PLUGIN_NAME,
28 _COMMON_PLUGIN_MODULE_NAME,
29 NETDATA_CHART_PRIO_SYSTEM_THREAD_QUEUE,
30 update_every,
31 RRDSET_TYPE_LINE);
32
33 rd_queue = rrddim_add(st_queue, "threads", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
34 }
35
36 rrddim_set_by_pointer(st_queue, rd_queue, (collected_number)processorQueue.current.Data);
37
38 rrdset_done(st_queue);
39 }
40
41 static bool do_processes(PERF_DATA_BLOCK *pDataBlock, int update_every)
42 {
43 PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, "System");
44 if (!pObjectType)
45 return false;
46
47 static COUNTER_DATA processesRunning = {.key = "Processes"};
48 static COUNTER_DATA contextSwitchPerSec = {.key = "Context Switches/sec"};
49 static COUNTER_DATA threads = {.key = "Threads"};
50
51 if (perflibGetObjectCounter(pDataBlock, pObjectType, &processesRunning)) {
52 ULONGLONG running = processesRunning.current.Data;
53 common_system_processes(running, update_every);
54 }
55
56 if (perflibGetObjectCounter(pDataBlock, pObjectType, &contextSwitchPerSec)) {
57 ULONGLONG contexts = contextSwitchPerSec.current.Data;
58 common_system_context_switch(contexts, update_every);
59 }
60
61 if (perflibGetObjectCounter(pDataBlock, pObjectType, &threads)) {
62 ULONGLONG totalThreads = threads.current.Data;
63 common_system_threads(totalThreads, update_every);
64 }
65
66 do_processor_queue(pDataBlock, pObjectType, update_every);
67 return true;
68 }
69
70 int do_PerflibProcesses(int update_every, usec_t dt __maybe_unused)
71 {
72 DWORD id = RegistryFindIDByName("System");
73 if (id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
74 return -1;
75
76 PERF_DATA_BLOCK *pDataBlock = perflibGetPerformanceData(id);
77 if (!pDataBlock)
78 return -1;
79
80 do_processes(pDataBlock, update_every);
81
82 return 0;
83 }