MCPcopy Create free account
hub / github.com/GameTechDev/PresentMon / wmain

Function wmain

PresentMon/MainThread.cpp:220–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220int wmain(int argc, wchar_t** argv)
221{
222 // Load system DLLs
223 LoadLibraryExA("advapi32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
224 LoadLibraryExA("shell32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
225 LoadLibraryExA("tdh.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
226 LoadLibraryExA("user32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
227
228 // Load NVIDIA DisplayDriver event manifest embedded in the PresentMon binary
229 if (!LoadNVDDManifest()) {
230 return 1;
231 }
232
233 // Initialize console
234 SetThreadDescription(GetCurrentThread(), L"PresentMon Consumer Thread");
235 InitializeConsole();
236
237 // Parse command line arguments.
238 if (!ParseCommandLine(argc, argv)) {
239 return 1;
240 }
241
242 auto const& args = GetCommandLineArgs();
243
244 // Special case handling for --terminate_existing_session
245 if (args.mTerminateExistingSession) {
246 auto status = StopNamedTraceSession(args.mSessionName);
247 switch (status) {
248 case ERROR_SUCCESS: return 0;
249 case ERROR_WMI_INSTANCE_NOT_FOUND: PrintError(L"error: no existing sessions found: %s\n", args.mSessionName); break;
250 default: PrintError(L"error: failed to terminate existing session (%s): %lu\n", args.mSessionName, status); break;
251 }
252 return 7;
253 }
254
255 // Attempt to elevate process privilege if necessary.
256 //
257 // If we are processing an ETL file we don't need elevated privilege, but
258 // for realtime analysis we need SeDebugPrivilege in order to open handles
259 // to processes started by other accounts (see OutputThread.cpp).
260 //
261 // If we can't enable SeDebugPrivilege, try to restart PresentMon as
262 // administrator unless the user requested not to.
263 //
264 // RestartAsAdministrator() waits for the elevated process to complete in
265 // order to report stderr and obtain it's exit code.
266 if (args.mEtlFileName == nullptr && // realtime analysis
267 !EnableDebugPrivilege()) { // failed to enable SeDebugPrivilege
268 if (args.mTryToElevate) {
269 return RestartAsAdministrator(argc, argv);
270 }
271
272 PrintWarning(
273 L"warning: PresentMon requires elevated privilege in order to query processes that are\n"
274 L" short-running or started on another account. Without it, those processes will\n"
275 L" be listed as '<unknown>' and they can't be targeted by --process_name nor trigger\n"
276 L" --terminate_on_proc_exit.\n");
277 }

Callers

nothing calls this directly

Calls 15

LoadNVDDManifestFunction · 0.85
ParseCommandLineFunction · 0.85
StopNamedTraceSessionFunction · 0.85
PrintErrorFunction · 0.85
EnableDebugPrivilegeFunction · 0.85
RestartAsAdministratorFunction · 0.85
PrintWarningFunction · 0.85
PrintHotkeyErrorFunction · 0.85
InPerfLogUsersGroupFunction · 0.85
StartConsumerThreadFunction · 0.85
StartOutputThreadFunction · 0.85
EnableScrollLockFunction · 0.85

Tested by

no test coverage detected