processor: Add storage for thread_slices + TrackEvent tts support.
Adds storage for attributes of thread slices and parses thread
timestamps to ProtoTraceParser
Bug: 130786981
Change-Id: I6bbb4d76cd1704c434a9ec38e3aec82d49007b94
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
index 77be056..9241e2e 100644
--- a/src/trace_processor/trace_storage.h
+++ b/src/trace_processor/trace_storage.h
@@ -374,6 +374,70 @@
std::deque<ArgSetId> arg_set_ids_;
};
+ class ThreadSlices {
+ public:
+ inline uint32_t AddThreadSlice(uint32_t slice_id,
+ int64_t thread_timestamp_ns,
+ int64_t thread_duration_ns,
+ int64_t thread_instruction_count,
+ int64_t thread_instruction_delta) {
+ slice_ids_.emplace_back(slice_id);
+ thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
+ thread_duration_ns_.emplace_back(thread_duration_ns);
+ thread_instruction_counts_.emplace_back(thread_instruction_count);
+ thread_instruction_deltas_.emplace_back(thread_instruction_delta);
+ return slice_count() - 1;
+ }
+
+ void set_thread_duration_ns(uint32_t index, int64_t thread_duration_ns) {
+ thread_duration_ns_[index] = thread_duration_ns;
+ }
+
+ void set_thread_instruction_delta(uint32_t index,
+ int64_t thread_instruction_delta) {
+ thread_instruction_deltas_[index] = thread_instruction_delta;
+ }
+
+ uint32_t slice_count() const {
+ return static_cast<uint32_t>(slice_ids_.size());
+ }
+
+ const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
+ const std::deque<int64_t>& thread_timestamp_ns() const {
+ return thread_timestamp_ns_;
+ }
+ const std::deque<int64_t>& thread_duration_ns() const {
+ return thread_duration_ns_;
+ }
+ const std::deque<int64_t>& thread_instruction_counts() const {
+ return thread_instruction_counts_;
+ }
+ const std::deque<int64_t>& thread_instruction_deltas() const {
+ return thread_instruction_deltas_;
+ }
+
+ uint32_t FindRowForSliceId(uint32_t slice_id) const {
+ auto it =
+ std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
+ PERFETTO_DCHECK(it != slice_ids().end() && *it == slice_id);
+ return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
+ }
+
+ void UpdateThreadDurationForSliceId(uint32_t slice_id,
+ int64_t end_thread_timestamp_ns) {
+ uint32_t row = FindRowForSliceId(slice_id);
+ int64_t begin_ns = thread_timestamp_ns_[row];
+ thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
+ }
+
+ private:
+ std::deque<uint32_t> slice_ids_;
+ std::deque<int64_t> thread_timestamp_ns_;
+ std::deque<int64_t> thread_duration_ns_;
+ std::deque<int64_t> thread_instruction_counts_;
+ std::deque<int64_t> thread_instruction_deltas_;
+ };
+
class CounterDefinitions {
public:
using Id = uint32_t;
@@ -974,6 +1038,9 @@
const NestableSlices& nestable_slices() const { return nestable_slices_; }
NestableSlices* mutable_nestable_slices() { return &nestable_slices_; }
+ const ThreadSlices& thread_slices() const { return thread_slices_; }
+ ThreadSlices* mutable_thread_slices() { return &thread_slices_; }
+
const CounterDefinitions& counter_definitions() const {
return counter_definitions_;
}
@@ -1091,6 +1158,9 @@
// Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros).
NestableSlices nestable_slices_;
+ // Additional attributes for threads slices (sub-type of NestableSlices).
+ ThreadSlices thread_slices_;
+
// The type of counters in the trace. Can be thought of as the "metadata".
CounterDefinitions counter_definitions_;