trace_processor: Stop confusing upid with utid in systrace parsing
Also make unmatched end slices not CHECK as this is fairly common in
Android systrace events.
Change-Id: I9091ff242d1a571f9ec1a035113efc6d96f5613f
diff --git a/src/trace_processor/counters_table.cc b/src/trace_processor/counters_table.cc
index 4f2173f..1cc4026 100644
--- a/src/trace_processor/counters_table.cc
+++ b/src/trace_processor/counters_table.cc
@@ -95,8 +95,8 @@
sqlite3_result_text(context, "cpu", -1, nullptr);
break;
}
- case RefType::kUPID: {
- sqlite3_result_text(context, "upid", -1, nullptr);
+ case RefType::kUTID: {
+ sqlite3_result_text(context, "utid", -1, nullptr);
break;
}
}
diff --git a/src/trace_processor/process_tracker.cc b/src/trace_processor/process_tracker.cc
index 295cf5a..2da8994 100644
--- a/src/trace_processor/process_tracker.cc
+++ b/src/trace_processor/process_tracker.cc
@@ -42,7 +42,8 @@
auto prev_utid = std::prev(pair_it.second)->second;
TraceStorage::Thread* thread =
context_->storage->GetMutableThread(prev_utid);
- thread->name_id = thread_name_id;
+ if (thread_name_id)
+ thread->name_id = thread_name_id;
return prev_utid;
}
diff --git a/src/trace_processor/proto_trace_parser.cc b/src/trace_processor/proto_trace_parser.cc
index bf42b3f..ac1b65c 100644
--- a/src/trace_processor/proto_trace_parser.cc
+++ b/src/trace_processor/proto_trace_parser.cc
@@ -45,31 +45,31 @@
const char* s = str.data();
size_t len = str.size();
- // If str matches '[BEC]\|[0-9]+[\|\n]' set pid_length to the length of
+ // If str matches '[BEC]\|[0-9]+[\|\n]' set tid_length to the length of
// the number. Otherwise return false.
if (len < 3 || s[1] != '|')
return false;
if (s[0] != 'B' && s[0] != 'E' && s[0] != 'C')
return false;
- size_t pid_length;
+ size_t tid_length;
for (size_t i = 2;; i++) {
if (i >= len)
return false;
if (s[i] == '|' || s[i] == '\n') {
- pid_length = i - 2;
+ tid_length = i - 2;
break;
}
if (s[i] < '0' || s[i] > '9')
return false;
}
- std::string pid_str(s + 2, pid_length);
- out->pid = static_cast<uint32_t>(std::stoi(pid_str.c_str()));
+ std::string tid_str(s + 2, tid_length);
+ out->tid = static_cast<uint32_t>(std::stoi(tid_str.c_str()));
out->phase = s[0];
switch (s[0]) {
case 'B': {
- size_t name_index = 2 + pid_length + 1;
+ size_t name_index = 2 + tid_length + 1;
out->name = base::StringView(s + name_index, len - name_index);
return true;
}
@@ -77,7 +77,7 @@
return true;
}
case 'C': {
- size_t name_index = 2 + pid_length + 1;
+ size_t name_index = 2 + tid_length + 1;
size_t name_length = 0;
for (size_t i = name_index; i < len; i++) {
if (s[i] == '|' || s[i] == '\n') {
@@ -289,24 +289,25 @@
if (!ParseSystraceTracePoint(buf, &point))
return;
- UniquePid upid = context_->process_tracker->UpdateProcess(point.pid);
+ UniqueTid utid =
+ context_->process_tracker->UpdateThread(timestamp, point.tid, 0);
switch (point.phase) {
case 'B': {
StringId name_id = context_->storage->InternString(point.name);
- context_->slice_tracker->Begin(timestamp, upid, 0 /*cat_id*/, name_id);
+ context_->slice_tracker->Begin(timestamp, utid, 0 /*cat_id*/, name_id);
break;
}
case 'E': {
- context_->slice_tracker->End(timestamp, upid);
+ context_->slice_tracker->End(timestamp, utid);
break;
}
case 'C': {
StringId name_id = context_->storage->InternString(point.name);
context_->sched_tracker->PushCounter(timestamp, point.value, name_id,
- upid, RefType::kUPID);
+ utid, RefType::kUTID);
}
}
PERFETTO_DCHECK(decoder.IsEndOfBuffer());
diff --git a/src/trace_processor/proto_trace_parser.h b/src/trace_processor/proto_trace_parser.h
index 2586e5c..9da91e4 100644
--- a/src/trace_processor/proto_trace_parser.h
+++ b/src/trace_processor/proto_trace_parser.h
@@ -31,7 +31,7 @@
struct SystraceTracePoint {
char phase;
- uint32_t pid;
+ uint32_t tid;
// For phase = 'B' and phase = 'C' only.
base::StringView name;
@@ -42,8 +42,8 @@
inline bool operator==(const SystraceTracePoint& x,
const SystraceTracePoint& y) {
- return std::tie(x.phase, x.pid, x.name, x.value) ==
- std::tie(y.phase, y.pid, y.name, y.value);
+ return std::tie(x.phase, x.tid, x.name, x.value) ==
+ std::tie(y.phase, y.tid, y.name, y.value);
}
bool ParseSystraceTracePoint(base::StringView, SystraceTracePoint* out);
diff --git a/src/trace_processor/slice_tracker.cc b/src/trace_processor/slice_tracker.cc
index 1d0e8d1..16dbc3c 100644
--- a/src/trace_processor/slice_tracker.cc
+++ b/src/trace_processor/slice_tracker.cc
@@ -56,7 +56,9 @@
StringId name) {
auto& stack = threads_[utid];
MaybeCloseStack(timestamp, stack);
- PERFETTO_CHECK(!stack.empty());
+ if (stack.empty()) {
+ return;
+ }
PERFETTO_CHECK(cat == 0 || stack.back().cat_id == cat);
PERFETTO_CHECK(name == 0 || stack.back().name_id == name);
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
index c462d19..47ccbf7 100644
--- a/src/trace_processor/trace_storage.h
+++ b/src/trace_processor/trace_storage.h
@@ -43,7 +43,7 @@
// StringId is an offset into |string_pool_|.
using StringId = size_t;
-enum RefType { kUPID = 0, kCPU_ID = 1 };
+enum RefType { kUTID = 0, kCPU_ID = 1 };
// Stores a data inside a trace file in a columnar form. This makes it efficient
// to read or search across a single field of the trace (e.g. all the thread