| 269 | } |
| 270 | |
| 271 | void startProfiling(INetwork* network, |
| 272 | Optional<int> maybePeriod /*= {}*/, |
| 273 | Optional<StringRef> maybeOutputFile /*= {}*/) { |
| 274 | int period; |
| 275 | if (maybePeriod.present()) { |
| 276 | period = maybePeriod.get(); |
| 277 | } else { |
| 278 | const char* periodEnv = getenv("FLOW_PROFILER_PERIOD"); |
| 279 | period = (periodEnv ? atoi(periodEnv) : 2000); |
| 280 | } |
| 281 | std::string outputFile; |
| 282 | if (maybeOutputFile.present()) { |
| 283 | outputFile = std::string((const char*)maybeOutputFile.get().begin(), maybeOutputFile.get().size()); |
| 284 | } else { |
| 285 | const char* outfn = getenv("FLOW_PROFILER_OUTPUT"); |
| 286 | outputFile = (outfn ? outfn : "profile.bin"); |
| 287 | } |
| 288 | outputFile = findAndReplace( |
| 289 | findAndReplace( |
| 290 | findAndReplace(outputFile, "%ADDRESS%", findAndReplace(network->getLocalAddress().toString(), ":", ".")), |
| 291 | "%PID%", |
| 292 | format("%d", getpid())), |
| 293 | "%TID%", |
| 294 | format("%llx", (long long)sys_gettid())); |
| 295 | |
| 296 | if (!Profiler::active_profiler) |
| 297 | Profiler::active_profiler = new Profiler(period, outputFile, network); |
| 298 | } |
| 299 | |
| 300 | void stopProfiling() { |
| 301 | if (Profiler::active_profiler) { |
no test coverage detected