Update get info
This commit is contained in:
@@ -905,8 +905,15 @@ private:
|
||||
}
|
||||
if (_query) {
|
||||
// Best-effort: missing counters just stay null; reads return -1.
|
||||
PdhAddEnglishCounterW(_query, L"\\Processor(_Total)\\% Processor Time", 0, &_cpuLoad);
|
||||
// \Processor Information is the modern object — handles >64-core
|
||||
// systems and processor groups correctly. The legacy \Processor
|
||||
// object can under-report on Windows 11 with virtualization-based
|
||||
// security, hybrid scheduler quirks, or processor-group routing.
|
||||
PdhAddEnglishCounterW(_query, L"\\Processor Information(_Total)\\% Processor Time", 0, &_cpuLoad);
|
||||
PdhAddEnglishCounterW(_query, L"\\Processor Information(_Total)\\% Processor Performance", 0, &_cpuPerf);
|
||||
// Turbo-aware utilization — matches what Task Manager displays.
|
||||
// Can exceed 100% during sustained turbo boost.
|
||||
PdhAddEnglishCounterW(_query, L"\\Processor Information(_Total)\\% Processor Utility", 0, &_cpuUtil);
|
||||
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\% Disk Time", 0, &_diskTime);
|
||||
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 0, &_diskRead);
|
||||
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 0, &_diskWrite);
|
||||
@@ -941,7 +948,8 @@ private:
|
||||
}
|
||||
|
||||
void ReadFromPdh(ANSCENTER::SystemHealthInfo& out) {
|
||||
out.cpuLoadPercent = Pdh_GetSingle(_cpuLoad);
|
||||
out.cpuLoadPercent = Pdh_GetSingle(_cpuLoad);
|
||||
out.cpuUtilizationPercent = Pdh_GetSingle(_cpuUtil);
|
||||
|
||||
const double perfPct = Pdh_GetSingle(_cpuPerf);
|
||||
if (perfPct >= 0 && _baseClockMHz > 0)
|
||||
@@ -1066,6 +1074,7 @@ private:
|
||||
PDH_HQUERY _query {nullptr};
|
||||
PDH_HCOUNTER _cpuLoad {nullptr};
|
||||
PDH_HCOUNTER _cpuPerf {nullptr};
|
||||
PDH_HCOUNTER _cpuUtil {nullptr};
|
||||
PDH_HCOUNTER _diskTime {nullptr};
|
||||
PDH_HCOUNTER _diskRead {nullptr};
|
||||
PDH_HCOUNTER _diskWrite{nullptr};
|
||||
|
||||
@@ -341,10 +341,19 @@ namespace ANSCENTER
|
||||
// ------------------------------------------------------------------------
|
||||
struct SystemHealthInfo {
|
||||
// CPU
|
||||
double cpuLoadPercent = -1.0; // 0..100, total across all logical cores
|
||||
double cpuTempDegC = -1.0; // -1 if unavailable
|
||||
double cpuFreqGHz = -1.0; // current clock (turbo-aware)
|
||||
std::string cpuModel; // e.g. "Intel(R) Core(TM) i9-..."
|
||||
// cpuLoadPercent — 0..100 always. Source: PDH "% Processor Time".
|
||||
// The right value for "what fraction of CPU time
|
||||
// am I spending in non-idle threads?".
|
||||
// cpuUtilizationPercent — turbo-aware. Source: PDH "% Processor
|
||||
// Utility". Can exceed 100% during sustained turbo
|
||||
// boost. This is what Task Manager displays.
|
||||
// Pick one to bind to the LabVIEW indicator; cpuUtilizationPercent
|
||||
// matches what users see in TM but breaks fixed-range UI scaling.
|
||||
double cpuLoadPercent = -1.0;
|
||||
double cpuUtilizationPercent = -1.0;
|
||||
double cpuTempDegC = -1.0;
|
||||
double cpuFreqGHz = -1.0; // current clock (turbo-aware)
|
||||
std::string cpuModel; // e.g. "Intel(R) Core(TM) i9-..."
|
||||
|
||||
// System memory
|
||||
double memTotalGB = -1.0;
|
||||
@@ -549,33 +558,38 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
||||
double* netReceiveSpeedMBs,
|
||||
double* netSendSpeedMBs,
|
||||
LStrHandle gpuName, // primary adapter name (e.g. "NVIDIA RTX 4090"); pass nullptr to skip
|
||||
LStrHandle gpuAdaptersDetail); // per-adapter rollup; pass nullptr to skip — see SystemHealthInfo for format
|
||||
LStrHandle gpuAdaptersDetail, // per-adapter rollup; pass nullptr to skip — see SystemHealthInfo for format
|
||||
double* cpuUtilizationPercent); // turbo-aware "% Processor Utility"; matches Task Manager (may exceed 100)
|
||||
|
||||
// Same payload as GetSystemHealthParameters, packed into a single string with
|
||||
// ';' separators in this exact order:
|
||||
// 1 cpuLoadPercent (%)
|
||||
// 2 cpuTempDegC (°C, -1 if unavailable)
|
||||
// 3 cpuFreqGHz (GHz)
|
||||
// 4 cpuModel (string; any literal ';' in the model is rewritten to ',')
|
||||
// 1 cpuLoadPercent (%; 0..100, "% Processor Time")
|
||||
// 2 cpuTempDegC (°C, -1 if unavailable)
|
||||
// 3 cpuFreqGHz (GHz)
|
||||
// 4 cpuModel (string; any literal ';' is rewritten to ',')
|
||||
// 5 memTotalGB
|
||||
// 6 rssPercent (%)
|
||||
// 7 swapPercent (%)
|
||||
// 8 gpuLoadPercent (%)
|
||||
// 9 valIRSS_MB (current process working set, MB)
|
||||
// 10 valSwap_MB (current process page-file usage, MB)
|
||||
// 11 valIGPU_MB (current process GPU dedicated memory, MB)
|
||||
// 6 rssPercent (%)
|
||||
// 7 swapPercent (%)
|
||||
// 8 gpuLoadPercent (%)
|
||||
// 9 valIRSS_MB (current process working set, MB)
|
||||
// 10 valSwap_MB (current process page-file usage, MB)
|
||||
// 11 valIGPU_MB (current process GPU dedicated memory, MB)
|
||||
// 12 memoryUsedGB
|
||||
// 13 memoryFreeGB
|
||||
// 14 diskLoadPercent (%)
|
||||
// 14 diskLoadPercent (%)
|
||||
// 15 diskReadSpeedMBs
|
||||
// 16 diskWriteSpeedMBs
|
||||
// 17 diskUsedGB
|
||||
// 18 diskTotalGB
|
||||
// 19 netLoadPercent (%)
|
||||
// 19 netLoadPercent (%)
|
||||
// 20 netReceiveSpeedMBs
|
||||
// 21 netSendSpeedMBs
|
||||
// 22 gpuName (primary adapter model, e.g. "NVIDIA RTX 4090")
|
||||
// 23 gpuAdaptersDetail (per-adapter rollup — see SystemHealthInfo struct)
|
||||
// 22 gpuName (primary adapter model, e.g. "NVIDIA RTX 4090")
|
||||
// 23 gpuAdaptersDetail (per-adapter rollup — see SystemHealthInfo struct)
|
||||
// 24 cpuUtilizationPercent (%; turbo-aware, may exceed 100; matches Task Manager)
|
||||
//
|
||||
// New fields are appended at the end so existing parsers stay valid. Fields
|
||||
// 1..23 are stable.
|
||||
// Numbers use the C locale ('.' decimal point) and 2-decimal fixed format.
|
||||
// Any literal ';' in gpuName / gpuAdaptersDetail is rewritten to ',' so the
|
||||
// outer separator is never ambiguous.
|
||||
|
||||
@@ -401,7 +401,8 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
||||
double* netReceiveSpeedMBs,
|
||||
double* netSendSpeedMBs,
|
||||
LStrHandle gpuName,
|
||||
LStrHandle gpuAdaptersDetail)
|
||||
LStrHandle gpuAdaptersDetail,
|
||||
double* cpuUtilizationPercent)
|
||||
{
|
||||
try {
|
||||
const ANSCENTER::SystemHealthInfo info =
|
||||
@@ -417,8 +418,9 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
||||
}
|
||||
};
|
||||
|
||||
if (cpuLoadPercent) *cpuLoadPercent = info.cpuLoadPercent;
|
||||
if (cpuTempDegC) *cpuTempDegC = info.cpuTempDegC;
|
||||
if (cpuLoadPercent) *cpuLoadPercent = info.cpuLoadPercent;
|
||||
if (cpuTempDegC) *cpuTempDegC = info.cpuTempDegC;
|
||||
if (cpuUtilizationPercent) *cpuUtilizationPercent = info.cpuUtilizationPercent;
|
||||
if (cpuFreqGHz) *cpuFreqGHz = info.cpuFreqGHz;
|
||||
if (memTotalGB) *memTotalGB = info.memTotalGB;
|
||||
if (rssPercent) *rssPercent = info.rssPercent;
|
||||
@@ -486,11 +488,12 @@ extern "C" __declspec(dllexport) int GetSystemHealthParametersString(LStrHandle
|
||||
<< info.diskWriteSpeedMBs << ';'
|
||||
<< info.diskUsedGB << ';'
|
||||
<< info.diskTotalGB << ';'
|
||||
<< info.netLoadPercent << ';'
|
||||
<< info.netReceiveSpeedMBs << ';'
|
||||
<< info.netSendSpeedMBs << ';'
|
||||
<< gpuName_ << ';'
|
||||
<< gpuDetail;
|
||||
<< info.netLoadPercent << ';'
|
||||
<< info.netReceiveSpeedMBs << ';'
|
||||
<< info.netSendSpeedMBs << ';'
|
||||
<< gpuName_ << ';'
|
||||
<< gpuDetail << ';'
|
||||
<< info.cpuUtilizationPercent;
|
||||
|
||||
const std::string s = os.str();
|
||||
const int size = static_cast<int>(s.length());
|
||||
|
||||
Reference in New Issue
Block a user