Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_ |
| 19 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 20 | #include <array> |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 21 | #include <deque> |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 22 | #include <map> |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <unordered_map> |
| 25 | #include <vector> |
| 26 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 27 | #include "perfetto/base/logging.h" |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 28 | #include "perfetto/base/string_view.h" |
Hector Dearman | c833993 | 2018-08-10 11:22:46 +0100 | [diff] [blame] | 29 | #include "perfetto/base/utils.h" |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 30 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 31 | namespace perfetto { |
| 32 | namespace trace_processor { |
| 33 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 34 | // UniquePid is an offset into |unique_processes_|. This is necessary because |
| 35 | // Unix pids are reused and thus not guaranteed to be unique over a long |
| 36 | // period of time. |
| 37 | using UniquePid = uint32_t; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 38 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 39 | // UniqueTid is an offset into |unique_threads_|. Necessary because tids can |
| 40 | // be reused. |
| 41 | using UniqueTid = uint32_t; |
| 42 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 43 | // StringId is an offset into |string_pool_|. |
| 44 | using StringId = size_t; |
| 45 | |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 46 | enum RefType { |
| 47 | kNoRef = 0, |
| 48 | kUtid = 1, |
| 49 | kCpuId = 2, |
| 50 | kIrq = 3, |
| 51 | kSoftIrq = 4, |
Primiano Tucci | c9d4a8b | 2018-10-30 20:19:01 -0700 | [diff] [blame] | 52 | kUpid = 5, |
| 53 | kMax = kUpid + 1 |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 54 | }; |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 55 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 56 | // Stores a data inside a trace file in a columnar form. This makes it efficient |
| 57 | // to read or search across a single field of the trace (e.g. all the thread |
| 58 | // names for a given CPU). |
| 59 | class TraceStorage { |
| 60 | public: |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 61 | TraceStorage(); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 62 | TraceStorage(const TraceStorage&) = delete; |
| 63 | |
| 64 | virtual ~TraceStorage(); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 65 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 66 | struct Stats { |
| 67 | uint64_t mismatched_sched_switch_tids_ = 0; |
| 68 | }; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 69 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 70 | // Information about a unique process seen in a trace. |
| 71 | struct Process { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 72 | explicit Process(uint32_t p) : pid(p) {} |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 73 | uint64_t start_ns = 0; |
| 74 | uint64_t end_ns = 0; |
| 75 | StringId name_id = 0; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 76 | uint32_t pid = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | // Information about a unique thread seen in a trace. |
| 80 | struct Thread { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 81 | explicit Thread(uint32_t t) : tid(t) {} |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 82 | uint64_t start_ns = 0; |
| 83 | uint64_t end_ns = 0; |
| 84 | StringId name_id = 0; |
| 85 | UniquePid upid = 0; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 86 | uint32_t tid = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 87 | }; |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 88 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 89 | class Slices { |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 90 | public: |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 91 | inline size_t AddSlice(uint32_t cpu, |
| 92 | uint64_t start_ns, |
| 93 | uint64_t duration_ns, |
| 94 | UniqueTid utid) { |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 95 | cpus_.emplace_back(cpu); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 96 | start_ns_.emplace_back(start_ns); |
| 97 | durations_.emplace_back(duration_ns); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 98 | utids_.emplace_back(utid); |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 99 | return slice_count() - 1; |
| 100 | } |
| 101 | |
| 102 | void set_duration(size_t index, uint64_t duration_ns) { |
| 103 | durations_[index] = duration_ns; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 106 | size_t slice_count() const { return start_ns_.size(); } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 107 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 108 | const std::deque<uint32_t>& cpus() const { return cpus_; } |
| 109 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 110 | const std::deque<uint64_t>& start_ns() const { return start_ns_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 111 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 112 | const std::deque<uint64_t>& durations() const { return durations_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 113 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 114 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 115 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 116 | private: |
Hector Dearman | 947f12a | 2018-09-11 16:50:36 +0100 | [diff] [blame] | 117 | // Each deque below has the same number of entries (the number of slices |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 118 | // in the trace for the CPU). |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 119 | std::deque<uint32_t> cpus_; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 120 | std::deque<uint64_t> start_ns_; |
| 121 | std::deque<uint64_t> durations_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 122 | std::deque<UniqueTid> utids_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 123 | }; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 124 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 125 | class NestableSlices { |
| 126 | public: |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 127 | inline size_t AddSlice(uint64_t start_ns, |
| 128 | uint64_t duration_ns, |
| 129 | UniqueTid utid, |
| 130 | StringId cat, |
| 131 | StringId name, |
| 132 | uint8_t depth, |
| 133 | uint64_t stack_id, |
| 134 | uint64_t parent_stack_id) { |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 135 | start_ns_.emplace_back(start_ns); |
| 136 | durations_.emplace_back(duration_ns); |
| 137 | utids_.emplace_back(utid); |
| 138 | cats_.emplace_back(cat); |
| 139 | names_.emplace_back(name); |
| 140 | depths_.emplace_back(depth); |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 141 | stack_ids_.emplace_back(stack_id); |
| 142 | parent_stack_ids_.emplace_back(parent_stack_id); |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 143 | return slice_count() - 1; |
| 144 | } |
| 145 | |
| 146 | void set_duration(size_t index, uint64_t duration_ns) { |
| 147 | durations_[index] = duration_ns; |
| 148 | } |
| 149 | |
| 150 | void set_stack_id(size_t index, uint64_t stack_id) { |
| 151 | stack_ids_[index] = stack_id; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | size_t slice_count() const { return start_ns_.size(); } |
| 155 | const std::deque<uint64_t>& start_ns() const { return start_ns_; } |
| 156 | const std::deque<uint64_t>& durations() const { return durations_; } |
| 157 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 158 | const std::deque<StringId>& cats() const { return cats_; } |
| 159 | const std::deque<StringId>& names() const { return names_; } |
| 160 | const std::deque<uint8_t>& depths() const { return depths_; } |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 161 | const std::deque<uint64_t>& stack_ids() const { return stack_ids_; } |
| 162 | const std::deque<uint64_t>& parent_stack_ids() const { |
| 163 | return parent_stack_ids_; |
| 164 | } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 165 | |
| 166 | private: |
| 167 | std::deque<uint64_t> start_ns_; |
| 168 | std::deque<uint64_t> durations_; |
| 169 | std::deque<UniqueTid> utids_; |
| 170 | std::deque<StringId> cats_; |
| 171 | std::deque<StringId> names_; |
| 172 | std::deque<uint8_t> depths_; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 173 | std::deque<uint64_t> stack_ids_; |
| 174 | std::deque<uint64_t> parent_stack_ids_; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 175 | }; |
| 176 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 177 | class Counters { |
| 178 | public: |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 179 | inline size_t AddCounter(uint64_t timestamp, |
| 180 | uint64_t duration, |
| 181 | StringId name_id, |
| 182 | double value, |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 183 | int64_t ref, |
| 184 | RefType type) { |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 185 | timestamps_.emplace_back(timestamp); |
| 186 | durations_.emplace_back(duration); |
| 187 | name_ids_.emplace_back(name_id); |
| 188 | values_.emplace_back(value); |
| 189 | refs_.emplace_back(ref); |
| 190 | types_.emplace_back(type); |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 191 | return counter_count() - 1; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 192 | } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 193 | |
| 194 | void set_duration(size_t index, uint64_t duration) { |
| 195 | durations_[index] = duration; |
| 196 | } |
| 197 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 198 | size_t counter_count() const { return timestamps_.size(); } |
| 199 | |
| 200 | const std::deque<uint64_t>& timestamps() const { return timestamps_; } |
| 201 | |
| 202 | const std::deque<uint64_t>& durations() const { return durations_; } |
| 203 | |
| 204 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 205 | |
| 206 | const std::deque<double>& values() const { return values_; } |
| 207 | |
| 208 | const std::deque<int64_t>& refs() const { return refs_; } |
| 209 | |
| 210 | const std::deque<RefType>& types() const { return types_; } |
| 211 | |
| 212 | private: |
| 213 | std::deque<uint64_t> timestamps_; |
| 214 | std::deque<uint64_t> durations_; |
| 215 | std::deque<StringId> name_ids_; |
| 216 | std::deque<double> values_; |
| 217 | std::deque<int64_t> refs_; |
| 218 | std::deque<RefType> types_; |
| 219 | }; |
| 220 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 221 | class SqlStats { |
| 222 | public: |
| 223 | static constexpr size_t kMaxLogEntries = 100; |
| 224 | void RecordQueryBegin(const std::string& query, |
| 225 | uint64_t time_queued, |
| 226 | uint64_t time_started); |
| 227 | void RecordQueryEnd(uint64_t time_ended); |
| 228 | size_t size() const { return queries_.size(); } |
| 229 | const std::deque<std::string>& queries() const { return queries_; } |
| 230 | const std::deque<uint64_t>& times_queued() const { return times_queued_; } |
| 231 | const std::deque<uint64_t>& times_started() const { return times_started_; } |
| 232 | const std::deque<uint64_t>& times_ended() const { return times_ended_; } |
| 233 | |
| 234 | private: |
| 235 | std::deque<std::string> queries_; |
| 236 | std::deque<uint64_t> times_queued_; |
| 237 | std::deque<uint64_t> times_started_; |
| 238 | std::deque<uint64_t> times_ended_; |
| 239 | }; |
| 240 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 241 | class Instants { |
| 242 | public: |
| 243 | inline size_t AddInstantEvent(uint64_t timestamp, |
| 244 | StringId name_id, |
| 245 | double value, |
| 246 | int64_t ref, |
| 247 | RefType type) { |
| 248 | timestamps_.emplace_back(timestamp); |
| 249 | name_ids_.emplace_back(name_id); |
| 250 | values_.emplace_back(value); |
| 251 | refs_.emplace_back(ref); |
| 252 | types_.emplace_back(type); |
| 253 | return instant_count() - 1; |
| 254 | } |
| 255 | |
| 256 | size_t instant_count() const { return timestamps_.size(); } |
| 257 | |
| 258 | const std::deque<uint64_t>& timestamps() const { return timestamps_; } |
| 259 | |
| 260 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 261 | |
| 262 | const std::deque<double>& values() const { return values_; } |
| 263 | |
| 264 | const std::deque<int64_t>& refs() const { return refs_; } |
| 265 | |
| 266 | const std::deque<RefType>& types() const { return types_; } |
| 267 | |
| 268 | private: |
| 269 | std::deque<uint64_t> timestamps_; |
| 270 | std::deque<StringId> name_ids_; |
| 271 | std::deque<double> values_; |
| 272 | std::deque<int64_t> refs_; |
| 273 | std::deque<RefType> types_; |
| 274 | }; |
| 275 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 276 | void ResetStorage(); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 277 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 278 | UniqueTid AddEmptyThread(uint32_t tid) { |
| 279 | unique_threads_.emplace_back(tid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 280 | return static_cast<UniqueTid>(unique_threads_.size() - 1); |
| 281 | } |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 282 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 283 | UniquePid AddEmptyProcess(uint32_t pid) { |
| 284 | unique_processes_.emplace_back(pid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 285 | return static_cast<UniquePid>(unique_processes_.size() - 1); |
| 286 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 287 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 288 | // Return an unqiue identifier for the contents of each string. |
| 289 | // The string is copied internally and can be destroyed after this called. |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 290 | // Virtual for testing. |
| 291 | virtual StringId InternString(base::StringView); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 292 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 293 | Process* GetMutableProcess(UniquePid upid) { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 294 | PERFETTO_DCHECK(upid > 0 && upid < unique_processes_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 295 | return &unique_processes_[upid]; |
| 296 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 297 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 298 | Thread* GetMutableThread(UniqueTid utid) { |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 299 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 300 | return &unique_threads_[utid]; |
| 301 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 302 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 303 | // Reading methods. |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 304 | const std::string& GetString(StringId id) const { |
| 305 | PERFETTO_DCHECK(id < string_pool_.size()); |
| 306 | return string_pool_[id]; |
| 307 | } |
| 308 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 309 | const Process& GetProcess(UniquePid upid) const { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 310 | PERFETTO_DCHECK(upid > 0 && upid < unique_processes_.size()); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 311 | return unique_processes_[upid]; |
| 312 | } |
| 313 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 314 | const Thread& GetThread(UniqueTid utid) const { |
Lalit Maganti | 1f64cfa | 2018-09-18 13:20:02 +0100 | [diff] [blame] | 315 | // Allow utid == 0 for idle thread retrieval. |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 316 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 317 | return unique_threads_[utid]; |
| 318 | } |
| 319 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 320 | const Slices& slices() const { return slices_; } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 321 | Slices* mutable_slices() { return &slices_; } |
| 322 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 323 | const NestableSlices& nestable_slices() const { return nestable_slices_; } |
| 324 | NestableSlices* mutable_nestable_slices() { return &nestable_slices_; } |
| 325 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 326 | const Counters& counters() const { return counters_; } |
| 327 | Counters* mutable_counters() { return &counters_; } |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 328 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 329 | const SqlStats& sql_stats() const { return sql_stats_; } |
| 330 | SqlStats* mutable_sql_stats() { return &sql_stats_; } |
| 331 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 332 | const Instants& instants() const { return instants_; } |
| 333 | Instants* mutable_instants() { return &instants_; } |
| 334 | |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame^] | 335 | const Stats& stats() const { return stats_; } |
| 336 | Stats* mutable_stats() { return &stats_; } |
| 337 | |
Lalit Maganti | acda68b | 2018-10-29 15:23:25 +0000 | [diff] [blame] | 338 | const std::deque<std::string>& string_pool() const { return string_pool_; } |
| 339 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 340 | // |unique_processes_| always contains at least 1 element becuase the 0th ID |
| 341 | // is reserved to indicate an invalid process. |
| 342 | size_t process_count() const { return unique_processes_.size() - 1; } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 343 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 344 | // |unique_threads_| always contains at least 1 element becuase the 0th ID |
| 345 | // is reserved to indicate an invalid thread. |
| 346 | size_t thread_count() const { return unique_threads_.size() - 1; } |
| 347 | |
Hector Dearman | 1232336 | 2018-08-09 16:09:28 +0100 | [diff] [blame] | 348 | // Number of interned strings in the pool. Includes the empty string w/ ID=0. |
| 349 | size_t string_count() const { return string_pool_.size(); } |
| 350 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 351 | private: |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 352 | TraceStorage& operator=(const TraceStorage&) = default; |
| 353 | |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 354 | using StringHash = uint64_t; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 355 | |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame^] | 356 | // Stats about parsing the trace. |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 357 | Stats stats_; |
| 358 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 359 | // One entry for each CPU in the trace. |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 360 | Slices slices_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 361 | |
| 362 | // One entry for each unique string in the trace. |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 363 | std::deque<std::string> string_pool_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 364 | |
| 365 | // One entry for each unique string in the trace. |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 366 | std::unordered_map<StringHash, StringId> string_index_; |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 367 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 368 | // One entry for each UniquePid, with UniquePid as the index. |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 369 | std::deque<Process> unique_processes_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 370 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 371 | // One entry for each UniqueTid, with UniqueTid as the index. |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 372 | std::deque<Thread> unique_threads_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 373 | |
| 374 | // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros). |
| 375 | NestableSlices nestable_slices_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 376 | |
| 377 | // Counter events from the trace. This includes CPU frequency events as well |
| 378 | // systrace trace_marker counter events. |
| 379 | Counters counters_; |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 380 | |
| 381 | SqlStats sql_stats_; |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 382 | // These are instantaneous events in the trace. They have no duration |
| 383 | // and do not have a value that make sense to track over time. |
| 384 | // e.g. signal events |
| 385 | Instants instants_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | } // namespace trace_processor |
| 389 | } // namespace perfetto |
| 390 | |
| 391 | #endif // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_ |