| 190 | }; |
| 191 | |
| 192 | int PacedPlaybackTest(std::unique_ptr<pmapi::Session> pSession) |
| 193 | { |
| 194 | auto& opt = clio::Options::Get(); |
| 195 | |
| 196 | std::optional<PM_STATUS> errorStatus; |
| 197 | |
| 198 | try { |
| 199 | if (!opt.processId) { |
| 200 | pmlog_error("need pid"); |
| 201 | } |
| 202 | |
| 203 | // connect to service and register query |
| 204 | TestClientModule client{ std::move(pSession), *opt.windowSize, *opt.metricOffset }; |
| 205 | if (opt.etwFlushPeriodMs) { |
| 206 | client.SetETWFlushPeriod(*opt.etwFlushPeriodMs); |
| 207 | } |
| 208 | if (opt.telemetryPeriodMs) { |
| 209 | client.SetTelemetryPeriod(*opt.telemetryPeriodMs); |
| 210 | } |
| 211 | |
| 212 | // ping gate to sync on init finished |
| 213 | std::string line; |
| 214 | std::getline(std::cin, line); |
| 215 | if (line != "%ping") { |
| 216 | std::cout << "%%{ping-error}%%" << std::endl; |
| 217 | return -1; |
| 218 | } |
| 219 | std::cout << "%%{ping-ok}%%" << std::endl; |
| 220 | |
| 221 | // poll for designated period and parse run results |
| 222 | const auto runTimeEnd = *opt.runStart + *opt.runTime; |
| 223 | auto run = client.RecordPolling(*opt.processId, *opt.runStart, runTimeEnd, *opt.pollPeriod); |
| 224 | WriteRunToCsv(*opt.outputPath, MakeHeader(client.GetQueryElements(), client.GetIntrospection()), run); |
| 225 | } |
| 226 | catch (const pmapi::ApiErrorException& e) { |
| 227 | if (!opt.testExpectError) { |
| 228 | throw; |
| 229 | } |
| 230 | errorStatus = e.GetCode(); |
| 231 | } |
| 232 | |
| 233 | std::string line; |
| 234 | |
| 235 | // if we captured an error, wait here for error ack |
| 236 | if (errorStatus) { |
| 237 | std::getline(std::cin, line); |
| 238 | if (line != "%err-check") { |
| 239 | std::cout << "%%{err-check-error}%%" << std::endl; |
| 240 | return -1; |
| 241 | } |
| 242 | auto&& err = pmapi::EnumMap::GetKeyMap(PM_ENUM_STATUS)->at(*errorStatus).narrowSymbol; |
| 243 | std::cout << "%%{err-check-ok:" << err << "}%%" << std::endl; |
| 244 | } |
| 245 | |
| 246 | // wait for command |
| 247 | while (std::getline(std::cin, line)) { |
| 248 | if (line == "%quit") { |
| 249 | std::cout << "%%{quit-ok}%%" << std::endl; |
no test coverage detected