61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
#ifndef GEOPRO_TOOLS_GPR_POC_PROBE_HPP
|
||
#define GEOPRO_TOOLS_GPR_POC_PROBE_HPP
|
||
|
||
// 轻量 headless 度量探针:墙钟计时 + 进程峰值工作集内存。
|
||
// 仅供 gpr_poc CLI 使用,header-only,零外部依赖(Windows 用 Psapi)。
|
||
|
||
#include <chrono>
|
||
#include <string>
|
||
|
||
#if defined(_WIN32)
|
||
// 防止 <windows.h> 的 min/max 宏污染 std::numeric_limits<>::min()/max()
|
||
// (ScalarVolumeI16.hpp 等会因此编译失败)。
|
||
#ifndef NOMINMAX
|
||
#define NOMINMAX
|
||
#endif
|
||
#ifndef WIN32_LEAN_AND_MEAN
|
||
#define WIN32_LEAN_AND_MEAN
|
||
#endif
|
||
#include <windows.h>
|
||
#include <psapi.h>
|
||
#endif
|
||
|
||
namespace geopro::tools {
|
||
|
||
// 墙钟计时器:构造即起表,elapsedMs() 返回毫秒(double)。
|
||
class Stopwatch {
|
||
public:
|
||
Stopwatch() : start_(std::chrono::steady_clock::now()) {}
|
||
|
||
void reset() { start_ = std::chrono::steady_clock::now(); }
|
||
|
||
double elapsedMs() const {
|
||
const auto now = std::chrono::steady_clock::now();
|
||
return std::chrono::duration<double, std::milli>(now - start_).count();
|
||
}
|
||
|
||
private:
|
||
std::chrono::steady_clock::time_point start_;
|
||
};
|
||
|
||
// 进程级度量探针。
|
||
struct Probe {
|
||
// 进程峰值工作集(MB)。Windows 取 GetProcessMemoryInfo::PeakWorkingSetSize;
|
||
// 其它平台返回 0(本任务仅 Windows 实测)。
|
||
static double peakMemMB() {
|
||
#if defined(_WIN32)
|
||
PROCESS_MEMORY_COUNTERS pmc;
|
||
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
||
return static_cast<double>(pmc.PeakWorkingSetSize) / (1024.0 * 1024.0);
|
||
}
|
||
return 0.0;
|
||
#else
|
||
return 0.0;
|
||
#endif
|
||
}
|
||
};
|
||
|
||
} // namespace geopro::tools
|
||
|
||
#endif // GEOPRO_TOOLS_GPR_POC_PROBE_HPP
|