trace2: report peak memory usage of the process
Teach Windows version of git to report peak memory usage during exit() processing. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
bce9db6de9
commit
26c6f251d7
@ -41,7 +41,7 @@ int main(int argc, const char **argv)
|
|||||||
|
|
||||||
trace2_initialize();
|
trace2_initialize();
|
||||||
trace2_cmd_start(argv);
|
trace2_cmd_start(argv);
|
||||||
trace2_collect_process_info();
|
trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);
|
||||||
|
|
||||||
git_setup_gettext();
|
git_setup_gettext();
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "../../cache.h"
|
#include "../../cache.h"
|
||||||
#include "../../json-writer.h"
|
#include "../../json-writer.h"
|
||||||
|
#include "lazyload.h"
|
||||||
#include <Psapi.h>
|
#include <Psapi.h>
|
||||||
#include <tlHelp32.h>
|
#include <tlHelp32.h>
|
||||||
|
|
||||||
@ -137,11 +138,54 @@ static void get_is_being_debugged(void)
|
|||||||
"windows/debugger_present", 1);
|
"windows/debugger_present", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trace2_collect_process_info(void)
|
/*
|
||||||
|
* Emit JSON data with the peak memory usage of the current process.
|
||||||
|
*/
|
||||||
|
static void get_peak_memory_info(void)
|
||||||
|
{
|
||||||
|
DECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE,
|
||||||
|
PPROCESS_MEMORY_COUNTERS, DWORD);
|
||||||
|
|
||||||
|
if (INIT_PROC_ADDR(GetProcessMemoryInfo)) {
|
||||||
|
PROCESS_MEMORY_COUNTERS pmc;
|
||||||
|
|
||||||
|
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc,
|
||||||
|
sizeof(pmc))) {
|
||||||
|
struct json_writer jw = JSON_WRITER_INIT;
|
||||||
|
|
||||||
|
jw_object_begin(&jw, 0);
|
||||||
|
|
||||||
|
#define KV(kv) #kv, (intmax_t)pmc.kv
|
||||||
|
|
||||||
|
jw_object_intmax(&jw, KV(PageFaultCount));
|
||||||
|
jw_object_intmax(&jw, KV(PeakWorkingSetSize));
|
||||||
|
jw_object_intmax(&jw, KV(PeakPagefileUsage));
|
||||||
|
|
||||||
|
jw_end(&jw);
|
||||||
|
|
||||||
|
trace2_data_json("process", the_repository,
|
||||||
|
"windows/memory", &jw);
|
||||||
|
jw_release(&jw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void trace2_collect_process_info(enum trace2_process_info_reason reason)
|
||||||
{
|
{
|
||||||
if (!trace2_is_enabled())
|
if (!trace2_is_enabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
get_is_being_debugged();
|
switch (reason) {
|
||||||
get_ancestry();
|
case TRACE2_PROCESS_INFO_STARTUP:
|
||||||
|
get_is_being_debugged();
|
||||||
|
get_ancestry();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case TRACE2_PROCESS_INFO_EXIT:
|
||||||
|
get_peak_memory_info();
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BUG("trace2_collect_process_info: unknown reason '%d'", reason);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
trace2.c
2
trace2.c
@ -213,6 +213,8 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)
|
|||||||
if (!trace2_enabled)
|
if (!trace2_enabled)
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
|
||||||
|
|
||||||
tr2main_exit_code = code;
|
tr2main_exit_code = code;
|
||||||
|
|
||||||
us_now = getnanotime() / 1000;
|
us_now = getnanotime() / 1000;
|
||||||
|
14
trace2.h
14
trace2.h
@ -391,13 +391,19 @@ void trace2_printf(const char *fmt, ...);
|
|||||||
* Optional platform-specific code to dump information about the
|
* Optional platform-specific code to dump information about the
|
||||||
* current and any parent process(es). This is intended to allow
|
* current and any parent process(es). This is intended to allow
|
||||||
* post-processors to know who spawned this git instance and anything
|
* post-processors to know who spawned this git instance and anything
|
||||||
* else the platform may be able to tell us about the current process.
|
* else that the platform may be able to tell us about the current process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
enum trace2_process_info_reason {
|
||||||
|
TRACE2_PROCESS_INFO_STARTUP,
|
||||||
|
TRACE2_PROCESS_INFO_EXIT,
|
||||||
|
};
|
||||||
|
|
||||||
#if defined(GIT_WINDOWS_NATIVE)
|
#if defined(GIT_WINDOWS_NATIVE)
|
||||||
void trace2_collect_process_info(void);
|
void trace2_collect_process_info(enum trace2_process_info_reason reason);
|
||||||
#else
|
#else
|
||||||
#define trace2_collect_process_info() \
|
#define trace2_collect_process_info(reason) \
|
||||||
do { \
|
do { \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user