| 43 | } |
| 44 | |
| 45 | void cmMakefileProfilingData::StartEntry(std::string const& category, |
| 46 | std::string const& name, |
| 47 | cm::optional<Json::Value> args) |
| 48 | { |
| 49 | /* Do not try again if we previously failed to write to output. */ |
| 50 | if (!this->ProfileStream.good()) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | try { |
| 55 | if (this->ProfileStream.tellp() > 1) { |
| 56 | this->ProfileStream << ","; |
| 57 | } |
| 58 | cmsys::SystemInformation info; |
| 59 | Json::Value v; |
| 60 | v["ph"] = "B"; |
| 61 | v["name"] = name; |
| 62 | v["cat"] = category; |
| 63 | v["ts"] = static_cast<Json::Value::UInt64>( |
| 64 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 65 | std::chrono::steady_clock::now().time_since_epoch()) |
| 66 | .count()); |
| 67 | v["pid"] = static_cast<int>(info.GetProcessId()); |
| 68 | v["tid"] = 0; |
| 69 | if (args) { |
| 70 | v["args"] = *std::move(args); |
| 71 | } |
| 72 | |
| 73 | this->JsonWriter->write(v, &this->ProfileStream); |
| 74 | } catch (std::ios_base::failure& fail) { |
| 75 | cmSystemTools::Error( |
| 76 | cmStrCat("Failed to write to profiling output: ", fail.what())); |
| 77 | } catch (...) { |
| 78 | cmSystemTools::Error("Error writing profiling output!"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void cmMakefileProfilingData::StopEntry() |
| 83 | { |