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