Update get info
This commit is contained in:
@@ -905,8 +905,15 @@ private:
|
|||||||
}
|
}
|
||||||
if (_query) {
|
if (_query) {
|
||||||
// Best-effort: missing counters just stay null; reads return -1.
|
// 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);
|
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 Time", 0, &_diskTime);
|
||||||
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 0, &_diskRead);
|
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Read Bytes/sec", 0, &_diskRead);
|
||||||
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 0, &_diskWrite);
|
PdhAddEnglishCounterW(_query, L"\\PhysicalDisk(_Total)\\Disk Write Bytes/sec", 0, &_diskWrite);
|
||||||
@@ -942,6 +949,7 @@ private:
|
|||||||
|
|
||||||
void ReadFromPdh(ANSCENTER::SystemHealthInfo& out) {
|
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);
|
const double perfPct = Pdh_GetSingle(_cpuPerf);
|
||||||
if (perfPct >= 0 && _baseClockMHz > 0)
|
if (perfPct >= 0 && _baseClockMHz > 0)
|
||||||
@@ -1066,6 +1074,7 @@ private:
|
|||||||
PDH_HQUERY _query {nullptr};
|
PDH_HQUERY _query {nullptr};
|
||||||
PDH_HCOUNTER _cpuLoad {nullptr};
|
PDH_HCOUNTER _cpuLoad {nullptr};
|
||||||
PDH_HCOUNTER _cpuPerf {nullptr};
|
PDH_HCOUNTER _cpuPerf {nullptr};
|
||||||
|
PDH_HCOUNTER _cpuUtil {nullptr};
|
||||||
PDH_HCOUNTER _diskTime {nullptr};
|
PDH_HCOUNTER _diskTime {nullptr};
|
||||||
PDH_HCOUNTER _diskRead {nullptr};
|
PDH_HCOUNTER _diskRead {nullptr};
|
||||||
PDH_HCOUNTER _diskWrite{nullptr};
|
PDH_HCOUNTER _diskWrite{nullptr};
|
||||||
|
|||||||
@@ -341,8 +341,17 @@ namespace ANSCENTER
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
struct SystemHealthInfo {
|
struct SystemHealthInfo {
|
||||||
// CPU
|
// CPU
|
||||||
double cpuLoadPercent = -1.0; // 0..100, total across all logical cores
|
// cpuLoadPercent — 0..100 always. Source: PDH "% Processor Time".
|
||||||
double cpuTempDegC = -1.0; // -1 if unavailable
|
// 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)
|
double cpuFreqGHz = -1.0; // current clock (turbo-aware)
|
||||||
std::string cpuModel; // e.g. "Intel(R) Core(TM) i9-..."
|
std::string cpuModel; // e.g. "Intel(R) Core(TM) i9-..."
|
||||||
|
|
||||||
@@ -549,14 +558,15 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
|||||||
double* netReceiveSpeedMBs,
|
double* netReceiveSpeedMBs,
|
||||||
double* netSendSpeedMBs,
|
double* netSendSpeedMBs,
|
||||||
LStrHandle gpuName, // primary adapter name (e.g. "NVIDIA RTX 4090"); pass nullptr to skip
|
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
|
// Same payload as GetSystemHealthParameters, packed into a single string with
|
||||||
// ';' separators in this exact order:
|
// ';' separators in this exact order:
|
||||||
// 1 cpuLoadPercent (%)
|
// 1 cpuLoadPercent (%; 0..100, "% Processor Time")
|
||||||
// 2 cpuTempDegC (°C, -1 if unavailable)
|
// 2 cpuTempDegC (°C, -1 if unavailable)
|
||||||
// 3 cpuFreqGHz (GHz)
|
// 3 cpuFreqGHz (GHz)
|
||||||
// 4 cpuModel (string; any literal ';' in the model is rewritten to ',')
|
// 4 cpuModel (string; any literal ';' is rewritten to ',')
|
||||||
// 5 memTotalGB
|
// 5 memTotalGB
|
||||||
// 6 rssPercent (%)
|
// 6 rssPercent (%)
|
||||||
// 7 swapPercent (%)
|
// 7 swapPercent (%)
|
||||||
@@ -576,6 +586,10 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
|||||||
// 21 netSendSpeedMBs
|
// 21 netSendSpeedMBs
|
||||||
// 22 gpuName (primary adapter model, e.g. "NVIDIA RTX 4090")
|
// 22 gpuName (primary adapter model, e.g. "NVIDIA RTX 4090")
|
||||||
// 23 gpuAdaptersDetail (per-adapter rollup — see SystemHealthInfo struct)
|
// 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.
|
// Numbers use the C locale ('.' decimal point) and 2-decimal fixed format.
|
||||||
// Any literal ';' in gpuName / gpuAdaptersDetail is rewritten to ',' so the
|
// Any literal ';' in gpuName / gpuAdaptersDetail is rewritten to ',' so the
|
||||||
// outer separator is never ambiguous.
|
// outer separator is never ambiguous.
|
||||||
|
|||||||
@@ -401,7 +401,8 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
|||||||
double* netReceiveSpeedMBs,
|
double* netReceiveSpeedMBs,
|
||||||
double* netSendSpeedMBs,
|
double* netSendSpeedMBs,
|
||||||
LStrHandle gpuName,
|
LStrHandle gpuName,
|
||||||
LStrHandle gpuAdaptersDetail)
|
LStrHandle gpuAdaptersDetail,
|
||||||
|
double* cpuUtilizationPercent)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
const ANSCENTER::SystemHealthInfo info =
|
const ANSCENTER::SystemHealthInfo info =
|
||||||
@@ -419,6 +420,7 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
|||||||
|
|
||||||
if (cpuLoadPercent) *cpuLoadPercent = info.cpuLoadPercent;
|
if (cpuLoadPercent) *cpuLoadPercent = info.cpuLoadPercent;
|
||||||
if (cpuTempDegC) *cpuTempDegC = info.cpuTempDegC;
|
if (cpuTempDegC) *cpuTempDegC = info.cpuTempDegC;
|
||||||
|
if (cpuUtilizationPercent) *cpuUtilizationPercent = info.cpuUtilizationPercent;
|
||||||
if (cpuFreqGHz) *cpuFreqGHz = info.cpuFreqGHz;
|
if (cpuFreqGHz) *cpuFreqGHz = info.cpuFreqGHz;
|
||||||
if (memTotalGB) *memTotalGB = info.memTotalGB;
|
if (memTotalGB) *memTotalGB = info.memTotalGB;
|
||||||
if (rssPercent) *rssPercent = info.rssPercent;
|
if (rssPercent) *rssPercent = info.rssPercent;
|
||||||
@@ -490,7 +492,8 @@ extern "C" __declspec(dllexport) int GetSystemHealthParametersString(LStrHandle
|
|||||||
<< info.netReceiveSpeedMBs << ';'
|
<< info.netReceiveSpeedMBs << ';'
|
||||||
<< info.netSendSpeedMBs << ';'
|
<< info.netSendSpeedMBs << ';'
|
||||||
<< gpuName_ << ';'
|
<< gpuName_ << ';'
|
||||||
<< gpuDetail;
|
<< gpuDetail << ';'
|
||||||
|
<< info.cpuUtilizationPercent;
|
||||||
|
|
||||||
const std::string s = os.str();
|
const std::string s = os.str();
|
||||||
const int size = static_cast<int>(s.length());
|
const int size = static_cast<int>(s.length());
|
||||||
|
|||||||
Reference in New Issue
Block a user