Memory: improve performance by not querying WMI (Windows)

This commit is contained in:
李通洲
2022-11-21 12:18:36 +08:00
parent c0037c99e4
commit 19c5904561
5 changed files with 24 additions and 50 deletions
+2 -2
View File
@@ -434,13 +434,13 @@ elseif(WIN32)
src/detection/host/host_windows.cpp
src/detection/localip/localip_windows.c
src/detection/media/media_nosupport.c
src/detection/memory/memory_windows.cpp
src/detection/memory/memory_windows.c
src/detection/opengl/opengl_windows.c
src/detection/os/os_windows.cpp
src/detection/packages/packages_windows.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_windows.cpp
src/detection/swap/swap_windows.cpp
src/detection/swap/swap_windows.c
src/detection/terminalfont/terminalfont_windows.c
src/detection/terminalshell/terminalshell_windows.cpp
src/detection/uptime/uptime_windows.c
+11
View File
@@ -0,0 +1,11 @@
#include "memory.h"
void ffDetectMemoryImpl(FFMemoryStorage* ram)
{
MEMORYSTATUSEX statex = {
.dwLength = sizeof(statex),
};
GlobalMemoryStatusEx(&statex);
ram->bytesTotal = statex.ullTotalPhys;
ram->bytesUsed = statex.ullTotalPhys - statex.ullAvailPhys;
}
-25
View File
@@ -1,25 +0,0 @@
extern "C" {
#include "memory.h"
}
#include "util/windows/wmi.hpp"
extern "C"
void ffDetectMemoryImpl(FFMemoryStorage* ram)
{
FFWmiQuery query(L"SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem", &ram->error);
if(!query)
return;
if(FFWmiRecord record = query.next())
{
//KB
record.getUnsigned(L"TotalVisibleMemorySize", &ram->bytesTotal);
uint64_t bytesFree;
record.getUnsigned(L"FreePhysicalMemory", &bytesFree);
ram->bytesUsed = ram->bytesTotal - bytesFree;
ram->bytesTotal *= 1024;
ram->bytesUsed *= 1024;
}
else
ffStrbufInitS(&ram->error, "No Wmi result returned");
}
+11
View File
@@ -0,0 +1,11 @@
#include "swap.h"
void ffDetectSwapImpl(FFMemoryStorage* swap)
{
MEMORYSTATUSEX statex = {
.dwLength = sizeof(statex),
};
GlobalMemoryStatusEx(&statex);
swap->bytesTotal = statex.ullTotalPageFile;
swap->bytesUsed = statex.ullTotalPageFile - statex.ullAvailPageFile;
}
-23
View File
@@ -1,23 +0,0 @@
extern "C" {
#include "swap.h"
}
#include "util/windows/wmi.hpp"
extern "C"
void ffDetectSwapImpl(FFMemoryStorage* swap)
{
FFWmiQuery query(L"SELECT AllocatedBaseSize, CurrentUsage FROM Win32_PageFileUsage", &swap->error);
if(!query)
return;
if(FFWmiRecord record = query.next())
{
//MB
record.getUnsigned(L"AllocatedBaseSize", &swap->bytesTotal);
record.getUnsigned(L"CurrentUsage", &swap->bytesUsed);
swap->bytesTotal *= 1024 * 1024;
swap->bytesUsed *= 1024 * 1024;
}
else
ffStrbufInitS(&swap->error, "No Wmi result returned");
}