/* * 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); } } }
static void warn_if_raster_font(void) { DWORD fontFamily = 0; DECLARE_PROC_ADDR(kernel32.dll, BOOL, GetCurrentConsoleFontEx, HANDLE, BOOL, PCONSOLE_FONT_INFOEX); /* don't bother if output was ascii only */ if (!non_ascii_used) return; /* GetCurrentConsoleFontEx is available since Vista */ if (INIT_PROC_ADDR(GetCurrentConsoleFontEx)) { CONSOLE_FONT_INFOEX cfi; cfi.cbSize = sizeof(cfi); if (GetCurrentConsoleFontEx(console, 0, &cfi)) fontFamily = cfi.FontFamily; } else { /* pre-Vista: check default console font in registry */ HKEY hkey; if (ERROR_SUCCESS == RegOpenKeyExA(HKEY_CURRENT_USER, "Console", 0, KEY_READ, &hkey)) { DWORD size = sizeof(fontFamily); RegQueryValueExA(hkey, "FontFamily", NULL, NULL, (LPVOID) &fontFamily, &size); RegCloseKey(hkey); } } if (!(fontFamily & TMPF_TRUETYPE)) { const wchar_t *msg = L"\nWarning: Your console font probably " L"doesn\'t support Unicode. If you experience strange " L"characters in the output, consider switching to a " L"TrueType font such as Consolas!\n"; DWORD dummy; WriteConsoleW(console, msg, wcslen(msg), &dummy, NULL); } }