mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-07-20 22:41:36 +00:00
Drop psutil requirement in functional tests, fetch memory usage directly
This commit is contained in:
@@ -2240,6 +2240,13 @@ DOCUMENT(R"(Retrieves the driver information (if available) for a given graphics
|
||||
)");
|
||||
extern "C" RENDERDOC_API DriverInformation RENDERDOC_CC RENDERDOC_GetDriverInformation(GraphicsAPI api);
|
||||
|
||||
DOCUMENT(R"(Returns the current process's memory usage in bytes
|
||||
|
||||
:return: The current memory usage in bytes.
|
||||
:rtype: ``int``
|
||||
)");
|
||||
extern "C" RENDERDOC_API uint64_t RENDERDOC_CC RENDERDOC_GetCurrentProcessMemoryUsage();
|
||||
|
||||
DOCUMENT("Internal function for retrieving a config setting.");
|
||||
extern "C" RENDERDOC_API const char *RENDERDOC_CC RENDERDOC_GetConfigSetting(const char *name);
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ void ApplyEnvironmentModification();
|
||||
|
||||
const char *GetEnvVariable(const char *name);
|
||||
|
||||
uint64_t GetMemoryUsage();
|
||||
|
||||
bool CanGlobalHook();
|
||||
bool StartGlobalHook(const char *pathmatch, const char *capturefile, const CaptureOptions &opts);
|
||||
bool IsGlobalHookActive();
|
||||
|
||||
@@ -157,3 +157,25 @@ const char *Process::GetEnvVariable(const char *name)
|
||||
|
||||
return settingsOutput.c_str();
|
||||
}
|
||||
|
||||
uint64_t Process::GetMemoryUsage()
|
||||
{
|
||||
FILE *f = FileIO::fopen("/proc/self/statm", "r");
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
RDCWARN("Couldn't open /proc/self/statm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char line[512] = {};
|
||||
fgets(line, 511, f);
|
||||
|
||||
uint32_t vmPages = 0;
|
||||
int num = sscanf(line, "%u", &vmPages);
|
||||
|
||||
if(num == 1 && vmPages > 0)
|
||||
return vmPages * (uint64_t)sysconf(_SC_PAGESIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include <crt_externs.h>
|
||||
#include <mach/mach.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -168,4 +169,17 @@ bool OSUtility::DebuggerPresent()
|
||||
const char *Process::GetEnvVariable(const char *name)
|
||||
{
|
||||
return getenv(name);
|
||||
}
|
||||
|
||||
uint64_t Process::GetMemoryUsage()
|
||||
{
|
||||
mach_task_basic_info taskInfo;
|
||||
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
|
||||
|
||||
int ret = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
|
||||
|
||||
if(ret != KERN_SUCCESS)
|
||||
return 0;
|
||||
|
||||
return taskInfo.resident_size;
|
||||
}
|
||||
@@ -173,4 +173,26 @@ bool OSUtility::DebuggerPresent()
|
||||
const char *Process::GetEnvVariable(const char *name)
|
||||
{
|
||||
return getenv(name);
|
||||
}
|
||||
|
||||
uint64_t Process::GetMemoryUsage()
|
||||
{
|
||||
FILE *f = FileIO::fopen("/proc/self/statm", "r");
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
RDCWARN("Couldn't open /proc/self/statm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char line[512] = {};
|
||||
fgets(line, 511, f);
|
||||
|
||||
uint32_t vmPages = 0;
|
||||
int num = sscanf(line, "%u", &vmPages);
|
||||
|
||||
if(num == 1 && vmPages > 0)
|
||||
return vmPages * (uint64_t)sysconf(_SC_PAGESIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
// must be separate so that it's included first and not sorted by clang-format
|
||||
#include <windows.h>
|
||||
|
||||
#include <Psapi.h>
|
||||
#include <tchar.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <string>
|
||||
@@ -183,6 +184,32 @@ const char *Process::GetEnvVariable(const char *name)
|
||||
return buf;
|
||||
}
|
||||
|
||||
uint64_t Process::GetMemoryUsage()
|
||||
{
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
|
||||
if(proc == NULL)
|
||||
{
|
||||
RDCERR("Couldn't open process: %d", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
PROCESS_MEMORY_COUNTERS memInfo = {};
|
||||
|
||||
uint64_t ret = 0;
|
||||
|
||||
if(GetProcessMemoryInfo(proc, &memInfo, sizeof(memInfo)))
|
||||
{
|
||||
ret = memInfo.WorkingSetSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
RDCERR("Couldn't get process memory info: %d", GetLastError());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// helpers for various shims and dlls etc, not part of the public API
|
||||
extern "C" __declspec(dllexport) void __cdecl INTERNAL_GetTargetControlIdent(uint32_t *ident)
|
||||
{
|
||||
|
||||
@@ -185,6 +185,11 @@ extern "C" RENDERDOC_API DriverInformation RENDERDOC_CC RENDERDOC_GetDriverInfor
|
||||
return RenderDoc::Inst().GetDriverInformation(api);
|
||||
}
|
||||
|
||||
extern "C" RENDERDOC_API uint64_t RENDERDOC_CC RENDERDOC_GetCurrentProcessMemoryUsage()
|
||||
{
|
||||
return Process::GetMemoryUsage();
|
||||
}
|
||||
|
||||
extern "C" RENDERDOC_API const char *RENDERDOC_CC RENDERDOC_GetConfigSetting(const char *name)
|
||||
{
|
||||
return RenderDoc::Inst().GetConfigSetting(name).c_str();
|
||||
|
||||
@@ -5,8 +5,6 @@ import sys
|
||||
try:
|
||||
import PIL
|
||||
del PIL
|
||||
import psutil
|
||||
del psutil
|
||||
except ImportError as e:
|
||||
print("Missing dependency: {}".format(e))
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import rdtest
|
||||
import os
|
||||
import psutil
|
||||
import renderdoc as rd
|
||||
|
||||
|
||||
@@ -20,7 +19,7 @@ class Repeat_Load(rdtest.TestCase):
|
||||
return
|
||||
|
||||
# Do nothing, just ensure it's loaded
|
||||
memory_usage: int = psutil.Process(os.getpid()).memory_info().rss
|
||||
memory_usage: int = rd.GetCurrentProcessMemoryUsage()
|
||||
|
||||
# We measure the baseline memory usage during the second peak to avoid any persistent caches etc that might
|
||||
# not be full
|
||||
|
||||
Reference in New Issue
Block a user