mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-11 13:30:47 -04:00
feat(util): add support for memory usage on Windows
This commit is contained in:
parent
038541f94e
commit
e9cff93636
@ -850,7 +850,7 @@ foreach(tgt ${LIBDWARFS_TARGETS} ${LIBDWARFS_OBJECT_TARGETS} dwarfs_test_helpers
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(${tgt} PRIVATE ntdll.lib dbghelp.lib)
|
||||
target_link_libraries(${tgt} PRIVATE ntdll.lib dbghelp.lib psapi.lib)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
18
src/util.cpp
18
src/util.cpp
@ -38,6 +38,10 @@
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PSAPI_VERSION 1
|
||||
#endif
|
||||
|
||||
#if __has_include(<utf8cpp/utf8.h>)
|
||||
#include <utf8cpp/utf8.h>
|
||||
#else
|
||||
@ -55,6 +59,10 @@
|
||||
|
||||
#include <dwarfs/config.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <psapi.h>
|
||||
#endif
|
||||
|
||||
#ifdef DWARFS_STACKTRACE_ENABLED
|
||||
#include <cpptrace/cpptrace.hpp>
|
||||
#include <csignal>
|
||||
@ -591,7 +599,15 @@ std::tm safe_localtime(std::time_t t) {
|
||||
|
||||
std::optional<size_t> get_self_memory_usage() {
|
||||
#if defined(_WIN32)
|
||||
// TODO
|
||||
PROCESS_MEMORY_COUNTERS_EX pmc{};
|
||||
|
||||
if (::GetProcessMemoryInfo(::GetCurrentProcess(),
|
||||
reinterpret_cast<PPROCESS_MEMORY_COUNTERS>(&pmc),
|
||||
sizeof(pmc))) {
|
||||
if (pmc.PrivateUsage > 0) {
|
||||
return static_cast<size_t>(pmc.PrivateUsage);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
task_vm_info info{};
|
||||
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
|
||||
|
Loading…
x
Reference in New Issue
Block a user