Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e496964 authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[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
parent 6f5cc1f4
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -44,13 +44,15 @@ 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)};
@@ -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_);
}