DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
SystemMetrics.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common.h"
4#include "System/Object.h"
5#include "System/String.h"
7#include "System/Action.h"
10
11namespace DotNetDupe {
12 namespace System {
13 namespace Diagnostics {
14
15 class ProcessStreamer;
16
19 struct MemoryInfo {
21 unsigned long long uMemoryTotalBytes;
22 unsigned long long uMemoryUsedBytes;
23 long long lPrivateBytes;
25
33 };
34
37 struct DiskInfo {
38 long long lDiskReadBytes;
39 long long lDiskWriteBytes;
40
43 };
44
54
67
78
102
115
122 class SystemMetrics : public Object {
123 public:
126
129
130 // System-wide metrics
131
135
138 DOTNETDUPE_API static double GetSystemCpuUsage();
139
143
147
148 // Process-specific metrics (by process name)
149
153 DOTNETDUPE_API static String GetProcessCommandLine(const String& sProcessName);
154
158 DOTNETDUPE_API static MemoryInfo GetProcessMemoryUsage(const String& sProcessName);
159
163 DOTNETDUPE_API static DiskInfo GetProcessDiskUsage(const String& sProcessName);
164
169
174
179
180 // Process-specific metrics by PID
181
186
191
196 DOTNETDUPE_API static void EnrichProcessInfo(ProcessInfo& proc, bool bIncludeNetwork = true);
197
198 // Progressive Streaming APIs
199
204
208 DOTNETDUPE_API static void EnumerateProcessesAsync(const Action<const ProcessInfo&>& fnOnProcess, const Action<>& fnOnComplete = nullptr);
209
210 // Service enumeration API
211
215
216 private:
217#if defined(_WIN32)
218 static void* OpenProcessByName(const String& sProcessName, unsigned long dwDesiredAccess, int& iOutProcessId);
219 static String ReadProcessCommandLineHandle(void* hProc);
220 static MemoryInfo ReadProcessMemoryHandle(void* hProc);
221 static DiskInfo ReadProcessDiskHandle(void* hProc, const String& sProcessName);
222 static NetworkUsageInfo ReadProcessNetworkHandle(void* hProc, const String& sProcessName);
223 static Collections::Generic::List<int> ReadProcessNetworkPortInternal(int iProcessId);
224 static ProcessNetworkConnectionInfo ReadProcessNetworkInfoInternal(int iProcessId);
225#else
226 static int FindPidByName(const String& sProcessName);
227 static MemoryInfo ReadLinuxProcessMemory(int iPid);
228 static DiskInfo ReadLinuxProcessDisk(int iPid);
229 static NetworkUsageInfo ReadLinuxProcessNetwork(int iPid);
230 static Collections::Generic::List<int> ReadLinuxProcessPorts(int iPid);
231 static ProcessNetworkConnectionInfo ReadLinuxProcessNetworkInfo(int iPid);
232#endif
233 };
234
235 }
236 }
237}
Encapsulates a delegate method that has parameters and returns void.
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Encapsulates a method that has parameters and does not return a value.
Definition Action.h:46
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
Streams system process updates asynchronously with batching and event notifications.
static String GetProcessCommandLine(const String &sProcessName)
Queries the full command line used to launch a process by name.
static void EnrichProcessInfo(ProcessInfo &proc, bool bIncludeNetwork=true)
Enriches an existing ProcessInfo instance with CPU, memory, disk, and network telemetry.
static Collections::Generic::List< int > GetProcessNetworkPort(const String &sProcessName)
Retrieves open listening ports bound by a process by name.
static SmartPointer< ProcessStreamer > CreateProcessStreamer(const ProcessStreamOptions &options=ProcessStreamOptions())
Creates a background process streaming engine configured with options.
static DiskInfo GetProcessDiskUsage(const String &sProcessName)
Queries disk transfer throughput for a process by name.
static MemoryInfo GetProcessMemoryUsage(const String &sProcessName)
Queries memory allocation details for a process by name.
static Collections::Generic::List< ServiceInfo > GetAllServices()
Enumerates all registered system background services and their current execution status.
SystemMetrics()
Initializes a new instance of SystemMetrics.
static MemoryInfo GetSystemMemoryUsage()
Retrieves total and consumed physical memory metrics for the entire machine.
static double GetSystemCpuUsage()
Computes total system CPU usage percentage across all processors.
static double GetSystemNetworkUsage()
Computes total network traffic throughput across all operational interfaces in Megabits per second.
static NetworkUsageInfo GetProcessNetworkUsage(const String &sProcessName)
Queries network transfer metrics for a process by name.
static ProcessNetworkConnectionInfo GetProcessNetworkInfo(const String &sProcessName)
Queries detailed socket connections for a process by name.
static void EnumerateProcessesAsync(const Action< const ProcessInfo & > &fnOnProcess, const Action<> &fnOnComplete=nullptr)
Asynchronously discovers processes on the host using fast discovery mode.
static DiskInfo GetSystemDiskUsage()
Retrieves total disk read and write transfer rates for the system.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
Rate or aggregate count of disk read and write operations.
long long lDiskWriteBytes
Disk write throughput in bytes per second or total transfer count.
long long lDiskReadBytes
Disk read throughput in bytes per second or total transfer count.
DiskInfo()
Default constructor initializing to unpopulated (-1).
Snapshot of physical and virtual memory utilization for the system or a specific process.
MemoryInfo()
Default constructor initializing default counters.
long long lPhysicalMemoryBytes
Working set size (physical RAM resident) for the target process.
unsigned long long uMemoryTotalBytes
Total physical RAM installed on the host in bytes.
double dMemoryUsagePercent
Percentage of total physical memory currently in use (0.0 - 100.0).
long long lPrivateBytes
Private bytes allocated by the target process (-1 if unavailable).
unsigned long long uMemoryUsedBytes
Currently consumed physical RAM across all processes.
String sState
Socket connection state (e.g. "ESTABLISHED", "LISTEN", "TIME_WAIT").
String sLocalAddress
Local IPv4 or IPv6 IP address.
Network throughput counters for bytes transmitted and received.
long long lNetworkReadBytes
Incoming network throughput in bytes or octets.
NetworkUsageInfo()
Default constructor initializing to unpopulated (-1).
long long lNetworkWriteBytes
Outgoing network throughput in bytes or octets.
Comprehensive telemetry snapshot for an operating system process.
double dCpuUsagePercent
Process CPU consumption percentage (0.0 - 100.0).
String sName
Process executable name without path.
Collections::Generic::List< int > lstOpenPorts
Open listening ports.
int iProcessId
Operating system process identifier (PID).
NetworkUsageInfo network
Network traffic metrics.
String sCommandLine
Full command-line arguments used to spawn the process.
bool bHasEstablishedConnection
True if any connection is established.
int iSessionId
Terminal Services session ID.
String sPath
Full filesystem path to the executable image.
MemoryInfo memory
Memory allocation statistics.
Collections::Generic::List< NetworkConnectionInfo > lstConnections
Active socket connections.
Collection of open ports and active connections attributed to a specific process.
Collections::Generic::List< NetworkConnectionInfo > lstConnections
Detailed active socket connections.
bool bHasEstablishedInboundConnection
True if process possesses at least one established connection.
Collections::Generic::List< int > lstOpenPorts
List of TCP/UDP ports bound or in LISTEN state.
Configuration options controlling the execution of a ProcessStreamer.
ProcessStreamOptions()
Default constructor configuring progressive telemetry defaults.
int iProcessId
Process ID hosting the service (0 if stopped).
String sDisplayName
Human-readable friendly display name.
String sStartType
Startup behavior (e.g. "Automatic", "Manual", "Disabled").
String sStatus
Current service state (e.g. "Running", "Stopped", "Paused").
String sServiceName
Internal service key identifier.