Pass process_priority from the StreamingProfile packets through to the JSON output
R=ssid@google.com
Bug:chromium:1065077
Change-Id: Ia73e9a744585a82c7c9f6a679ffedc2b77d3f56e
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index ae9cfbb..62cd802 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -6000,6 +6000,7 @@
// TODO(eseckler): ThreadDescriptor-based timestamps are deprecated. Replace
// this with ClockSnapshot-based delta encoding instead.
repeated int64 timestamp_delta_us = 2;
+ optional int32 process_priority = 3;
}
// Namespace for the contained enums.
diff --git a/protos/perfetto/trace/profiling/profile_packet.proto b/protos/perfetto/trace/profiling/profile_packet.proto
index 6a94772..eb994b7 100644
--- a/protos/perfetto/trace/profiling/profile_packet.proto
+++ b/protos/perfetto/trace/profiling/profile_packet.proto
@@ -148,6 +148,7 @@
// TODO(eseckler): ThreadDescriptor-based timestamps are deprecated. Replace
// this with ClockSnapshot-based delta encoding instead.
repeated int64 timestamp_delta_us = 2;
+ optional int32 process_priority = 3;
}
// Namespace for the contained enums.
diff --git a/src/trace_processor/export_json.cc b/src/trace_processor/export_json.cc
index 2e5516d..c99c15b 100644
--- a/src/trace_processor/export_json.cc
+++ b/src/trace_processor/export_json.cc
@@ -1175,6 +1175,7 @@
}
event["args"]["frames"] = merged_callstack;
+ event["args"]["process_priority"] = samples.process_priority()[i];
// TODO(oysteine): Used for backwards compatibility with the memlog
// pipeline, should remove once we've switched to looking directly at the
diff --git a/src/trace_processor/export_json_unittest.cc b/src/trace_processor/export_json_unittest.cc
index 4be5687..7b71563 100644
--- a/src/trace_processor/export_json_unittest.cc
+++ b/src/trace_processor/export_json_unittest.cc
@@ -1340,6 +1340,7 @@
const uint32_t kProcessID = 100;
const uint32_t kThreadID = 200;
const int64_t kTimestamp = 10000000;
+ const int32_t kProcessPriority = 42;
TraceStorage* storage = context_.storage.get();
@@ -1386,7 +1387,7 @@
callsites->Insert({1, frame_callsite_1.id, frame_2.id});
storage->mutable_cpu_profile_stack_sample_table()->Insert(
- {kTimestamp, frame_callsite_2.id, utid});
+ {kTimestamp, frame_callsite_2.id, utid, kProcessPriority});
base::TempFile temp_file = base::TempFile::Create();
FILE* output = fopen(temp_file.path().c_str(), "w+");
@@ -1408,6 +1409,7 @@
EXPECT_EQ(event["args"]["frames"].asString(),
"foo_func - foo_module_name [foo_module_id]\nbar_func - "
"bar_module_name [bar_module_id]\n");
+ EXPECT_EQ(event["args"]["process_priority"].asInt(), kProcessPriority);
}
TEST_F(ExportJsonTest, ArgumentFilter) {
diff --git a/src/trace_processor/importers/proto/profile_module.cc b/src/trace_processor/importers/proto/profile_module.cc
index 8249452..2ce0236 100644
--- a/src/trace_processor/importers/proto/profile_module.cc
+++ b/src/trace_processor/importers/proto/profile_module.cc
@@ -142,8 +142,8 @@
// Resolve the delta timestamps based on the packet's root timestamp.
timestamp += *timestamp_it * 1000;
- tables::CpuProfileStackSampleTable::Row sample_row{timestamp, *opt_cs_id,
- utid};
+ tables::CpuProfileStackSampleTable::Row sample_row{
+ timestamp, *opt_cs_id, utid, packet.process_priority()};
storage->mutable_cpu_profile_stack_sample_table()->Insert(sample_row);
}
}
diff --git a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
index ec5ea31..7187c45 100644
--- a/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/importers/proto/proto_trace_parser_unittest.cc
@@ -2569,6 +2569,7 @@
samples->add_callstack_iid(1);
samples->add_timestamp_delta_us(15);
+ samples->set_process_priority(20);
}
{
@@ -2578,6 +2579,7 @@
samples->add_callstack_iid(42);
samples->add_timestamp_delta_us(42);
+ samples->set_process_priority(30);
}
EXPECT_CALL(*process_, UpdateThread(16, 15))
@@ -2592,14 +2594,17 @@
EXPECT_EQ(samples.ts()[0], 11000);
EXPECT_EQ(samples.callsite_id()[0], CallsiteId{0});
EXPECT_EQ(samples.utid()[0], 1u);
+ EXPECT_EQ(samples.process_priority()[0], 20);
EXPECT_EQ(samples.ts()[1], 26000);
EXPECT_EQ(samples.callsite_id()[1], CallsiteId{1});
EXPECT_EQ(samples.utid()[1], 1u);
+ EXPECT_EQ(samples.process_priority()[1], 20);
EXPECT_EQ(samples.ts()[2], 68000);
EXPECT_EQ(samples.callsite_id()[2], CallsiteId{0});
EXPECT_EQ(samples.utid()[2], 1u);
+ EXPECT_EQ(samples.process_priority()[2], 30);
// Breakpad build_ids should not be modified/mangled.
ASSERT_STREQ(
diff --git a/src/trace_processor/tables/profiler_tables.h b/src/trace_processor/tables/profiler_tables.h
index 1720408..9c5b840 100644
--- a/src/trace_processor/tables/profiler_tables.h
+++ b/src/trace_processor/tables/profiler_tables.h
@@ -83,7 +83,8 @@
PERFETTO_TP_ROOT_TABLE(PARENT, C) \
C(int64_t, ts, Column::Flag::kSorted) \
C(StackProfileCallsiteTable::Id, callsite_id) \
- C(uint32_t, utid)
+ C(uint32_t, utid) \
+ C(int32_t, process_priority)
PERFETTO_TP_TABLE(PERFETTO_TP_CPU_PROFILE_STACK_SAMPLE_DEF);