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> |
Ioannis Ilkos | b8b1110 | 2019-01-29 17:56:55 +0000 | [diff] [blame] | 25 | #include <utility> |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 26 | #include <vector> |
| 27 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 28 | #include "perfetto/base/logging.h" |
Lalit Maganti | 770886a | 2018-11-16 17:40:21 +0000 | [diff] [blame] | 29 | #include "perfetto/base/optional.h" |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 30 | #include "perfetto/base/string_view.h" |
Hector Dearman | c833993 | 2018-08-10 11:22:46 +0100 | [diff] [blame] | 31 | #include "perfetto/base/utils.h" |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 32 | #include "src/trace_processor/ftrace_utils.h" |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 33 | #include "src/trace_processor/stats.h" |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 34 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 35 | namespace perfetto { |
| 36 | namespace trace_processor { |
| 37 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 38 | // UniquePid is an offset into |unique_processes_|. This is necessary because |
| 39 | // Unix pids are reused and thus not guaranteed to be unique over a long |
| 40 | // period of time. |
| 41 | using UniquePid = uint32_t; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 42 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 43 | // UniqueTid is an offset into |unique_threads_|. Necessary because tids can |
| 44 | // be reused. |
| 45 | using UniqueTid = uint32_t; |
| 46 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 47 | // StringId is an offset into |string_pool_|. |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 48 | using StringId = uint32_t; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 49 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 50 | // Identifiers for all the tables in the database. |
| 51 | enum TableId : uint8_t { |
| 52 | // Intentionally don't have TableId == 0 so that RowId == 0 can refer to an |
| 53 | // invalid row id. |
| 54 | kCounters = 1, |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 55 | kRawEvents = 2, |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 56 | kInstants = 3, |
Isabelle Taylor | b9222c3 | 2019-01-31 10:58:37 +0000 | [diff] [blame] | 57 | kSched = 4, |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | // The top 8 bits are set to the TableId and the bottom 32 to the row of the |
| 61 | // table. |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 62 | using RowId = int64_t; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 63 | static const RowId kInvalidRowId = 0; |
| 64 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 65 | using ArgSetId = uint32_t; |
| 66 | static const ArgSetId kInvalidArgSetId = 0; |
| 67 | |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 68 | enum RefType { |
Primiano Tucci | 5403e4f | 2018-11-27 10:07:03 +0000 | [diff] [blame] | 69 | kRefNoRef = 0, |
| 70 | kRefUtid = 1, |
| 71 | kRefCpuId = 2, |
| 72 | kRefIrq = 3, |
| 73 | kRefSoftIrq = 4, |
| 74 | kRefUpid = 5, |
| 75 | kRefUtidLookupUpid = 6, |
| 76 | kRefMax |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 77 | }; |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 78 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 79 | // Stores a data inside a trace file in a columnar form. This makes it efficient |
| 80 | // to read or search across a single field of the trace (e.g. all the thread |
| 81 | // names for a given CPU). |
| 82 | class TraceStorage { |
| 83 | public: |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 84 | TraceStorage(); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 85 | TraceStorage(const TraceStorage&) = delete; |
| 86 | |
| 87 | virtual ~TraceStorage(); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 88 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 89 | // Information about a unique process seen in a trace. |
| 90 | struct Process { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 91 | explicit Process(uint32_t p) : pid(p) {} |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 92 | int64_t start_ns = 0; |
| 93 | int64_t end_ns = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 94 | StringId name_id = 0; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 95 | uint32_t pid = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | // Information about a unique thread seen in a trace. |
| 99 | struct Thread { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 100 | explicit Thread(uint32_t t) : tid(t) {} |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 101 | int64_t start_ns = 0; |
| 102 | int64_t end_ns = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 103 | StringId name_id = 0; |
Lalit Maganti | 770886a | 2018-11-16 17:40:21 +0000 | [diff] [blame] | 104 | base::Optional<UniquePid> upid; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 105 | uint32_t tid = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 106 | }; |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 107 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 108 | // Generic key value storage which can be referenced by other tables. |
| 109 | class Args { |
| 110 | public: |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 111 | // Variadic type representing the possible values for the args table. |
| 112 | struct Variadic { |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 113 | enum Type { kInt, kString, kReal }; |
| 114 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 115 | static Variadic Integer(int64_t int_value) { |
| 116 | Variadic variadic; |
| 117 | variadic.type = Type::kInt; |
| 118 | variadic.int_value = int_value; |
| 119 | return variadic; |
| 120 | } |
| 121 | |
| 122 | static Variadic String(StringId string_id) { |
| 123 | Variadic variadic; |
| 124 | variadic.type = Type::kString; |
| 125 | variadic.string_value = string_id; |
| 126 | return variadic; |
| 127 | } |
| 128 | |
| 129 | static Variadic Real(double real_value) { |
| 130 | Variadic variadic; |
| 131 | variadic.type = Type::kReal; |
| 132 | variadic.real_value = real_value; |
| 133 | return variadic; |
| 134 | } |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 135 | |
| 136 | Type type; |
| 137 | union { |
| 138 | int64_t int_value; |
| 139 | StringId string_value; |
| 140 | double real_value; |
| 141 | }; |
| 142 | }; |
| 143 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 144 | struct Arg { |
| 145 | StringId flat_key = 0; |
| 146 | StringId key = 0; |
| 147 | Variadic value = Variadic::Integer(0); |
| 148 | |
| 149 | // This is only used by the arg tracker and so is not part of the hash. |
| 150 | RowId row_id = 0; |
| 151 | }; |
| 152 | |
| 153 | struct ArgHasher { |
| 154 | uint64_t operator()(const Arg& arg) const noexcept { |
| 155 | uint64_t hash = kFnv1a64OffsetBasis; |
| 156 | hash ^= static_cast<decltype(hash)>(arg.key); |
| 157 | hash *= 1099511628211; // FNV-1a-64 prime. |
| 158 | // We don't hash arg.flat_key because it's a subsequence of arg.key. |
| 159 | switch (arg.value.type) { |
| 160 | case Variadic::Type::kInt: |
| 161 | hash ^= static_cast<uint64_t>(arg.value.int_value); |
| 162 | break; |
| 163 | case Variadic::Type::kString: |
| 164 | hash ^= static_cast<uint64_t>(arg.value.string_value); |
| 165 | break; |
| 166 | case Variadic::Type::kReal: |
| 167 | hash ^= static_cast<uint64_t>(arg.value.real_value); |
| 168 | break; |
| 169 | } |
| 170 | hash *= kFnv1a64Prime; |
| 171 | return hash; |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | const std::deque<ArgSetId>& set_ids() const { return set_ids_; } |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 176 | const std::deque<StringId>& flat_keys() const { return flat_keys_; } |
| 177 | const std::deque<StringId>& keys() const { return keys_; } |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 178 | const std::deque<Variadic>& arg_values() const { return arg_values_; } |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 179 | uint32_t args_count() const { |
| 180 | return static_cast<uint32_t>(set_ids_.size()); |
Lalit Maganti | 79472be | 2018-12-04 13:41:27 +0000 | [diff] [blame] | 181 | } |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 182 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 183 | ArgSetId AddArgSet(const std::vector<Arg>& args, |
| 184 | uint32_t begin, |
| 185 | uint32_t end) { |
| 186 | ArgSetHash hash = kFnv1a64OffsetBasis; |
| 187 | for (uint32_t i = begin; i < end; i++) { |
| 188 | hash ^= ArgHasher()(args[i]); |
| 189 | hash *= kFnv1a64Prime; |
| 190 | } |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 191 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 192 | auto it = arg_row_for_hash_.find(hash); |
| 193 | if (it != arg_row_for_hash_.end()) { |
| 194 | return set_ids_[it->second]; |
| 195 | } |
| 196 | |
| 197 | // The +1 ensures that nothing has an id == kInvalidArgSetId == 0. |
| 198 | ArgSetId id = static_cast<uint32_t>(arg_row_for_hash_.size()) + 1; |
| 199 | arg_row_for_hash_.emplace(hash, args_count()); |
| 200 | for (uint32_t i = begin; i < end; i++) { |
| 201 | const auto& arg = args[i]; |
| 202 | set_ids_.emplace_back(id); |
| 203 | flat_keys_.emplace_back(arg.flat_key); |
| 204 | keys_.emplace_back(arg.key); |
| 205 | arg_values_.emplace_back(arg.value); |
| 206 | } |
| 207 | return id; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 210 | private: |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 211 | using ArgSetHash = uint64_t; |
| 212 | |
| 213 | static constexpr uint64_t kFnv1a64OffsetBasis = 0xcbf29ce484222325; |
| 214 | static constexpr uint64_t kFnv1a64Prime = 0xcbf29ce484222325; |
| 215 | |
| 216 | std::deque<ArgSetId> set_ids_; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 217 | std::deque<StringId> flat_keys_; |
| 218 | std::deque<StringId> keys_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 219 | std::deque<Variadic> arg_values_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 220 | |
| 221 | std::unordered_map<ArgSetHash, uint32_t> arg_row_for_hash_; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 224 | class Slices { |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 225 | public: |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 226 | inline size_t AddSlice(uint32_t cpu, |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 227 | int64_t start_ns, |
| 228 | int64_t duration_ns, |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 229 | UniqueTid utid, |
| 230 | ftrace_utils::TaskState end_state, |
| 231 | int32_t priority) { |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 232 | cpus_.emplace_back(cpu); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 233 | start_ns_.emplace_back(start_ns); |
| 234 | durations_.emplace_back(duration_ns); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 235 | utids_.emplace_back(utid); |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 236 | end_states_.emplace_back(end_state); |
| 237 | priorities_.emplace_back(priority); |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 238 | |
| 239 | if (utid >= rows_for_utids_.size()) |
| 240 | rows_for_utids_.resize(utid + 1); |
| 241 | rows_for_utids_[utid].emplace_back(slice_count() - 1); |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 242 | return slice_count() - 1; |
| 243 | } |
| 244 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 245 | void set_duration(size_t index, int64_t duration_ns) { |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 246 | durations_[index] = duration_ns; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 247 | } |
| 248 | |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 249 | void set_end_state(size_t index, ftrace_utils::TaskState end_state) { |
| 250 | end_states_[index] = end_state; |
| 251 | } |
| 252 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 253 | size_t slice_count() const { return start_ns_.size(); } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 254 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 255 | const std::deque<uint32_t>& cpus() const { return cpus_; } |
| 256 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 257 | const std::deque<int64_t>& start_ns() const { return start_ns_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 258 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 259 | const std::deque<int64_t>& durations() const { return durations_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 260 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 261 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 262 | |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 263 | const std::deque<ftrace_utils::TaskState>& end_state() const { |
| 264 | return end_states_; |
| 265 | } |
| 266 | |
| 267 | const std::deque<int32_t>& priorities() const { return priorities_; } |
| 268 | |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 269 | const std::deque<std::vector<uint32_t>>& rows_for_utids() const { |
Lalit Maganti | f0f09c3 | 2019-01-18 17:29:31 +0000 | [diff] [blame] | 270 | return rows_for_utids_; |
| 271 | } |
| 272 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 273 | private: |
Hector Dearman | 947f12a | 2018-09-11 16:50:36 +0100 | [diff] [blame] | 274 | // 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] | 275 | // in the trace for the CPU). |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 276 | std::deque<uint32_t> cpus_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 277 | std::deque<int64_t> start_ns_; |
| 278 | std::deque<int64_t> durations_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 279 | std::deque<UniqueTid> utids_; |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 280 | std::deque<ftrace_utils::TaskState> end_states_; |
| 281 | std::deque<int32_t> priorities_; |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 282 | |
| 283 | // One row per utid. |
| 284 | std::deque<std::vector<uint32_t>> rows_for_utids_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 285 | }; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 286 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 287 | class NestableSlices { |
| 288 | public: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 289 | inline size_t AddSlice(int64_t start_ns, |
| 290 | int64_t duration_ns, |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 291 | UniqueTid utid, |
| 292 | StringId cat, |
| 293 | StringId name, |
| 294 | uint8_t depth, |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 295 | int64_t stack_id, |
| 296 | int64_t parent_stack_id) { |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 297 | start_ns_.emplace_back(start_ns); |
| 298 | durations_.emplace_back(duration_ns); |
| 299 | utids_.emplace_back(utid); |
| 300 | cats_.emplace_back(cat); |
| 301 | names_.emplace_back(name); |
| 302 | depths_.emplace_back(depth); |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 303 | stack_ids_.emplace_back(stack_id); |
| 304 | parent_stack_ids_.emplace_back(parent_stack_id); |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 305 | return slice_count() - 1; |
| 306 | } |
| 307 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 308 | void set_duration(size_t index, int64_t duration_ns) { |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 309 | durations_[index] = duration_ns; |
| 310 | } |
| 311 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 312 | void set_stack_id(size_t index, int64_t stack_id) { |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 313 | stack_ids_[index] = stack_id; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | size_t slice_count() const { return start_ns_.size(); } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 317 | const std::deque<int64_t>& start_ns() const { return start_ns_; } |
| 318 | const std::deque<int64_t>& durations() const { return durations_; } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 319 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 320 | const std::deque<StringId>& cats() const { return cats_; } |
| 321 | const std::deque<StringId>& names() const { return names_; } |
| 322 | const std::deque<uint8_t>& depths() const { return depths_; } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 323 | const std::deque<int64_t>& stack_ids() const { return stack_ids_; } |
| 324 | const std::deque<int64_t>& parent_stack_ids() const { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 325 | return parent_stack_ids_; |
| 326 | } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 327 | |
| 328 | private: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 329 | std::deque<int64_t> start_ns_; |
| 330 | std::deque<int64_t> durations_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 331 | std::deque<UniqueTid> utids_; |
| 332 | std::deque<StringId> cats_; |
| 333 | std::deque<StringId> names_; |
| 334 | std::deque<uint8_t> depths_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 335 | std::deque<int64_t> stack_ids_; |
| 336 | std::deque<int64_t> parent_stack_ids_; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 337 | }; |
| 338 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 339 | class Counters { |
| 340 | public: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 341 | inline size_t AddCounter(int64_t timestamp, |
| 342 | int64_t duration, |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 343 | StringId name_id, |
| 344 | double value, |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 345 | int64_t ref, |
| 346 | RefType type) { |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 347 | timestamps_.emplace_back(timestamp); |
| 348 | durations_.emplace_back(duration); |
| 349 | name_ids_.emplace_back(name_id); |
| 350 | values_.emplace_back(value); |
| 351 | refs_.emplace_back(ref); |
| 352 | types_.emplace_back(type); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 353 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 354 | return counter_count() - 1; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 355 | } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 356 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 357 | void set_duration(size_t index, int64_t duration) { |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 358 | durations_[index] = duration; |
| 359 | } |
| 360 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 361 | void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; } |
| 362 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 363 | size_t counter_count() const { return timestamps_.size(); } |
| 364 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 365 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 366 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 367 | const std::deque<int64_t>& durations() const { return durations_; } |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 368 | |
| 369 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 370 | |
| 371 | const std::deque<double>& values() const { return values_; } |
| 372 | |
| 373 | const std::deque<int64_t>& refs() const { return refs_; } |
| 374 | |
| 375 | const std::deque<RefType>& types() const { return types_; } |
| 376 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 377 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
| 378 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 379 | private: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 380 | std::deque<int64_t> timestamps_; |
| 381 | std::deque<int64_t> durations_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 382 | std::deque<StringId> name_ids_; |
| 383 | std::deque<double> values_; |
| 384 | std::deque<int64_t> refs_; |
| 385 | std::deque<RefType> types_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 386 | std::deque<ArgSetId> arg_set_ids_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 387 | }; |
| 388 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 389 | class SqlStats { |
| 390 | public: |
| 391 | static constexpr size_t kMaxLogEntries = 100; |
| 392 | void RecordQueryBegin(const std::string& query, |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 393 | int64_t time_queued, |
| 394 | int64_t time_started); |
| 395 | void RecordQueryEnd(int64_t time_ended); |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 396 | size_t size() const { return queries_.size(); } |
| 397 | const std::deque<std::string>& queries() const { return queries_; } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 398 | const std::deque<int64_t>& times_queued() const { return times_queued_; } |
| 399 | const std::deque<int64_t>& times_started() const { return times_started_; } |
| 400 | const std::deque<int64_t>& times_ended() const { return times_ended_; } |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 401 | |
| 402 | private: |
| 403 | std::deque<std::string> queries_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 404 | std::deque<int64_t> times_queued_; |
| 405 | std::deque<int64_t> times_started_; |
| 406 | std::deque<int64_t> times_ended_; |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 409 | class Instants { |
| 410 | public: |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 411 | inline uint32_t AddInstantEvent(int64_t timestamp, |
| 412 | StringId name_id, |
| 413 | double value, |
| 414 | int64_t ref, |
| 415 | RefType type) { |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 416 | timestamps_.emplace_back(timestamp); |
| 417 | name_ids_.emplace_back(name_id); |
| 418 | values_.emplace_back(value); |
| 419 | refs_.emplace_back(ref); |
| 420 | types_.emplace_back(type); |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 421 | return static_cast<uint32_t>(instant_count() - 1); |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | size_t instant_count() const { return timestamps_.size(); } |
| 425 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 426 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 427 | |
| 428 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 429 | |
| 430 | const std::deque<double>& values() const { return values_; } |
| 431 | |
| 432 | const std::deque<int64_t>& refs() const { return refs_; } |
| 433 | |
| 434 | const std::deque<RefType>& types() const { return types_; } |
| 435 | |
| 436 | private: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 437 | std::deque<int64_t> timestamps_; |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 438 | std::deque<StringId> name_ids_; |
| 439 | std::deque<double> values_; |
| 440 | std::deque<int64_t> refs_; |
| 441 | std::deque<RefType> types_; |
| 442 | }; |
| 443 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 444 | class RawEvents { |
| 445 | public: |
| 446 | inline RowId AddRawEvent(int64_t timestamp, |
| 447 | StringId name_id, |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 448 | uint32_t cpu, |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 449 | UniqueTid utid) { |
| 450 | timestamps_.emplace_back(timestamp); |
| 451 | name_ids_.emplace_back(name_id); |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 452 | cpus_.emplace_back(cpu); |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 453 | utids_.emplace_back(utid); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 454 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 455 | return CreateRowId(TableId::kRawEvents, |
| 456 | static_cast<uint32_t>(raw_event_count() - 1)); |
| 457 | } |
| 458 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 459 | void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; } |
| 460 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 461 | size_t raw_event_count() const { return timestamps_.size(); } |
| 462 | |
| 463 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
| 464 | |
| 465 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 466 | |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 467 | const std::deque<uint32_t>& cpus() const { return cpus_; } |
| 468 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 469 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 470 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 471 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
| 472 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 473 | private: |
| 474 | std::deque<int64_t> timestamps_; |
| 475 | std::deque<StringId> name_ids_; |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 476 | std::deque<uint32_t> cpus_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 477 | std::deque<UniqueTid> utids_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 478 | std::deque<ArgSetId> arg_set_ids_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 481 | class AndroidLogs { |
| 482 | public: |
| 483 | inline size_t AddLogEvent(int64_t timestamp, |
| 484 | UniqueTid utid, |
| 485 | uint8_t prio, |
| 486 | StringId tag_id, |
| 487 | StringId msg_id) { |
| 488 | timestamps_.emplace_back(timestamp); |
| 489 | utids_.emplace_back(utid); |
| 490 | prios_.emplace_back(prio); |
| 491 | tag_ids_.emplace_back(tag_id); |
| 492 | msg_ids_.emplace_back(msg_id); |
| 493 | return size() - 1; |
| 494 | } |
| 495 | |
| 496 | size_t size() const { return timestamps_.size(); } |
| 497 | |
| 498 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
| 499 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 500 | const std::deque<uint8_t>& prios() const { return prios_; } |
| 501 | const std::deque<StringId>& tag_ids() const { return tag_ids_; } |
| 502 | const std::deque<StringId>& msg_ids() const { return msg_ids_; } |
| 503 | |
| 504 | private: |
| 505 | std::deque<int64_t> timestamps_; |
| 506 | std::deque<UniqueTid> utids_; |
| 507 | std::deque<uint8_t> prios_; |
| 508 | std::deque<StringId> tag_ids_; |
| 509 | std::deque<StringId> msg_ids_; |
| 510 | }; |
| 511 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 512 | struct Stats { |
| 513 | using IndexMap = std::map<int, int64_t>; |
| 514 | int64_t value = 0; |
| 515 | IndexMap indexed_values; |
| 516 | }; |
| 517 | using StatsMap = std::array<Stats, stats::kNumKeys>; |
| 518 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 519 | void ResetStorage(); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 520 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 521 | UniqueTid AddEmptyThread(uint32_t tid) { |
| 522 | unique_threads_.emplace_back(tid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 523 | return static_cast<UniqueTid>(unique_threads_.size() - 1); |
| 524 | } |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 525 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 526 | UniquePid AddEmptyProcess(uint32_t pid) { |
| 527 | unique_processes_.emplace_back(pid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 528 | return static_cast<UniquePid>(unique_processes_.size() - 1); |
| 529 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 530 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 531 | // Return an unqiue identifier for the contents of each string. |
| 532 | // The string is copied internally and can be destroyed after this called. |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 533 | // Virtual for testing. |
| 534 | virtual StringId InternString(base::StringView); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 535 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 536 | Process* GetMutableProcess(UniquePid upid) { |
Lalit Maganti | 676658b | 2018-11-20 18:24:31 +0000 | [diff] [blame] | 537 | PERFETTO_DCHECK(upid < unique_processes_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 538 | return &unique_processes_[upid]; |
| 539 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 540 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 541 | Thread* GetMutableThread(UniqueTid utid) { |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 542 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 543 | return &unique_threads_[utid]; |
| 544 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 545 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 546 | // Example usage: SetStats(stats::android_log_num_failed, 42); |
| 547 | void SetStats(size_t key, int64_t value) { |
| 548 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 549 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle); |
| 550 | stats_[key].value = value; |
| 551 | } |
| 552 | |
| 553 | // Example usage: IncrementStats(stats::android_log_num_failed, -1); |
| 554 | void IncrementStats(size_t key, int64_t increment = 1) { |
| 555 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 556 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle); |
| 557 | stats_[key].value += increment; |
| 558 | } |
| 559 | |
| 560 | // Example usage: SetIndexedStats(stats::cpu_failure, 1, 42); |
| 561 | void SetIndexedStats(size_t key, int index, int64_t value) { |
| 562 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 563 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed); |
| 564 | stats_[key].indexed_values[index] = value; |
| 565 | } |
| 566 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 567 | // Reading methods. |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 568 | const std::string& GetString(StringId id) const { |
| 569 | PERFETTO_DCHECK(id < string_pool_.size()); |
| 570 | return string_pool_[id]; |
| 571 | } |
| 572 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 573 | const Process& GetProcess(UniquePid upid) const { |
Lalit Maganti | 676658b | 2018-11-20 18:24:31 +0000 | [diff] [blame] | 574 | PERFETTO_DCHECK(upid < unique_processes_.size()); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 575 | return unique_processes_[upid]; |
| 576 | } |
| 577 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 578 | const Thread& GetThread(UniqueTid utid) const { |
Lalit Maganti | 1f64cfa | 2018-09-18 13:20:02 +0100 | [diff] [blame] | 579 | // Allow utid == 0 for idle thread retrieval. |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 580 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 581 | return unique_threads_[utid]; |
| 582 | } |
| 583 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 584 | static RowId CreateRowId(TableId table, uint32_t row) { |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 585 | return (static_cast<RowId>(table) << kRowIdTableShift) | row; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 588 | static std::pair<int8_t /*table*/, uint32_t /*row*/> ParseRowId(RowId rowid) { |
| 589 | auto id = static_cast<uint64_t>(rowid); |
| 590 | auto table_id = static_cast<uint8_t>(id >> kRowIdTableShift); |
| 591 | auto row = static_cast<uint32_t>(id & ((1ull << kRowIdTableShift) - 1)); |
| 592 | return std::make_pair(table_id, row); |
| 593 | } |
| 594 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 595 | const Slices& slices() const { return slices_; } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 596 | Slices* mutable_slices() { return &slices_; } |
| 597 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 598 | const NestableSlices& nestable_slices() const { return nestable_slices_; } |
| 599 | NestableSlices* mutable_nestable_slices() { return &nestable_slices_; } |
| 600 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 601 | const Counters& counters() const { return counters_; } |
| 602 | Counters* mutable_counters() { return &counters_; } |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 603 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 604 | const SqlStats& sql_stats() const { return sql_stats_; } |
| 605 | SqlStats* mutable_sql_stats() { return &sql_stats_; } |
| 606 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 607 | const Instants& instants() const { return instants_; } |
| 608 | Instants* mutable_instants() { return &instants_; } |
| 609 | |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 610 | const AndroidLogs& android_logs() const { return android_log_; } |
| 611 | AndroidLogs* mutable_android_log() { return &android_log_; } |
| 612 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 613 | const StatsMap& stats() const { return stats_; } |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame] | 614 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 615 | const Args& args() const { return args_; } |
| 616 | Args* mutable_args() { return &args_; } |
| 617 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 618 | const RawEvents& raw_events() const { return raw_events_; } |
| 619 | RawEvents* mutable_raw_events() { return &raw_events_; } |
| 620 | |
Lalit Maganti | acda68b | 2018-10-29 15:23:25 +0000 | [diff] [blame] | 621 | const std::deque<std::string>& string_pool() const { return string_pool_; } |
| 622 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 623 | // |unique_processes_| always contains at least 1 element becuase the 0th ID |
| 624 | // is reserved to indicate an invalid process. |
Lalit Maganti | 9c6395b | 2019-01-17 00:25:09 +0000 | [diff] [blame] | 625 | size_t process_count() const { return unique_processes_.size(); } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 626 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 627 | // |unique_threads_| always contains at least 1 element becuase the 0th ID |
| 628 | // is reserved to indicate an invalid thread. |
Lalit Maganti | 9c6395b | 2019-01-17 00:25:09 +0000 | [diff] [blame] | 629 | size_t thread_count() const { return unique_threads_.size(); } |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 630 | |
Hector Dearman | 1232336 | 2018-08-09 16:09:28 +0100 | [diff] [blame] | 631 | // Number of interned strings in the pool. Includes the empty string w/ ID=0. |
| 632 | size_t string_count() const { return string_pool_.size(); } |
| 633 | |
Ioannis Ilkos | b8b1110 | 2019-01-29 17:56:55 +0000 | [diff] [blame] | 634 | // Start / end ts (in nanoseconds) across the parsed trace events. |
| 635 | // Returns (0, 0) if the trace is empty. |
| 636 | std::pair<int64_t, int64_t> GetTraceTimestampBoundsNs() const; |
| 637 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 638 | private: |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 639 | static constexpr uint8_t kRowIdTableShift = 32; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 640 | |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 641 | using StringHash = uint64_t; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 642 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame^] | 643 | TraceStorage& operator=(const TraceStorage&) = default; |
| 644 | |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame] | 645 | // Stats about parsing the trace. |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 646 | StatsMap stats_{}; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 647 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 648 | // One entry for each CPU in the trace. |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 649 | Slices slices_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 650 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 651 | // Args for all other tables. |
| 652 | Args args_; |
| 653 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 654 | // One entry for each unique string in the trace. |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 655 | std::deque<std::string> string_pool_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 656 | |
| 657 | // One entry for each unique string in the trace. |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 658 | std::unordered_map<StringHash, StringId> string_index_; |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 659 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 660 | // One entry for each UniquePid, with UniquePid as the index. |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 661 | std::deque<Process> unique_processes_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 662 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 663 | // One entry for each UniqueTid, with UniqueTid as the index. |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 664 | std::deque<Thread> unique_threads_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 665 | |
| 666 | // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros). |
| 667 | NestableSlices nestable_slices_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 668 | |
| 669 | // Counter events from the trace. This includes CPU frequency events as well |
| 670 | // systrace trace_marker counter events. |
| 671 | Counters counters_; |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 672 | |
| 673 | SqlStats sql_stats_; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 674 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 675 | // These are instantaneous events in the trace. They have no duration |
| 676 | // and do not have a value that make sense to track over time. |
| 677 | // e.g. signal events |
| 678 | Instants instants_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 679 | |
| 680 | // Raw events are every ftrace event in the trace. The raw event includes |
| 681 | // the timestamp and the pid. The args for the raw event will be in the |
| 682 | // args table. This table can be used to generate a text version of the |
| 683 | // trace. |
| 684 | RawEvents raw_events_; |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 685 | AndroidLogs android_log_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | } // namespace trace_processor |
| 689 | } // namespace perfetto |
| 690 | |
| 691 | #endif // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_ |