diff options
| author | 2023-08-21 16:50:30 +0000 | |
|---|---|---|
| committer | 2023-08-21 16:50:30 +0000 | |
| commit | f131d8beb2c86ff8610eac35a3db181358d710db (patch) | |
| tree | 0b6b309947ce2160fca3c6d0772aa31ae760f66f | |
| parent | 1fc9dac6f433142f59017e087209cd3f286c4495 (diff) | |
| parent | 1e496964ae10fb5a2be8a483b3844cfafb867aef (diff) | |
Merge "[aapt2] Change the base timestamp of the traces" into main
| -rw-r--r-- | tools/aapt2/trace/TraceBuffer.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tools/aapt2/trace/TraceBuffer.cpp b/tools/aapt2/trace/TraceBuffer.cpp index fab2df383e3f..0988c313b65b 100644 --- a/tools/aapt2/trace/TraceBuffer.cpp +++ b/tools/aapt2/trace/TraceBuffer.cpp @@ -44,14 +44,16 @@ struct TracePoint { std::vector<TracePoint> traces; bool enabled = true; +constinit std::chrono::steady_clock::time_point startTime = {}; int64_t GetTime() noexcept { auto now = std::chrono::steady_clock::now(); - return std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count(); + if (startTime == decltype(tracebuffer::startTime){}) { + startTime = now; + } + return std::chrono::duration_cast<std::chrono::microseconds>(now - startTime).count(); } -} // namespace anonymous - void AddWithTime(std::string tag, char type, int64_t time) noexcept { TracePoint t = {type, getpid(), time, std::move(tag)}; traces.emplace_back(std::move(t)); @@ -76,7 +78,7 @@ void Flush(const std::string& basePath) { // Wrap the trace in a JSON array [] to make Chrome/Perfetto UI handle it. char delimiter = '['; - for(const TracePoint& trace : traces) { + for (const TracePoint& trace : traces) { fprintf(f, "%c{\"ts\" : \"%" PRIu64 "\", \"ph\" : \"%c\", \"tid\" : \"%d\" , \"pid\" : \"%d\", \"name\" : \"%s\" }\n", @@ -90,6 +92,8 @@ void Flush(const std::string& basePath) { traces.clear(); } +} // namespace + } // namespace tracebuffer void BeginTrace(std::string tag) { @@ -166,7 +170,7 @@ FlushTrace::FlushTrace(std::string_view basepath, std::string_view tag, FlushTrace::~FlushTrace() { if (!tracebuffer::enabled) return; - tracebuffer::Add(tag_, tracebuffer::kEnd); + tracebuffer::Add(std::move(tag_), tracebuffer::kEnd); tracebuffer::Flush(basepath_); } |