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