summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yurii Zubrytskyi <zyy@google.com> 2023-08-17 13:55:49 -0700
committer Yurii Zubrytskyi <zyy@google.com> 2023-08-17 13:58:44 -0700
commit1e496964ae10fb5a2be8a483b3844cfafb867aef (patch)
tree80b44a06360474c90aee63ff1e2a09ac7a5ac04f
parent6f5cc1f4762f90f76fd249ed1298bca01f930ce2 (diff)
[aapt2] Change the base timestamp of the traces
Perfetto UI doesn't work well if the timestamps are way into the 64 bit territory. This CL ensures we always start with 0, making the UI work well for all traces Bug: 294025081 Test: manual tracing run Change-Id: I5b74d4dda62ff40c1eab7e33144533e77e59c949
-rw-r--r--tools/aapt2/trace/TraceBuffer.cpp14
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_);
}