1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// SPDX-License-Identifier: GPL-3.0-or-later
#include "windows_plugin.h"
#include "windows-internals.h"
#define _COMMON_PLUGIN_NAME "windows.plugin"
#define _COMMON_PLUGIN_MODULE_NAME "PerflibProcesses"
#include "../common-contexts/common-contexts.h"
static void initialize(void) {
;
}
static bool do_processes(PERF_DATA_BLOCK *pDataBlock, int update_every) {
PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, "System");
if (!pObjectType)
return false;
static COUNTER_DATA processesRunning = { .key = "Processes" };
static COUNTER_DATA contextSwitchPerSec = { .key = "Context Switches/sec" };
static COUNTER_DATA threads = { .key = "Threads" };
if(perflibGetObjectCounter(pDataBlock, pObjectType, &processesRunning)) {
ULONGLONG running = processesRunning.current.Data;
common_system_processes(running, update_every);
}
if(perflibGetObjectCounter(pDataBlock, pObjectType, &contextSwitchPerSec)) {
ULONGLONG contexts = contextSwitchPerSec.current.Data;
common_system_context_switch(contexts, update_every);
}
if(perflibGetObjectCounter(pDataBlock, pObjectType, &threads)) {
ULONGLONG totalThreads = threads.current.Data;
common_system_threads(totalThreads, update_every);
}
return true;
}
int do_PerflibProcesses(int update_every, usec_t dt __maybe_unused) {
static bool initialized = false;
if(unlikely(!initialized)) {
initialize();
initialized = true;
}
DWORD id = RegistryFindIDByName("System");
if(id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
return -1;
PERF_DATA_BLOCK *pDataBlock = perflibGetPerformanceData(id);
if(!pDataBlock) return -1;
do_processes(pDataBlock, update_every);
return 0;
}
|