Minor fixes to tracing
The chrome://tracing expects the timestamp to be in microseconds, but
it had been stored in the TraceItem in nanoseconds, so this fixes it.
Also adds quotes around the thread_id, since on Mac it is written in hex
format and so the JSON parser doesn't recognize it.
Finally, adds toolchain information to the import traces.
Change-Id: If5960074d4fc8301cbcc4a3524cb17ab6a95010a
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/5140
Commit-Queue: Julie Hockett <juliehockett@google.com>
Reviewed-by: Scott Graham <scottmg@chromium.org>
diff --git a/tools/gn/import_manager.cc b/tools/gn/import_manager.cc
index 36c7088..9339ff5 100644
--- a/tools/gn/import_manager.cc
+++ b/tools/gn/import_manager.cc
@@ -21,6 +21,7 @@
const ParseNode* node_for_err,
Err* err) {
ScopedTrace load_trace(TraceItem::TRACE_IMPORT_LOAD, file.value());
+ load_trace.SetToolchain(settings->toolchain_label());
const ParseNode* node = g_scheduler->input_file_manager()->SyncLoadFile(
node_for_err->GetRange(), settings->build_settings(), file, err);
@@ -129,6 +130,8 @@
std::this_thread::get_id());
import_block_trace->set_begin(import_block_begin);
import_block_trace->set_end(import_block_end);
+ import_block_trace->set_toolchain(
+ scope->settings()->toolchain_label().GetUserVisibleName(false));
AddTrace(import_block_trace);
}
}
diff --git a/tools/gn/trace.cc b/tools/gn/trace.cc
index 184c450..58a8c3c 100644
--- a/tools/gn/trace.cc
+++ b/tools/gn/trace.cc
@@ -24,6 +24,8 @@
namespace {
+constexpr uint64_t kNanosecondsToMicroseconds = 1'000;
+
class TraceLog {
public:
TraceLog() { events_.reserve(16384); }
@@ -244,7 +246,7 @@
// Write main thread metadata (assume this is being written on the main
// thread).
- out << "{\"pid\":0,\"tid\":" << std::this_thread::get_id();
+ out << "{\"pid\":0,\"tid\":\"" << std::this_thread::get_id() << "\"";
out << ",\"ts\":0,\"ph\":\"M\",";
out << "\"name\":\"thread_name\",\"args\":{\"name\":\"Main thread\"}},";
@@ -254,8 +256,8 @@
if (i != 0)
out << ",";
- out << "{\"pid\":0,\"tid\":" << item.thread_id();
- out << ",\"ts\":" << item.begin();
+ out << "{\"pid\":0,\"tid\":\"" << item.thread_id() << "\"";
+ out << ",\"ts\":" << item.begin() / kNanosecondsToMicroseconds;
out << ",\"ph\":\"X\""; // "X" = complete event with begin & duration.
out << ",\"dur\":" << item.delta().InMicroseconds();