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

Function WinMain

IntelPresentMon/KernelProcess/winmain.cpp:117–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
118{
119 using namespace kproc;
120 using namespace p2c;
121
122#ifdef NDEBUG
123 constexpr bool is_debug = false;
124#else
125 constexpr bool is_debug = true;
126#endif
127
128 try {
129 util::log::IdentificationTable::AddThisProcess("kproc");
130 util::log::IdentificationTable::AddThisThread("main");
131 // if we were run from a parent with a console (terminal?), try to attach there
132 const bool fromTerminal = TryAttachToParentConsole_();
133 // parse the command line arguments and make them globally available
134 if (auto err = cli::Options::Init(__argc, __argv, true)) {
135 if (*err == 0) {
136 // we don't have a console connection by default, so get one
137 if (!fromTerminal) {
138 AllocAndBindConsole_();
139 }
140 std::cout << cli::Options::GetDiagnostics() << std::endl;
141 // if we're not run from terminal, make sure created console does not close immediately
142 if (!fromTerminal) {
143 std::cout << "Press <ENTER> to continue...";
144 std::cin.get();
145 }
146 }
147 else {
148 if (fromTerminal) {
149 std::cerr << cli::Options::GetDiagnostics() << std::endl;
150 }
151 else {
152 MessageBoxA(nullptr, cli::Options::GetDiagnostics().c_str(), "Command Line Parse Error",
153 MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
154 }
155 }
156 return *err;
157 }
158 const auto& opt = cli::Options::Get();
159 if (opt.logFolder) {
160 infra::util::FolderResolver::SetLogPathOverride(util::str::ToWide(*opt.logFolder));
161 }
162 // do some post validation here
163 if (opt.subcCapture.Active()) {
164 // make sure target is specified
165 if (!opt.capTargetName && !opt.capTargetPid) {
166 std::cerr << "Must specify one of --target-name or --target-pid for capture" << std::endl;
167 return -1;
168 }
169 }
170 if (opt.subcList.Active()) {
171 // make sure target is specified
172 if (!opt.listMetrics && !opt.listDevices) {
173 std::cerr << "Must specify one of --metrics or --devices for list" << std::endl;
174 return -1;

Callers

nothing calls this directly

Calls 15

AllocAndBindConsole_Function · 0.85
GetDiagnosticsFunction · 0.85
ToWideFunction · 0.85
ExplorePathFunction · 0.85
GetVerboseModuleNameFunction · 0.85
VEnum · 0.85
ToLowerFunction · 0.85
ConfigureHeadlessLoggingFunction · 0.85
BuildIdShortHashFunction · 0.85

Tested by

no test coverage detected