Merge changes I5930e6b7,I80863a68
* changes:
Get the waker from the instants table instead of the raw table
Populate waker_utid arg for sched_waking and sched_wakeup
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.cc b/src/trace_processor/importers/ftrace/ftrace_parser.cc
index c25859e..28df319 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.cc
@@ -145,7 +145,8 @@
sched_blocked_reason_id_(
context->storage->InternString("sched_blocked_reason")),
io_wait_id_(context->storage->InternString("io_wait")),
- function_id_(context->storage->InternString("function")) {
+ function_id_(context->storage->InternString("function")),
+ waker_utid_id_(context->storage->InternString("waker_utid")) {
// Build the lookup table for the strings inside ftrace events (e.g. the
// name of ftrace event fields and the names of their args).
for (size_t i = 0; i < GetDescriptorsSize(); i++) {
@@ -368,11 +369,11 @@
break;
}
case FtraceEvent::kSchedWakeupFieldNumber: {
- ParseSchedWakeup(ts, data);
+ ParseSchedWakeup(ts, pid, data);
break;
}
case FtraceEvent::kSchedWakingFieldNumber: {
- ParseSchedWaking(ts, data);
+ ParseSchedWaking(ts, pid, data);
break;
}
case FtraceEvent::kSchedProcessFreeFieldNumber: {
@@ -734,24 +735,36 @@
next_pid, ss.next_comm(), ss.next_prio());
}
-void FtraceParser::ParseSchedWakeup(int64_t timestamp, ConstBytes blob) {
+void FtraceParser::ParseSchedWakeup(int64_t timestamp,
+ uint32_t pid,
+ ConstBytes blob) {
protos::pbzero::SchedWakeupFtraceEvent::Decoder sw(blob.data, blob.size);
uint32_t wakee_pid = static_cast<uint32_t>(sw.pid());
StringId name_id = context_->storage->InternString(sw.comm());
- auto utid = context_->process_tracker->UpdateThreadName(
+ auto wakee_utid = context_->process_tracker->UpdateThreadName(
wakee_pid, name_id, ThreadNamePriority::kFtrace);
- context_->event_tracker->PushInstant(timestamp, sched_wakeup_name_id_, utid,
- RefType::kRefUtid);
+ InstantId id = context_->event_tracker->PushInstant(
+ timestamp, sched_wakeup_name_id_, wakee_utid, RefType::kRefUtid);
+
+ UniqueTid utid = context_->process_tracker->GetOrCreateThread(pid);
+ context_->args_tracker->AddArgsTo(id).AddArg(waker_utid_id_,
+ Variadic::UnsignedInteger(utid));
}
-void FtraceParser::ParseSchedWaking(int64_t timestamp, ConstBytes blob) {
+void FtraceParser::ParseSchedWaking(int64_t timestamp,
+ uint32_t pid,
+ ConstBytes blob) {
protos::pbzero::SchedWakingFtraceEvent::Decoder sw(blob.data, blob.size);
uint32_t wakee_pid = static_cast<uint32_t>(sw.pid());
StringId name_id = context_->storage->InternString(sw.comm());
- auto utid = context_->process_tracker->UpdateThreadName(
+ auto wakee_utid = context_->process_tracker->UpdateThreadName(
wakee_pid, name_id, ThreadNamePriority::kFtrace);
- context_->event_tracker->PushInstant(timestamp, sched_waking_name_id_, utid,
- RefType::kRefUtid);
+ InstantId id = context_->event_tracker->PushInstant(
+ timestamp, sched_waking_name_id_, wakee_utid, RefType::kRefUtid);
+
+ UniqueTid utid = context_->process_tracker->GetOrCreateThread(pid);
+ context_->args_tracker->AddArgsTo(id).AddArg(waker_utid_id_,
+ Variadic::UnsignedInteger(utid));
}
void FtraceParser::ParseSchedProcessFree(int64_t timestamp, ConstBytes blob) {
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.h b/src/trace_processor/importers/ftrace/ftrace_parser.h
index bf798a3..2f4cb0b 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.h
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.h
@@ -48,8 +48,8 @@
protozero::ConstBytes,
PacketSequenceStateGeneration*);
void ParseSchedSwitch(uint32_t cpu, int64_t timestamp, protozero::ConstBytes);
- void ParseSchedWakeup(int64_t timestamp, protozero::ConstBytes);
- void ParseSchedWaking(int64_t timestamp, protozero::ConstBytes);
+ void ParseSchedWakeup(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
+ void ParseSchedWaking(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
void ParseSchedProcessFree(int64_t timestamp, protozero::ConstBytes);
void ParseCpuFreq(int64_t timestamp, protozero::ConstBytes);
void ParseGpuFreq(int64_t timestamp, protozero::ConstBytes);
@@ -191,6 +191,7 @@
const StringId sched_blocked_reason_id_;
const StringId io_wait_id_;
const StringId function_id_;
+ const StringId waker_utid_id_;
struct FtraceMessageStrings {
// The string id of name of the event field (e.g. sched_switch's id).
diff --git a/src/trace_processor/importers/ftrace/sched_event_tracker.cc b/src/trace_processor/importers/ftrace/sched_event_tracker.cc
index 2fc7fc3..00fc93f 100644
--- a/src/trace_processor/importers/ftrace/sched_event_tracker.cc
+++ b/src/trace_processor/importers/ftrace/sched_event_tracker.cc
@@ -36,7 +36,8 @@
namespace trace_processor {
SchedEventTracker::SchedEventTracker(TraceProcessorContext* context)
- : context_(context) {
+ : waker_utid_id_(context->storage->InternString("waker_utid")),
+ context_(context) {
// pre-parse sched_switch
auto* switch_descriptor = GetMessageDescriptorForId(
protos::pbzero::FtraceEvent::kSchedSwitchFieldNumber);
@@ -318,7 +319,11 @@
auto* instants = context_->storage->mutable_instant_table();
auto ref_type_id = context_->storage->InternString(
GetRefTypeStringMap()[static_cast<size_t>(RefType::kRefUtid)]);
- instants->Insert({ts, sched_waking_id_, wakee_utid, ref_type_id});
+ tables::InstantTable::Id id =
+ instants->Insert({ts, sched_waking_id_, wakee_utid, ref_type_id}).id;
+
+ context_->args_tracker->AddArgsTo(id).AddArg(
+ waker_utid_id_, Variadic::UnsignedInteger(curr_utid));
}
void SchedEventTracker::FlushPendingEvents() {
diff --git a/src/trace_processor/importers/ftrace/sched_event_tracker.h b/src/trace_processor/importers/ftrace/sched_event_tracker.h
index eae4bac..eff442c 100644
--- a/src/trace_processor/importers/ftrace/sched_event_tracker.h
+++ b/src/trace_processor/importers/ftrace/sched_event_tracker.h
@@ -129,6 +129,8 @@
std::array<StringId, kSchedWakingMaxFieldId + 1> sched_waking_field_ids_;
StringId sched_waking_id_;
+ StringId waker_utid_id_;
+
TraceProcessorContext* const context_;
};
diff --git a/src/trace_processor/importers/systrace/systrace_line_parser.cc b/src/trace_processor/importers/systrace/systrace_line_parser.cc
index 5df3e8d..c78d975 100644
--- a/src/trace_processor/importers/systrace/systrace_line_parser.cc
+++ b/src/trace_processor/importers/systrace/systrace_line_parser.cc
@@ -45,7 +45,8 @@
workqueue_name_id_(ctx->storage->InternString("workqueue")),
sched_blocked_reason_id_(
ctx->storage->InternString("sched_blocked_reason")),
- io_wait_id_(ctx->storage->InternString("io_wait")) {}
+ io_wait_id_(ctx->storage->InternString("io_wait")),
+ waker_utid_id_(ctx->storage->InternString("waker_utid")) {}
util::Status SystraceLineParser::ParseLine(const SystraceLine& line) {
auto utid = context_->process_tracker->UpdateThreadName(
@@ -117,8 +118,11 @@
StringId event_name_id = line.event_name == "sched_wakeup"
? sched_wakeup_name_id_
: sched_waking_name_id_;
- context_->event_tracker->PushInstant(line.ts, event_name_id, wakee_utid,
- RefType::kRefUtid);
+ InstantId instant_id = context_->event_tracker->PushInstant(
+ line.ts, event_name_id, wakee_utid, RefType::kRefUtid);
+ context_->args_tracker->AddArgsTo(instant_id)
+ .AddArg(waker_utid_id_, Variadic::UnsignedInteger(utid));
+
} else if (line.event_name == "cpu_idle") {
base::Optional<uint32_t> event_cpu = base::StringToUInt32(args["cpu_id"]);
base::Optional<double> new_state = base::StringToDouble(args["state"]);
diff --git a/src/trace_processor/importers/systrace/systrace_line_parser.h b/src/trace_processor/importers/systrace/systrace_line_parser.h
index f0738a8..24331fe 100644
--- a/src/trace_processor/importers/systrace/systrace_line_parser.h
+++ b/src/trace_processor/importers/systrace/systrace_line_parser.h
@@ -43,6 +43,7 @@
const StringId workqueue_name_id_ = kNullStringId;
const StringId sched_blocked_reason_id_ = kNullStringId;
const StringId io_wait_id_ = kNullStringId;
+ const StringId waker_utid_id_ = kNullStringId;
};
} // namespace trace_processor
diff --git a/ui/src/controller/selection_controller.ts b/ui/src/controller/selection_controller.ts
index 3726947..82f6e22 100644
--- a/ui/src/controller/selection_controller.ts
+++ b/ui/src/controller/selection_controller.ts
@@ -416,10 +416,22 @@
}
// Find the sched slice with the utid of the waker running when the
// sched wakeup occurred. This is the waker.
- const queryWaker = `select utid, cpu from sched where utid =
- (select utid from raw where name = '${event}' and ts = ${wakeupTs})
+ let queryWaker = `select utid, cpu from sched where utid =
+ (select EXTRACT_ARG(arg_set_id, 'waker_utid') from instants where name =
+ '${event}' and ts = ${wakeupTs})
and ts < ${wakeupTs} and ts + dur >= ${wakeupTs};`;
- const wakerResult = await this.args.engine.query(queryWaker);
+ let wakerResult = await this.args.engine.query(queryWaker);
+ if (wakerResult.numRows() === 0) {
+ // An old version of trace processor (that does not populate the
+ // 'waker_utid' arg) might be in use. Try getting the same info from the
+ // raw table).
+ // TODO(b/206390308): Remove this workaround when
+ // TRACE_PROCESSOR_CURRENT_API_VERSION is incremented.
+ queryWaker = `select utid, cpu from sched where utid =
+ (select utid from raw where name = '${event}' and ts = ${wakeupTs})
+ and ts < ${wakeupTs} and ts + dur >= ${wakeupTs};`;
+ wakerResult = await this.args.engine.query(queryWaker);
+ }
if (wakerResult.numRows() === 0) {
return undefined;
}