diff options
| author | stainer_t <thomas.stainer@oecd-nea.org> | 2025-09-08 13:48:49 +0200 |
|---|---|---|
| committer | stainer_t <thomas.stainer@oecd-nea.org> | 2025-09-08 13:48:49 +0200 |
| commit | 7dfcc480ba1e19bd3232349fc733caef94034292 (patch) | |
| tree | 03ee104eb8846d5cc1a981d267687a729185d3f3 /Ganlib/src/getusage.c | |
Initial commit from Polytechnique Montreal
Diffstat (limited to 'Ganlib/src/getusage.c')
| -rw-r--r-- | Ganlib/src/getusage.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Ganlib/src/getusage.c b/Ganlib/src/getusage.c new file mode 100644 index 0000000..c5b484a --- /dev/null +++ b/Ganlib/src/getusage.c @@ -0,0 +1,44 @@ +/* + ----------------------------------------------------------------------- + Copyright (C) 2019 Ecole Polytechnique de Montreal + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + RECOVER USER ALLOCATED MEMORY USED + + ----------------------------------------------------------------------- + */ + +#include <stdio.h> +#ifndef MSDOS +#include <sys/time.h> +#include <sys/resource.h> + +double getusage() +{ + struct rusage r_usage; + getrusage(RUSAGE_SELF, &r_usage); + double utime=(double) r_usage.ru_maxrss; + return utime; +#else +#include <windows.h> +#include <psapi.h> + +double getusage() +{ + HANDLE h_process = GetCurrentProcess(); + PROCESS_MEMORY_COUNTERS pmc; + + if(GetProcessMemoryInfo(h_process, &pmc, sizeof(pmc))) { + // The *nix equivalent is expressed in KB, but Windows uses bytes + SIZE_T mem_kb = pmc.WorkingSetSize / 1024; + return (double)mem_kb; + } else { + return 0.0; + } +} +#endif +} |
