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