| 73 | } |
| 74 | |
| 75 | void Tracer::writeAsyncEvent( |
| 76 | const char* category, |
| 77 | const char* name, |
| 78 | char type, |
| 79 | int64_t id) { |
| 80 | |
| 81 | bool isAsync = true; |
| 82 | if (id < 0) { |
| 83 | // Use a standard Duration event for slices without an async ID. |
| 84 | isAsync = false; |
| 85 | if (type == 'b') { |
| 86 | type = 'B'; |
| 87 | } else if (type == 'e') { |
| 88 | type = 'E'; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | std::chrono::steady_clock::time_point time = std::chrono::steady_clock::now(); |
| 93 | int64_t microseconds = |
| 94 | std::chrono::time_point_cast<std::chrono::microseconds>(time) |
| 95 | .time_since_epoch() |
| 96 | .count(); |
| 97 | |
| 98 | std::lock_guard<std::mutex> lock(_lock); |
| 99 | if (!this->_output) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | // Chrome tracing wants the text like this |
| 104 | if (this->_numTraces++ > 0) { |
| 105 | this->_output << ","; |
| 106 | } |
| 107 | this->_output << "{"; |
| 108 | this->_output << "\"cat\":\"" << category << "\","; |
| 109 | if (isAsync) { |
| 110 | this->_output << "\"id\":" << id << ","; |
| 111 | } else { |
| 112 | this->_output << "\"tid\":" << std::this_thread::get_id() << ","; |
| 113 | } |
| 114 | this->_output << "\"name\":\"" << name << "\","; |
| 115 | this->_output << "\"ph\":\"" << type << "\","; |
| 116 | this->_output << "\"pid\":0,"; |
| 117 | this->_output << "\"ts\":" << microseconds; |
| 118 | this->_output << "}"; |
| 119 | } |
| 120 | |
| 121 | ScopedTrace::ScopedTrace(const std::string& message) |
| 122 | : _name{message}, |
no outgoing calls
no test coverage detected