| 12 | using Clock = std::chrono::steady_clock; |
| 13 | |
| 14 | int MultiClientTest(std::unique_ptr<pmapi::Session> pSession) |
| 15 | { |
| 16 | auto& opt = clio::Options::Get(); |
| 17 | |
| 18 | std::optional<PM_STATUS> errorStatus; |
| 19 | pmapi::ProcessTracker tracker; |
| 20 | |
| 21 | try { |
| 22 | if (opt.telemetryPeriodMs) { |
| 23 | pSession->SetTelemetryPollingPeriod(0, *opt.telemetryPeriodMs); |
| 24 | } |
| 25 | if (opt.etwFlushPeriodMs) { |
| 26 | pSession->SetEtwFlushPeriod(*opt.etwFlushPeriodMs); |
| 27 | } |
| 28 | if (opt.processId) { |
| 29 | tracker = pSession->TrackProcess(*opt.processId); |
| 30 | } |
| 31 | } |
| 32 | catch (const pmapi::ApiErrorException& e) { |
| 33 | if (!opt.testExpectError) { |
| 34 | throw; |
| 35 | } |
| 36 | errorStatus = e.GetCode(); |
| 37 | } |
| 38 | |
| 39 | std::string line; |
| 40 | |
| 41 | // ping gate to sync on init finished |
| 42 | std::getline(std::cin, line); |
| 43 | if (line != "%ping") { |
| 44 | std::cout << "%%{ping-error}%%" << std::endl; |
| 45 | return -1; |
| 46 | } |
| 47 | std::cout << "%%{ping-ok}%%" << std::endl; |
| 48 | |
| 49 | // if we captured an error, wait here for error ack |
| 50 | if (errorStatus) { |
| 51 | std::getline(std::cin, line); |
| 52 | if (line != "%err-check") { |
| 53 | std::cout << "%%{err-check-error}%%" << std::endl; |
| 54 | return -1; |
| 55 | } |
| 56 | auto&& err = pmapi::EnumMap::GetKeyMap(PM_ENUM_STATUS)->at(*errorStatus).narrowSymbol; |
| 57 | std::cout << "%%{err-check-ok:" << err << "}%%" << std::endl; |
| 58 | } |
| 59 | |
| 60 | // capture frames if requested |
| 61 | std::vector<Frame> frames; |
| 62 | if (opt.runTime) { |
| 63 | PM_BEGIN_FIXED_FRAME_QUERY(FrameQuery) |
| 64 | pmapi::FixedQueryElement cpuStartTime{ this, PM_METRIC_CPU_START_TIME }; |
| 65 | pmapi::FixedQueryElement msBetweenPresents{ this, PM_METRIC_BETWEEN_PRESENTS }; |
| 66 | pmapi::FixedQueryElement msUntilDisplayed{ this, PM_METRIC_UNTIL_DISPLAYED }; |
| 67 | pmapi::FixedQueryElement msGpuBusy{ this, PM_METRIC_GPU_BUSY }; |
| 68 | PM_END_FIXED_QUERY query{ *pSession, 1'000 }; |
| 69 | |
| 70 | const auto start = Clock::now(); |
| 71 | while (Clock::now() - start < 1s * *opt.runTime) { |
no test coverage detected