forked from GameTechDev/PresentMon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
118 lines (104 loc) · 3.62 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//--------------------------------------------------------------------------------------
// Copyright 2015 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies. Intel makes no representations about the
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//--------------------------------------------------------------------------------------
#include <windows.h>
#include <thread>
#include <cstdio>
#include "PresentMon.hpp"
#include "Util.hpp"
bool g_Quit = false;
static std::thread *g_PresentMonThread;
BOOL WINAPI HandlerRoutine(
_In_ DWORD dwCtrlType
)
{
g_Quit = true;
if (g_PresentMonThread) {
g_PresentMonThread->join();
}
exit(0);
return TRUE;
}
int main(int argc, char ** argv)
{
--argc;
++argv;
if (argc == 0) {
printf(
"command line options:\n"
" -captureall: record ALL processes (default).\n"
" -process_name [exe name]: record specific process.\n"
" -process_id [integer]: record specific process ID.\n"
" -output_file [path]: override the default output path.\n"
" -no_csv: do not create any output file.\n"
" -scroll_toggle: use scroll lock to toggle capture on/off.\n"
);
return 0;
}
int waitpid = -1;
PresentMonArgs args;
args.mTargetProcessName = "*";
for (int i = 0; i < argc; ++i)
{
// 2-component arguments
if (i + 1 < argc)
{
if (!strcmp(argv[i], "-waitpid"))
{
waitpid = atoi(argv[++i]);
}
else if (!strcmp(argv[i], "-process_name"))
{
args.mTargetProcessName = argv[++i];
}
else if (!strcmp(argv[i], "-process_id"))
{
args.mTargetPid = atoi(argv[++i]);
}
else if (!strcmp(argv[i], "-output_file"))
{
args.mOutputFileName = argv[++i];
}
}
// 1-component args
else
{
if (!strcmp(argv[i], "-no_csv"))
{
args.mOutputFileName = "*";
} else if (!strcmp(argv[i], "-scroll_toggle"))
{
args.mScrollLockToggle = true;
}
}
}
if (waitpid >= 0) {
WaitForProcess(waitpid);
if (!HaveAdministratorPrivilidges()) {
printf("Elevation process failed. Aborting.\n");
return 0;
}
}
if (!HaveAdministratorPrivilidges()) {
printf("Process is not running as admin. Attempting to elevate.\n");
RestartAsAdministrator(argc, argv);
return 0;
}
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
// Run PM in a separate thread so we can join it in the CtrlHandler (can't join the main thread)
std::thread pm(PresentMonEtw, args);
g_PresentMonThread = ±
Sleep(INFINITE);
}