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" |
Primiano Tucci | 2c5488f | 2019-06-01 03:27:28 +0100 | [diff] [blame] | 29 | #include "perfetto/ext/base/hash.h" |
| 30 | #include "perfetto/ext/base/optional.h" |
| 31 | #include "perfetto/ext/base/string_view.h" |
| 32 | #include "perfetto/ext/base/time.h" |
| 33 | #include "perfetto/ext/base/utils.h" |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 34 | #include "src/trace_processor/ftrace_utils.h" |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 35 | #include "src/trace_processor/metadata.h" |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 36 | #include "src/trace_processor/stats.h" |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 37 | #include "src/trace_processor/string_pool.h" |
Mikhail Khokhlov | 85a0dd0 | 2019-05-17 14:22:28 +0100 | [diff] [blame] | 38 | #include "src/trace_processor/variadic.h" |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 39 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 40 | namespace perfetto { |
| 41 | namespace trace_processor { |
| 42 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 43 | // UniquePid is an offset into |unique_processes_|. This is necessary because |
| 44 | // Unix pids are reused and thus not guaranteed to be unique over a long |
| 45 | // period of time. |
| 46 | using UniquePid = uint32_t; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 47 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 48 | // UniqueTid is an offset into |unique_threads_|. Necessary because tids can |
| 49 | // be reused. |
| 50 | using UniqueTid = uint32_t; |
| 51 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 52 | // StringId is an offset into |string_pool_|. |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 53 | using StringId = StringPool::Id; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 54 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 55 | // Identifiers for all the tables in the database. |
| 56 | enum TableId : uint8_t { |
| 57 | // Intentionally don't have TableId == 0 so that RowId == 0 can refer to an |
| 58 | // invalid row id. |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 59 | kCounterValues = 1, |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 60 | kRawEvents = 2, |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 61 | kInstants = 3, |
Isabelle Taylor | b9222c3 | 2019-01-31 10:58:37 +0000 | [diff] [blame] | 62 | kSched = 4, |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 63 | kNestableSlices = 5, |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 64 | kMetadataTable = 6, |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | // The top 8 bits are set to the TableId and the bottom 32 to the row of the |
| 68 | // table. |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 69 | using RowId = int64_t; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 70 | static const RowId kInvalidRowId = 0; |
| 71 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 72 | using ArgSetId = uint32_t; |
| 73 | static const ArgSetId kInvalidArgSetId = 0; |
| 74 | |
Eric Seckler | 5703ede | 2019-07-10 10:13:02 +0100 | [diff] [blame] | 75 | using TrackId = uint32_t; |
| 76 | |
| 77 | enum class VirtualTrackScope : uint8_t { |
| 78 | // VirtualTrack with global scope, will not have a |upid| set. |
| 79 | kGlobal = 0, |
| 80 | // VirtualTrack associated with a specific process via |upid|. |
| 81 | kProcess = 1 |
| 82 | }; |
| 83 | |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 84 | enum RefType { |
Primiano Tucci | 5403e4f | 2018-11-27 10:07:03 +0000 | [diff] [blame] | 85 | kRefNoRef = 0, |
| 86 | kRefUtid = 1, |
| 87 | kRefCpuId = 2, |
| 88 | kRefIrq = 3, |
| 89 | kRefSoftIrq = 4, |
| 90 | kRefUpid = 5, |
Sidath Senanayake | 1f5f93a | 2019-06-06 22:24:15 +0100 | [diff] [blame] | 91 | kRefGpuId = 6, |
Eric Seckler | 5703ede | 2019-07-10 10:13:02 +0100 | [diff] [blame] | 92 | kRefTrack = 7, |
Primiano Tucci | 5403e4f | 2018-11-27 10:07:03 +0000 | [diff] [blame] | 93 | kRefMax |
Isabelle Taylor | a97c5f5 | 2018-10-23 17:36:12 +0100 | [diff] [blame] | 94 | }; |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 95 | |
Eric Seckler | 972225e | 2019-04-18 11:07:12 +0100 | [diff] [blame] | 96 | const std::vector<const char*>& GetRefTypeStringMap(); |
| 97 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 98 | // Stores a data inside a trace file in a columnar form. This makes it efficient |
| 99 | // to read or search across a single field of the trace (e.g. all the thread |
| 100 | // names for a given CPU). |
| 101 | class TraceStorage { |
| 102 | public: |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 103 | TraceStorage(); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 104 | |
| 105 | virtual ~TraceStorage(); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 106 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 107 | // Information about a unique process seen in a trace. |
| 108 | struct Process { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 109 | explicit Process(uint32_t p) : pid(p) {} |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 110 | int64_t start_ns = 0; |
Lalit Maganti | 637589a | 2019-07-04 17:25:29 +0100 | [diff] [blame] | 111 | int64_t end_ns = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 112 | StringId name_id = 0; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 113 | uint32_t pid = 0; |
Lalit Maganti | 369b057 | 2019-07-11 15:35:09 +0100 | [diff] [blame] | 114 | base::Optional<UniquePid> parent_upid; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | // Information about a unique thread seen in a trace. |
| 118 | struct Thread { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 119 | explicit Thread(uint32_t t) : tid(t) {} |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 120 | int64_t start_ns = 0; |
Lalit Maganti | b5bd233 | 2019-06-06 14:20:47 +0100 | [diff] [blame] | 121 | int64_t end_ns = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 122 | StringId name_id = 0; |
Lalit Maganti | 770886a | 2018-11-16 17:40:21 +0000 | [diff] [blame] | 123 | base::Optional<UniquePid> upid; |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 124 | uint32_t tid = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 125 | }; |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 126 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 127 | // Generic key value storage which can be referenced by other tables. |
| 128 | class Args { |
| 129 | public: |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 130 | struct Arg { |
| 131 | StringId flat_key = 0; |
| 132 | StringId key = 0; |
| 133 | Variadic value = Variadic::Integer(0); |
| 134 | |
| 135 | // This is only used by the arg tracker and so is not part of the hash. |
| 136 | RowId row_id = 0; |
| 137 | }; |
| 138 | |
| 139 | struct ArgHasher { |
| 140 | uint64_t operator()(const Arg& arg) const noexcept { |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 141 | base::Hash hash; |
| 142 | hash.Update(arg.key); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 143 | // We don't hash arg.flat_key because it's a subsequence of arg.key. |
| 144 | switch (arg.value.type) { |
| 145 | case Variadic::Type::kInt: |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 146 | hash.Update(arg.value.int_value); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 147 | break; |
Eric Seckler | c93823e | 2019-06-03 16:49:19 +0100 | [diff] [blame] | 148 | case Variadic::Type::kUint: |
| 149 | hash.Update(arg.value.uint_value); |
| 150 | break; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 151 | case Variadic::Type::kString: |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 152 | hash.Update(arg.value.string_value); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 153 | break; |
| 154 | case Variadic::Type::kReal: |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 155 | hash.Update(arg.value.real_value); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 156 | break; |
Eric Seckler | c93823e | 2019-06-03 16:49:19 +0100 | [diff] [blame] | 157 | case Variadic::Type::kPointer: |
| 158 | hash.Update(arg.value.pointer_value); |
| 159 | break; |
| 160 | case Variadic::Type::kBool: |
| 161 | hash.Update(arg.value.bool_value); |
| 162 | break; |
| 163 | case Variadic::Type::kJson: |
| 164 | hash.Update(arg.value.json_value); |
| 165 | break; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 166 | } |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 167 | return hash.digest(); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 168 | } |
| 169 | }; |
| 170 | |
| 171 | const std::deque<ArgSetId>& set_ids() const { return set_ids_; } |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 172 | const std::deque<StringId>& flat_keys() const { return flat_keys_; } |
| 173 | const std::deque<StringId>& keys() const { return keys_; } |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 174 | const std::deque<Variadic>& arg_values() const { return arg_values_; } |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 175 | uint32_t args_count() const { |
| 176 | return static_cast<uint32_t>(set_ids_.size()); |
Lalit Maganti | 79472be | 2018-12-04 13:41:27 +0000 | [diff] [blame] | 177 | } |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 178 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 179 | ArgSetId AddArgSet(const std::vector<Arg>& args, |
| 180 | uint32_t begin, |
| 181 | uint32_t end) { |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 182 | base::Hash hash; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 183 | for (uint32_t i = begin; i < end; i++) { |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 184 | hash.Update(ArgHasher()(args[i])); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 185 | } |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 186 | |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 187 | ArgSetHash digest = hash.digest(); |
| 188 | auto it = arg_row_for_hash_.find(digest); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 189 | if (it != arg_row_for_hash_.end()) { |
| 190 | return set_ids_[it->second]; |
| 191 | } |
| 192 | |
| 193 | // The +1 ensures that nothing has an id == kInvalidArgSetId == 0. |
| 194 | ArgSetId id = static_cast<uint32_t>(arg_row_for_hash_.size()) + 1; |
Lalit Maganti | 1f46474 | 2019-02-28 13:49:31 +0000 | [diff] [blame] | 195 | arg_row_for_hash_.emplace(digest, args_count()); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 196 | for (uint32_t i = begin; i < end; i++) { |
| 197 | const auto& arg = args[i]; |
| 198 | set_ids_.emplace_back(id); |
| 199 | flat_keys_.emplace_back(arg.flat_key); |
| 200 | keys_.emplace_back(arg.key); |
| 201 | arg_values_.emplace_back(arg.value); |
| 202 | } |
| 203 | return id; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 206 | private: |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 207 | using ArgSetHash = uint64_t; |
| 208 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 209 | std::deque<ArgSetId> set_ids_; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 210 | std::deque<StringId> flat_keys_; |
| 211 | std::deque<StringId> keys_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 212 | std::deque<Variadic> arg_values_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 213 | |
| 214 | std::unordered_map<ArgSetHash, uint32_t> arg_row_for_hash_; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
Eric Seckler | 5703ede | 2019-07-10 10:13:02 +0100 | [diff] [blame] | 217 | class VirtualTracks { |
| 218 | public: |
| 219 | inline uint32_t AddVirtualTrack(TrackId track_id, |
| 220 | StringId name, |
| 221 | VirtualTrackScope scope, |
| 222 | UniquePid upid = 0u) { |
| 223 | track_ids_.emplace_back(track_id); |
| 224 | names_.emplace_back(name); |
| 225 | scopes_.emplace_back(scope); |
| 226 | upids_.emplace_back(upid); |
| 227 | return virtual_track_count() - 1; |
| 228 | } |
| 229 | |
| 230 | uint32_t virtual_track_count() const { |
| 231 | return static_cast<uint32_t>(track_ids_.size()); |
| 232 | } |
| 233 | |
| 234 | const std::deque<uint32_t>& track_ids() const { return track_ids_; } |
| 235 | const std::deque<StringId>& names() const { return names_; } |
| 236 | const std::deque<VirtualTrackScope>& scopes() const { return scopes_; } |
| 237 | const std::deque<UniquePid>& upids() const { return upids_; } |
| 238 | |
| 239 | private: |
| 240 | std::deque<uint32_t> track_ids_; |
| 241 | std::deque<StringId> names_; |
| 242 | std::deque<VirtualTrackScope> scopes_; |
| 243 | std::deque<UniquePid> upids_; |
| 244 | }; |
| 245 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 246 | class Slices { |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 247 | public: |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 248 | inline size_t AddSlice(uint32_t cpu, |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 249 | int64_t start_ns, |
| 250 | int64_t duration_ns, |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 251 | UniqueTid utid, |
| 252 | ftrace_utils::TaskState end_state, |
| 253 | int32_t priority) { |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 254 | cpus_.emplace_back(cpu); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 255 | start_ns_.emplace_back(start_ns); |
| 256 | durations_.emplace_back(duration_ns); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 257 | utids_.emplace_back(utid); |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 258 | end_states_.emplace_back(end_state); |
| 259 | priorities_.emplace_back(priority); |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 260 | |
| 261 | if (utid >= rows_for_utids_.size()) |
| 262 | rows_for_utids_.resize(utid + 1); |
| 263 | rows_for_utids_[utid].emplace_back(slice_count() - 1); |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 264 | return slice_count() - 1; |
| 265 | } |
| 266 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 267 | void set_duration(size_t index, int64_t duration_ns) { |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 268 | durations_[index] = duration_ns; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 271 | void set_end_state(size_t index, ftrace_utils::TaskState end_state) { |
| 272 | end_states_[index] = end_state; |
| 273 | } |
| 274 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 275 | size_t slice_count() const { return start_ns_.size(); } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 276 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 277 | const std::deque<uint32_t>& cpus() const { return cpus_; } |
| 278 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 279 | const std::deque<int64_t>& start_ns() const { return start_ns_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 280 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 281 | const std::deque<int64_t>& durations() const { return durations_; } |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 282 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 283 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 284 | |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 285 | const std::deque<ftrace_utils::TaskState>& end_state() const { |
| 286 | return end_states_; |
| 287 | } |
| 288 | |
| 289 | const std::deque<int32_t>& priorities() const { return priorities_; } |
| 290 | |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 291 | const std::deque<std::vector<uint32_t>>& rows_for_utids() const { |
Lalit Maganti | f0f09c3 | 2019-01-18 17:29:31 +0000 | [diff] [blame] | 292 | return rows_for_utids_; |
| 293 | } |
| 294 | |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 295 | private: |
Hector Dearman | 947f12a | 2018-09-11 16:50:36 +0100 | [diff] [blame] | 296 | // 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] | 297 | // in the trace for the CPU). |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 298 | std::deque<uint32_t> cpus_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 299 | std::deque<int64_t> start_ns_; |
| 300 | std::deque<int64_t> durations_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 301 | std::deque<UniqueTid> utids_; |
Lalit Maganti | b0b53ee | 2019-01-24 17:53:39 +0000 | [diff] [blame] | 302 | std::deque<ftrace_utils::TaskState> end_states_; |
| 303 | std::deque<int32_t> priorities_; |
Lalit Maganti | 5863893 | 2019-01-31 10:48:26 +0000 | [diff] [blame] | 304 | |
| 305 | // One row per utid. |
| 306 | std::deque<std::vector<uint32_t>> rows_for_utids_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 307 | }; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 308 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 309 | class NestableSlices { |
| 310 | public: |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 311 | inline uint32_t AddSlice(int64_t start_ns, |
| 312 | int64_t duration_ns, |
| 313 | int64_t ref, |
| 314 | RefType type, |
Lalit Maganti | 81a02cd | 2019-07-12 17:05:11 +0100 | [diff] [blame] | 315 | StringId category, |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 316 | StringId name, |
| 317 | uint8_t depth, |
| 318 | int64_t stack_id, |
| 319 | int64_t parent_stack_id) { |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 320 | start_ns_.emplace_back(start_ns); |
| 321 | durations_.emplace_back(duration_ns); |
Eric Seckler | 972225e | 2019-04-18 11:07:12 +0100 | [diff] [blame] | 322 | refs_.emplace_back(ref); |
| 323 | types_.emplace_back(type); |
Lalit Maganti | 81a02cd | 2019-07-12 17:05:11 +0100 | [diff] [blame] | 324 | categories_.emplace_back(category); |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 325 | names_.emplace_back(name); |
| 326 | depths_.emplace_back(depth); |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 327 | stack_ids_.emplace_back(stack_id); |
| 328 | parent_stack_ids_.emplace_back(parent_stack_id); |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 329 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 330 | return slice_count() - 1; |
| 331 | } |
| 332 | |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 333 | void set_duration(uint32_t index, int64_t duration_ns) { |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 334 | durations_[index] = duration_ns; |
| 335 | } |
| 336 | |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 337 | void set_stack_id(uint32_t index, int64_t stack_id) { |
Lalit Maganti | 7b37bbf | 2018-11-09 15:58:54 +0000 | [diff] [blame] | 338 | stack_ids_[index] = stack_id; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 339 | } |
| 340 | |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 341 | void set_arg_set_id(uint32_t index, ArgSetId id) { |
| 342 | arg_set_ids_[index] = id; |
| 343 | } |
| 344 | |
| 345 | uint32_t slice_count() const { |
| 346 | return static_cast<uint32_t>(start_ns_.size()); |
| 347 | } |
| 348 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 349 | const std::deque<int64_t>& start_ns() const { return start_ns_; } |
| 350 | const std::deque<int64_t>& durations() const { return durations_; } |
Eric Seckler | 972225e | 2019-04-18 11:07:12 +0100 | [diff] [blame] | 351 | const std::deque<int64_t>& refs() const { return refs_; } |
| 352 | const std::deque<RefType>& types() const { return types_; } |
Lalit Maganti | 81a02cd | 2019-07-12 17:05:11 +0100 | [diff] [blame] | 353 | const std::deque<StringId>& categories() const { return categories_; } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 354 | const std::deque<StringId>& names() const { return names_; } |
| 355 | const std::deque<uint8_t>& depths() const { return depths_; } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 356 | const std::deque<int64_t>& stack_ids() const { return stack_ids_; } |
| 357 | const std::deque<int64_t>& parent_stack_ids() const { |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 358 | return parent_stack_ids_; |
| 359 | } |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 360 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 361 | |
| 362 | private: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 363 | std::deque<int64_t> start_ns_; |
| 364 | std::deque<int64_t> durations_; |
Eric Seckler | 972225e | 2019-04-18 11:07:12 +0100 | [diff] [blame] | 365 | std::deque<int64_t> refs_; |
| 366 | std::deque<RefType> types_; |
Lalit Maganti | 81a02cd | 2019-07-12 17:05:11 +0100 | [diff] [blame] | 367 | std::deque<StringId> categories_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 368 | std::deque<StringId> names_; |
| 369 | std::deque<uint8_t> depths_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 370 | std::deque<int64_t> stack_ids_; |
| 371 | std::deque<int64_t> parent_stack_ids_; |
Eric Seckler | 70cc442 | 2019-05-28 16:00:23 +0100 | [diff] [blame] | 372 | std::deque<ArgSetId> arg_set_ids_; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 373 | }; |
| 374 | |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 375 | class ThreadSlices { |
| 376 | public: |
| 377 | inline uint32_t AddThreadSlice(uint32_t slice_id, |
| 378 | int64_t thread_timestamp_ns, |
| 379 | int64_t thread_duration_ns, |
| 380 | int64_t thread_instruction_count, |
| 381 | int64_t thread_instruction_delta) { |
| 382 | slice_ids_.emplace_back(slice_id); |
| 383 | thread_timestamp_ns_.emplace_back(thread_timestamp_ns); |
| 384 | thread_duration_ns_.emplace_back(thread_duration_ns); |
| 385 | thread_instruction_counts_.emplace_back(thread_instruction_count); |
| 386 | thread_instruction_deltas_.emplace_back(thread_instruction_delta); |
| 387 | return slice_count() - 1; |
| 388 | } |
| 389 | |
Eric Seckler | c3430c6 | 2019-07-22 10:49:58 +0100 | [diff] [blame^] | 390 | uint32_t slice_count() const { |
| 391 | return static_cast<uint32_t>(slice_ids_.size()); |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Eric Seckler | c3430c6 | 2019-07-22 10:49:58 +0100 | [diff] [blame^] | 394 | const std::deque<uint32_t>& slice_ids() const { return slice_ids_; } |
| 395 | const std::deque<int64_t>& thread_timestamp_ns() const { |
| 396 | return thread_timestamp_ns_; |
| 397 | } |
| 398 | const std::deque<int64_t>& thread_duration_ns() const { |
| 399 | return thread_duration_ns_; |
| 400 | } |
| 401 | const std::deque<int64_t>& thread_instruction_counts() const { |
| 402 | return thread_instruction_counts_; |
| 403 | } |
| 404 | const std::deque<int64_t>& thread_instruction_deltas() const { |
| 405 | return thread_instruction_deltas_; |
| 406 | } |
| 407 | |
| 408 | base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const { |
| 409 | auto it = |
| 410 | std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id); |
| 411 | if (it != slice_ids().end() && *it == slice_id) { |
| 412 | return static_cast<uint32_t>(std::distance(slice_ids().begin(), it)); |
| 413 | } |
| 414 | return base::nullopt; |
| 415 | } |
| 416 | |
| 417 | void UpdateThreadDurationForSliceId(uint32_t slice_id, |
| 418 | int64_t end_thread_timestamp_ns) { |
| 419 | uint32_t row = *FindRowForSliceId(slice_id); |
| 420 | int64_t begin_ns = thread_timestamp_ns_[row]; |
| 421 | thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns; |
| 422 | } |
| 423 | |
| 424 | private: |
| 425 | std::deque<uint32_t> slice_ids_; |
| 426 | std::deque<int64_t> thread_timestamp_ns_; |
| 427 | std::deque<int64_t> thread_duration_ns_; |
| 428 | std::deque<int64_t> thread_instruction_counts_; |
| 429 | std::deque<int64_t> thread_instruction_deltas_; |
| 430 | }; |
| 431 | |
| 432 | class VirtualTrackSlices { |
| 433 | public: |
| 434 | inline uint32_t AddVirtualTrackSlice(uint32_t slice_id, |
| 435 | int64_t thread_timestamp_ns, |
| 436 | int64_t thread_duration_ns, |
| 437 | int64_t thread_instruction_count, |
| 438 | int64_t thread_instruction_delta) { |
| 439 | slice_ids_.emplace_back(slice_id); |
| 440 | thread_timestamp_ns_.emplace_back(thread_timestamp_ns); |
| 441 | thread_duration_ns_.emplace_back(thread_duration_ns); |
| 442 | thread_instruction_counts_.emplace_back(thread_instruction_count); |
| 443 | thread_instruction_deltas_.emplace_back(thread_instruction_delta); |
| 444 | return slice_count() - 1; |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | uint32_t slice_count() const { |
| 448 | return static_cast<uint32_t>(slice_ids_.size()); |
| 449 | } |
| 450 | |
| 451 | const std::deque<uint32_t>& slice_ids() const { return slice_ids_; } |
| 452 | const std::deque<int64_t>& thread_timestamp_ns() const { |
| 453 | return thread_timestamp_ns_; |
| 454 | } |
| 455 | const std::deque<int64_t>& thread_duration_ns() const { |
| 456 | return thread_duration_ns_; |
| 457 | } |
| 458 | const std::deque<int64_t>& thread_instruction_counts() const { |
| 459 | return thread_instruction_counts_; |
| 460 | } |
| 461 | const std::deque<int64_t>& thread_instruction_deltas() const { |
| 462 | return thread_instruction_deltas_; |
| 463 | } |
| 464 | |
Mikhail Khokhlov | 7db0491 | 2019-07-18 16:11:11 +0100 | [diff] [blame] | 465 | base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const { |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 466 | auto it = |
| 467 | std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id); |
Mikhail Khokhlov | 7db0491 | 2019-07-18 16:11:11 +0100 | [diff] [blame] | 468 | if (it != slice_ids().end() && *it == slice_id) { |
| 469 | return static_cast<uint32_t>(std::distance(slice_ids().begin(), it)); |
| 470 | } |
| 471 | return base::nullopt; |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void UpdateThreadDurationForSliceId(uint32_t slice_id, |
| 475 | int64_t end_thread_timestamp_ns) { |
Mikhail Khokhlov | 7db0491 | 2019-07-18 16:11:11 +0100 | [diff] [blame] | 476 | uint32_t row = *FindRowForSliceId(slice_id); |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 477 | int64_t begin_ns = thread_timestamp_ns_[row]; |
| 478 | thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns; |
| 479 | } |
| 480 | |
| 481 | private: |
| 482 | std::deque<uint32_t> slice_ids_; |
| 483 | std::deque<int64_t> thread_timestamp_ns_; |
| 484 | std::deque<int64_t> thread_duration_ns_; |
| 485 | std::deque<int64_t> thread_instruction_counts_; |
| 486 | std::deque<int64_t> thread_instruction_deltas_; |
| 487 | }; |
| 488 | |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 489 | class CounterDefinitions { |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 490 | public: |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 491 | using Id = uint32_t; |
Lalit Maganti | 521d97b | 2019-04-29 13:47:03 +0100 | [diff] [blame] | 492 | static constexpr Id kInvalidId = std::numeric_limits<Id>::max(); |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 493 | |
| 494 | inline Id AddCounterDefinition(StringId name_id, |
| 495 | int64_t ref, |
| 496 | RefType type) { |
| 497 | base::Hash hash; |
| 498 | hash.Update(name_id); |
| 499 | hash.Update(ref); |
| 500 | hash.Update(type); |
| 501 | |
| 502 | // TODO(lalitm): this is a perf bottleneck and likely we can do something |
| 503 | // quite a bit better here. |
| 504 | uint64_t digest = hash.digest(); |
| 505 | auto it = hash_to_row_idx_.find(digest); |
| 506 | if (it != hash_to_row_idx_.end()) |
| 507 | return it->second; |
| 508 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 509 | name_ids_.emplace_back(name_id); |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 510 | refs_.emplace_back(ref); |
| 511 | types_.emplace_back(type); |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 512 | hash_to_row_idx_.emplace(digest, size() - 1); |
| 513 | return size() - 1; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 514 | } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 515 | |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 516 | uint32_t size() const { return static_cast<uint32_t>(name_ids_.size()); } |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 517 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 518 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 519 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 520 | const std::deque<int64_t>& refs() const { return refs_; } |
| 521 | |
| 522 | const std::deque<RefType>& types() const { return types_; } |
| 523 | |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 524 | private: |
| 525 | std::deque<StringId> name_ids_; |
| 526 | std::deque<int64_t> refs_; |
| 527 | std::deque<RefType> types_; |
| 528 | |
| 529 | std::unordered_map<uint64_t, uint32_t> hash_to_row_idx_; |
| 530 | }; |
| 531 | |
| 532 | class CounterValues { |
| 533 | public: |
| 534 | inline uint32_t AddCounterValue(CounterDefinitions::Id counter_id, |
| 535 | int64_t timestamp, |
| 536 | double value) { |
| 537 | counter_ids_.emplace_back(counter_id); |
| 538 | timestamps_.emplace_back(timestamp); |
| 539 | values_.emplace_back(value); |
| 540 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Ioannis Ilkos | f129c26 | 2019-04-25 14:53:51 +0100 | [diff] [blame] | 541 | |
Lalit Maganti | 521d97b | 2019-04-29 13:47:03 +0100 | [diff] [blame] | 542 | if (counter_id != CounterDefinitions::kInvalidId) { |
| 543 | if (counter_id >= rows_for_counter_id_.size()) { |
| 544 | rows_for_counter_id_.resize(counter_id + 1); |
| 545 | } |
| 546 | rows_for_counter_id_[counter_id].emplace_back(size() - 1); |
| 547 | } |
| 548 | return size() - 1; |
| 549 | } |
| 550 | |
| 551 | void set_counter_id(uint32_t index, CounterDefinitions::Id counter_id) { |
| 552 | PERFETTO_DCHECK(counter_ids_[index] == CounterDefinitions::kInvalidId); |
| 553 | |
| 554 | counter_ids_[index] = counter_id; |
Ioannis Ilkos | f129c26 | 2019-04-25 14:53:51 +0100 | [diff] [blame] | 555 | if (counter_id >= rows_for_counter_id_.size()) { |
| 556 | rows_for_counter_id_.resize(counter_id + 1); |
| 557 | } |
Lalit Maganti | 521d97b | 2019-04-29 13:47:03 +0100 | [diff] [blame] | 558 | |
| 559 | auto* new_rows = &rows_for_counter_id_[counter_id]; |
| 560 | new_rows->insert( |
| 561 | std::upper_bound(new_rows->begin(), new_rows->end(), index), index); |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; } |
| 565 | |
| 566 | uint32_t size() const { return static_cast<uint32_t>(counter_ids_.size()); } |
| 567 | |
| 568 | const std::deque<CounterDefinitions::Id>& counter_ids() const { |
| 569 | return counter_ids_; |
| 570 | } |
| 571 | |
| 572 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
| 573 | |
| 574 | const std::deque<double>& values() const { return values_; } |
| 575 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 576 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
| 577 | |
Ioannis Ilkos | f129c26 | 2019-04-25 14:53:51 +0100 | [diff] [blame] | 578 | const std::deque<std::vector<uint32_t>>& rows_for_counter_id() const { |
| 579 | return rows_for_counter_id_; |
| 580 | } |
| 581 | |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 582 | private: |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 583 | std::deque<CounterDefinitions::Id> counter_ids_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 584 | std::deque<int64_t> timestamps_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 585 | std::deque<double> values_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 586 | std::deque<ArgSetId> arg_set_ids_; |
Ioannis Ilkos | f129c26 | 2019-04-25 14:53:51 +0100 | [diff] [blame] | 587 | |
| 588 | // Indexed by counter_id value and contains the row numbers corresponding to |
| 589 | // it. |
| 590 | std::deque<std::vector<uint32_t>> rows_for_counter_id_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 591 | }; |
| 592 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 593 | class SqlStats { |
| 594 | public: |
| 595 | static constexpr size_t kMaxLogEntries = 100; |
Lalit Maganti | aac2f65 | 2019-04-30 12:16:21 +0100 | [diff] [blame] | 596 | uint32_t RecordQueryBegin(const std::string& query, |
| 597 | int64_t time_queued, |
| 598 | int64_t time_started); |
| 599 | void RecordQueryFirstNext(uint32_t row, int64_t time_first_next); |
| 600 | void RecordQueryEnd(uint32_t row, int64_t time_end); |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 601 | size_t size() const { return queries_.size(); } |
| 602 | const std::deque<std::string>& queries() const { return queries_; } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 603 | const std::deque<int64_t>& times_queued() const { return times_queued_; } |
| 604 | const std::deque<int64_t>& times_started() const { return times_started_; } |
Lalit Maganti | aac2f65 | 2019-04-30 12:16:21 +0100 | [diff] [blame] | 605 | const std::deque<int64_t>& times_first_next() const { |
| 606 | return times_first_next_; |
| 607 | } |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 608 | const std::deque<int64_t>& times_ended() const { return times_ended_; } |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 609 | |
| 610 | private: |
Lalit Maganti | aac2f65 | 2019-04-30 12:16:21 +0100 | [diff] [blame] | 611 | uint32_t popped_queries_ = 0; |
| 612 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 613 | std::deque<std::string> queries_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 614 | std::deque<int64_t> times_queued_; |
| 615 | std::deque<int64_t> times_started_; |
Lalit Maganti | aac2f65 | 2019-04-30 12:16:21 +0100 | [diff] [blame] | 616 | std::deque<int64_t> times_first_next_; |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 617 | std::deque<int64_t> times_ended_; |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 618 | }; |
| 619 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 620 | class Instants { |
| 621 | public: |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 622 | inline uint32_t AddInstantEvent(int64_t timestamp, |
| 623 | StringId name_id, |
| 624 | double value, |
| 625 | int64_t ref, |
| 626 | RefType type) { |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 627 | timestamps_.emplace_back(timestamp); |
| 628 | name_ids_.emplace_back(name_id); |
| 629 | values_.emplace_back(value); |
| 630 | refs_.emplace_back(ref); |
| 631 | types_.emplace_back(type); |
Lalit Maganti | 1c21d17 | 2019-02-07 10:48:24 +0000 | [diff] [blame] | 632 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Lalit Maganti | 66ed7ad | 2019-01-11 16:47:26 +0000 | [diff] [blame] | 633 | return static_cast<uint32_t>(instant_count() - 1); |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Lalit Maganti | 521d97b | 2019-04-29 13:47:03 +0100 | [diff] [blame] | 636 | void set_ref(uint32_t row, int64_t ref) { refs_[row] = ref; } |
| 637 | |
Lalit Maganti | 1c21d17 | 2019-02-07 10:48:24 +0000 | [diff] [blame] | 638 | void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; } |
| 639 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 640 | size_t instant_count() const { return timestamps_.size(); } |
| 641 | |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 642 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 643 | |
| 644 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 645 | |
| 646 | const std::deque<double>& values() const { return values_; } |
| 647 | |
| 648 | const std::deque<int64_t>& refs() const { return refs_; } |
| 649 | |
| 650 | const std::deque<RefType>& types() const { return types_; } |
| 651 | |
Lalit Maganti | 1c21d17 | 2019-02-07 10:48:24 +0000 | [diff] [blame] | 652 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
| 653 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 654 | private: |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 655 | std::deque<int64_t> timestamps_; |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 656 | std::deque<StringId> name_ids_; |
| 657 | std::deque<double> values_; |
| 658 | std::deque<int64_t> refs_; |
| 659 | std::deque<RefType> types_; |
Lalit Maganti | 1c21d17 | 2019-02-07 10:48:24 +0000 | [diff] [blame] | 660 | std::deque<ArgSetId> arg_set_ids_; |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 661 | }; |
| 662 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 663 | class RawEvents { |
| 664 | public: |
| 665 | inline RowId AddRawEvent(int64_t timestamp, |
| 666 | StringId name_id, |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 667 | uint32_t cpu, |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 668 | UniqueTid utid) { |
| 669 | timestamps_.emplace_back(timestamp); |
| 670 | name_ids_.emplace_back(name_id); |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 671 | cpus_.emplace_back(cpu); |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 672 | utids_.emplace_back(utid); |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 673 | arg_set_ids_.emplace_back(kInvalidArgSetId); |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 674 | return CreateRowId(TableId::kRawEvents, |
| 675 | static_cast<uint32_t>(raw_event_count() - 1)); |
| 676 | } |
| 677 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 678 | void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; } |
| 679 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 680 | size_t raw_event_count() const { return timestamps_.size(); } |
| 681 | |
| 682 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
| 683 | |
| 684 | const std::deque<StringId>& name_ids() const { return name_ids_; } |
| 685 | |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 686 | const std::deque<uint32_t>& cpus() const { return cpus_; } |
| 687 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 688 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 689 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 690 | const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; } |
| 691 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 692 | private: |
| 693 | std::deque<int64_t> timestamps_; |
| 694 | std::deque<StringId> name_ids_; |
Lalit Maganti | e87cc81 | 2019-01-10 15:20:06 +0000 | [diff] [blame] | 695 | std::deque<uint32_t> cpus_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 696 | std::deque<UniqueTid> utids_; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 697 | std::deque<ArgSetId> arg_set_ids_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 698 | }; |
| 699 | |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 700 | class AndroidLogs { |
| 701 | public: |
| 702 | inline size_t AddLogEvent(int64_t timestamp, |
| 703 | UniqueTid utid, |
| 704 | uint8_t prio, |
| 705 | StringId tag_id, |
| 706 | StringId msg_id) { |
| 707 | timestamps_.emplace_back(timestamp); |
| 708 | utids_.emplace_back(utid); |
| 709 | prios_.emplace_back(prio); |
| 710 | tag_ids_.emplace_back(tag_id); |
| 711 | msg_ids_.emplace_back(msg_id); |
| 712 | return size() - 1; |
| 713 | } |
| 714 | |
| 715 | size_t size() const { return timestamps_.size(); } |
| 716 | |
| 717 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
| 718 | const std::deque<UniqueTid>& utids() const { return utids_; } |
| 719 | const std::deque<uint8_t>& prios() const { return prios_; } |
| 720 | const std::deque<StringId>& tag_ids() const { return tag_ids_; } |
| 721 | const std::deque<StringId>& msg_ids() const { return msg_ids_; } |
| 722 | |
| 723 | private: |
| 724 | std::deque<int64_t> timestamps_; |
| 725 | std::deque<UniqueTid> utids_; |
| 726 | std::deque<uint8_t> prios_; |
| 727 | std::deque<StringId> tag_ids_; |
| 728 | std::deque<StringId> msg_ids_; |
| 729 | }; |
| 730 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 731 | struct Stats { |
| 732 | using IndexMap = std::map<int, int64_t>; |
| 733 | int64_t value = 0; |
| 734 | IndexMap indexed_values; |
| 735 | }; |
| 736 | using StatsMap = std::array<Stats, stats::kNumKeys>; |
| 737 | |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 738 | class Metadata { |
| 739 | public: |
| 740 | const std::deque<metadata::KeyIDs>& keys() const { return keys_; } |
| 741 | const std::deque<Variadic>& values() const { return values_; } |
| 742 | |
| 743 | RowId SetScalarMetadata(metadata::KeyIDs key, Variadic value) { |
| 744 | PERFETTO_DCHECK(key < metadata::kNumKeys); |
| 745 | PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kSingle); |
| 746 | PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]); |
| 747 | |
| 748 | // Already set - on release builds, overwrite the previous value. |
| 749 | auto it = scalar_indices.find(key); |
| 750 | if (it != scalar_indices.end()) { |
| 751 | PERFETTO_DFATAL("Setting a scalar metadata entry more than once."); |
| 752 | uint32_t index = static_cast<uint32_t>(it->second); |
| 753 | values_[index] = value; |
| 754 | return TraceStorage::CreateRowId(kMetadataTable, index); |
| 755 | } |
| 756 | // First time setting this key. |
| 757 | keys_.push_back(key); |
| 758 | values_.push_back(value); |
| 759 | uint32_t index = static_cast<uint32_t>(keys_.size() - 1); |
| 760 | scalar_indices[key] = index; |
| 761 | return TraceStorage::CreateRowId(kMetadataTable, index); |
| 762 | } |
| 763 | |
| 764 | RowId AppendMetadata(metadata::KeyIDs key, Variadic value) { |
| 765 | PERFETTO_DCHECK(key < metadata::kNumKeys); |
| 766 | PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kMulti); |
| 767 | PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]); |
| 768 | |
| 769 | keys_.push_back(key); |
| 770 | values_.push_back(value); |
| 771 | uint32_t index = static_cast<uint32_t>(keys_.size() - 1); |
| 772 | return TraceStorage::CreateRowId(kMetadataTable, index); |
| 773 | } |
| 774 | |
Ryan Savitski | 0476ee9 | 2019-07-09 14:29:33 +0100 | [diff] [blame] | 775 | void OverwriteMetadata(uint32_t index, Variadic value) { |
| 776 | PERFETTO_DCHECK(index < values_.size()); |
| 777 | values_[index] = value; |
| 778 | } |
| 779 | |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 780 | private: |
| 781 | std::deque<metadata::KeyIDs> keys_; |
| 782 | std::deque<Variadic> values_; |
| 783 | // Extraneous state to track locations of entries that should have at most |
| 784 | // one row. Used only to maintain uniqueness during insertions. |
| 785 | std::map<metadata::KeyIDs, uint32_t> scalar_indices; |
| 786 | }; |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 787 | |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 788 | class HeapProfileFrames { |
| 789 | public: |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 790 | struct Row { |
| 791 | StringId name_id; |
| 792 | int64_t mapping_row; |
| 793 | int64_t rel_pc; |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 794 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 795 | bool operator==(const Row& other) const { |
| 796 | return std::tie(name_id, mapping_row, rel_pc) == |
| 797 | std::tie(other.name_id, other.mapping_row, other.rel_pc); |
| 798 | } |
| 799 | }; |
| 800 | |
Lalit Maganti | 9b2d52b | 2019-05-07 14:32:15 +0100 | [diff] [blame] | 801 | uint32_t size() const { return static_cast<uint32_t>(names_.size()); } |
| 802 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 803 | int64_t Insert(const Row& row) { |
| 804 | names_.emplace_back(row.name_id); |
| 805 | mappings_.emplace_back(row.mapping_row); |
| 806 | rel_pcs_.emplace_back(row.rel_pc); |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 807 | return static_cast<int64_t>(names_.size()) - 1; |
| 808 | } |
| 809 | |
| 810 | const std::deque<StringId>& names() const { return names_; } |
| 811 | const std::deque<int64_t>& mappings() const { return mappings_; } |
| 812 | const std::deque<int64_t>& rel_pcs() const { return rel_pcs_; } |
| 813 | |
| 814 | private: |
| 815 | std::deque<StringId> names_; |
| 816 | std::deque<int64_t> mappings_; |
| 817 | std::deque<int64_t> rel_pcs_; |
| 818 | }; |
| 819 | |
| 820 | class HeapProfileCallsites { |
| 821 | public: |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 822 | struct Row { |
| 823 | int64_t depth; |
| 824 | int64_t parent_id; |
| 825 | int64_t frame_row; |
| 826 | |
| 827 | bool operator==(const Row& other) const { |
| 828 | return std::tie(depth, parent_id, frame_row) == |
| 829 | std::tie(other.depth, other.parent_id, other.frame_row); |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 830 | } |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 831 | }; |
| 832 | |
Lalit Maganti | 9b2d52b | 2019-05-07 14:32:15 +0100 | [diff] [blame] | 833 | uint32_t size() const { return static_cast<uint32_t>(frame_ids_.size()); } |
| 834 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 835 | int64_t Insert(const Row& row) { |
| 836 | frame_depths_.emplace_back(row.depth); |
| 837 | parent_callsite_ids_.emplace_back(row.parent_id); |
| 838 | frame_ids_.emplace_back(row.frame_row); |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 839 | return static_cast<int64_t>(frame_depths_.size()) - 1; |
| 840 | } |
| 841 | |
| 842 | const std::deque<int64_t>& frame_depths() const { return frame_depths_; } |
| 843 | const std::deque<int64_t>& parent_callsite_ids() const { |
| 844 | return parent_callsite_ids_; |
| 845 | } |
| 846 | const std::deque<int64_t>& frame_ids() const { return frame_ids_; } |
| 847 | |
| 848 | private: |
| 849 | std::deque<int64_t> frame_depths_; |
| 850 | std::deque<int64_t> parent_callsite_ids_; |
| 851 | std::deque<int64_t> frame_ids_; |
| 852 | }; |
| 853 | |
| 854 | class HeapProfileMappings { |
| 855 | public: |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 856 | struct Row { |
| 857 | StringId build_id; |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 858 | int64_t exact_offset; |
| 859 | int64_t start_offset; |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 860 | int64_t start; |
| 861 | int64_t end; |
| 862 | int64_t load_bias; |
| 863 | StringId name_id; |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 864 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 865 | bool operator==(const Row& other) const { |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 866 | return std::tie(build_id, exact_offset, start_offset, start, end, |
| 867 | load_bias, name_id) == |
| 868 | std::tie(other.build_id, other.exact_offset, other.start_offset, |
| 869 | other.start, other.end, other.load_bias, other.name_id); |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 870 | } |
| 871 | }; |
| 872 | |
Lalit Maganti | 9b2d52b | 2019-05-07 14:32:15 +0100 | [diff] [blame] | 873 | uint32_t size() const { return static_cast<uint32_t>(names_.size()); } |
| 874 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 875 | int64_t Insert(const Row& row) { |
| 876 | build_ids_.emplace_back(row.build_id); |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 877 | exact_offsets_.emplace_back(row.exact_offset); |
| 878 | start_offsets_.emplace_back(row.start_offset); |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 879 | starts_.emplace_back(row.start); |
| 880 | ends_.emplace_back(row.end); |
| 881 | load_biases_.emplace_back(row.load_bias); |
| 882 | names_.emplace_back(row.name_id); |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 883 | return static_cast<int64_t>(build_ids_.size()) - 1; |
| 884 | } |
| 885 | |
| 886 | const std::deque<StringId>& build_ids() const { return build_ids_; } |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 887 | const std::deque<int64_t>& exact_offsets() const { return exact_offsets_; } |
| 888 | const std::deque<int64_t>& start_offsets() const { return start_offsets_; } |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 889 | const std::deque<int64_t>& starts() const { return starts_; } |
| 890 | const std::deque<int64_t>& ends() const { return ends_; } |
| 891 | const std::deque<int64_t>& load_biases() const { return load_biases_; } |
| 892 | const std::deque<StringId>& names() const { return names_; } |
| 893 | |
| 894 | private: |
| 895 | std::deque<StringId> build_ids_; |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 896 | std::deque<int64_t> exact_offsets_; |
| 897 | std::deque<int64_t> start_offsets_; |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 898 | std::deque<int64_t> starts_; |
| 899 | std::deque<int64_t> ends_; |
| 900 | std::deque<int64_t> load_biases_; |
| 901 | std::deque<StringId> names_; |
| 902 | }; |
| 903 | |
| 904 | class HeapProfileAllocations { |
| 905 | public: |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 906 | struct Row { |
| 907 | int64_t timestamp; |
Florian Mayer | df1968c | 2019-05-13 16:39:35 +0100 | [diff] [blame] | 908 | UniquePid upid; |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 909 | int64_t callsite_id; |
| 910 | int64_t count; |
| 911 | int64_t size; |
| 912 | }; |
| 913 | |
Lalit Maganti | 9b2d52b | 2019-05-07 14:32:15 +0100 | [diff] [blame] | 914 | uint32_t size() const { return static_cast<uint32_t>(timestamps_.size()); } |
| 915 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 916 | void Insert(const Row& row) { |
| 917 | timestamps_.emplace_back(row.timestamp); |
Florian Mayer | df1968c | 2019-05-13 16:39:35 +0100 | [diff] [blame] | 918 | upids_.emplace_back(row.upid); |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 919 | callsite_ids_.emplace_back(row.callsite_id); |
| 920 | counts_.emplace_back(row.count); |
| 921 | sizes_.emplace_back(row.size); |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | const std::deque<int64_t>& timestamps() const { return timestamps_; } |
Florian Mayer | df1968c | 2019-05-13 16:39:35 +0100 | [diff] [blame] | 925 | const std::deque<UniquePid>& upids() const { return upids_; } |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 926 | const std::deque<int64_t>& callsite_ids() const { return callsite_ids_; } |
| 927 | const std::deque<int64_t>& counts() const { return counts_; } |
| 928 | const std::deque<int64_t>& sizes() const { return sizes_; } |
| 929 | |
| 930 | private: |
| 931 | std::deque<int64_t> timestamps_; |
Florian Mayer | df1968c | 2019-05-13 16:39:35 +0100 | [diff] [blame] | 932 | std::deque<UniquePid> upids_; |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 933 | std::deque<int64_t> callsite_ids_; |
| 934 | std::deque<int64_t> counts_; |
| 935 | std::deque<int64_t> sizes_; |
| 936 | }; |
| 937 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 938 | void ResetStorage(); |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 939 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 940 | UniqueTid AddEmptyThread(uint32_t tid) { |
| 941 | unique_threads_.emplace_back(tid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 942 | return static_cast<UniqueTid>(unique_threads_.size() - 1); |
| 943 | } |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 944 | |
Primiano Tucci | b75dcee | 2018-08-08 12:21:36 +0100 | [diff] [blame] | 945 | UniquePid AddEmptyProcess(uint32_t pid) { |
| 946 | unique_processes_.emplace_back(pid); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 947 | return static_cast<UniquePid>(unique_processes_.size() - 1); |
| 948 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 949 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 950 | // Return an unqiue identifier for the contents of each string. |
| 951 | // The string is copied internally and can be destroyed after this called. |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 952 | // Virtual for testing. |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 953 | virtual StringId InternString(base::StringView str) { |
| 954 | return string_pool_.InternString(str); |
| 955 | } |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 956 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 957 | Process* GetMutableProcess(UniquePid upid) { |
Lalit Maganti | 676658b | 2018-11-20 18:24:31 +0000 | [diff] [blame] | 958 | PERFETTO_DCHECK(upid < unique_processes_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 959 | return &unique_processes_[upid]; |
| 960 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 961 | |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 962 | Thread* GetMutableThread(UniqueTid utid) { |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 963 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 964 | return &unique_threads_[utid]; |
| 965 | } |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 966 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 967 | // Example usage: SetStats(stats::android_log_num_failed, 42); |
| 968 | void SetStats(size_t key, int64_t value) { |
| 969 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 970 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle); |
| 971 | stats_[key].value = value; |
| 972 | } |
| 973 | |
| 974 | // Example usage: IncrementStats(stats::android_log_num_failed, -1); |
| 975 | void IncrementStats(size_t key, int64_t increment = 1) { |
| 976 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 977 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle); |
| 978 | stats_[key].value += increment; |
| 979 | } |
| 980 | |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 981 | // Example usage: IncrementIndexedStats(stats::cpu_failure, 1); |
| 982 | void IncrementIndexedStats(size_t key, int index, int64_t increment = 1) { |
| 983 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 984 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed); |
| 985 | stats_[key].indexed_values[index] += increment; |
| 986 | } |
| 987 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 988 | // Example usage: SetIndexedStats(stats::cpu_failure, 1, 42); |
| 989 | void SetIndexedStats(size_t key, int index, int64_t value) { |
| 990 | PERFETTO_DCHECK(key < stats::kNumKeys); |
| 991 | PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed); |
| 992 | stats_[key].indexed_values[index] = value; |
| 993 | } |
| 994 | |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 995 | // Example usage: |
| 996 | // SetMetadata(metadata::benchmark_name, |
| 997 | // Variadic::String(storage->InternString("foo")); |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 998 | // Returns the RowId of the new entry. |
Mikhail Khokhlov | b1fe42a | 2019-05-23 13:58:05 +0100 | [diff] [blame] | 999 | // Virtual for testing. |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 1000 | virtual RowId SetMetadata(metadata::KeyIDs key, Variadic value) { |
| 1001 | return metadata_.SetScalarMetadata(key, value); |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | // Example usage: |
| 1005 | // AppendMetadata(metadata::benchmark_story_tags, |
| 1006 | // Variadic::String(storage->InternString("bar")); |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 1007 | // Returns the RowId of the new entry. |
Mikhail Khokhlov | b1fe42a | 2019-05-23 13:58:05 +0100 | [diff] [blame] | 1008 | // Virtual for testing. |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 1009 | virtual RowId AppendMetadata(metadata::KeyIDs key, Variadic value) { |
| 1010 | return metadata_.AppendMetadata(key, value); |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
Eric Seckler | 77b5278 | 2019-05-02 15:18:57 +0100 | [diff] [blame] | 1013 | class ScopedStatsTracer { |
| 1014 | public: |
| 1015 | ScopedStatsTracer(TraceStorage* storage, size_t key) |
| 1016 | : storage_(storage), key_(key), start_ns_(base::GetWallTimeNs()) {} |
| 1017 | |
| 1018 | ~ScopedStatsTracer() { |
| 1019 | if (!storage_) |
| 1020 | return; |
| 1021 | auto delta_ns = base::GetWallTimeNs() - start_ns_; |
| 1022 | storage_->IncrementStats(key_, delta_ns.count()); |
| 1023 | } |
| 1024 | |
| 1025 | ScopedStatsTracer(ScopedStatsTracer&& other) noexcept { MoveImpl(&other); } |
| 1026 | |
| 1027 | ScopedStatsTracer& operator=(ScopedStatsTracer&& other) { |
| 1028 | MoveImpl(&other); |
| 1029 | return *this; |
| 1030 | } |
| 1031 | |
| 1032 | private: |
| 1033 | ScopedStatsTracer(const ScopedStatsTracer&) = delete; |
| 1034 | ScopedStatsTracer& operator=(const ScopedStatsTracer&) = delete; |
| 1035 | |
| 1036 | void MoveImpl(ScopedStatsTracer* other) { |
| 1037 | storage_ = other->storage_; |
| 1038 | key_ = other->key_; |
| 1039 | start_ns_ = other->start_ns_; |
| 1040 | other->storage_ = nullptr; |
| 1041 | } |
| 1042 | |
| 1043 | TraceStorage* storage_; |
| 1044 | size_t key_; |
| 1045 | base::TimeNanos start_ns_; |
| 1046 | }; |
| 1047 | |
| 1048 | ScopedStatsTracer TraceExecutionTimeIntoStats(size_t key) { |
| 1049 | return ScopedStatsTracer(this, key); |
| 1050 | } |
| 1051 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1052 | // Reading methods. |
Eric Seckler | c93823e | 2019-06-03 16:49:19 +0100 | [diff] [blame] | 1053 | // Virtual for testing. |
| 1054 | virtual NullTermStringView GetString(StringId id) const { |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 1055 | return string_pool_.Get(id); |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 1058 | const Process& GetProcess(UniquePid upid) const { |
Lalit Maganti | 676658b | 2018-11-20 18:24:31 +0000 | [diff] [blame] | 1059 | PERFETTO_DCHECK(upid < unique_processes_.size()); |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 1060 | return unique_processes_[upid]; |
| 1061 | } |
| 1062 | |
Lalit Maganti | e9d4053 | 2018-06-29 13:15:06 +0100 | [diff] [blame] | 1063 | const Thread& GetThread(UniqueTid utid) const { |
Lalit Maganti | 1f64cfa | 2018-09-18 13:20:02 +0100 | [diff] [blame] | 1064 | // Allow utid == 0 for idle thread retrieval. |
Florian Mayer | a1aaec2 | 2018-09-19 17:02:26 +0100 | [diff] [blame] | 1065 | PERFETTO_DCHECK(utid < unique_threads_.size()); |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 1066 | return unique_threads_[utid]; |
| 1067 | } |
| 1068 | |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 1069 | static RowId CreateRowId(TableId table, uint32_t row) { |
Lalit Maganti | 85ca4a8 | 2018-12-07 17:28:02 +0000 | [diff] [blame] | 1070 | return (static_cast<RowId>(table) << kRowIdTableShift) | row; |
Lalit Maganti | 5ea9e93 | 2018-11-30 14:19:39 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 1073 | static std::pair<int8_t /*table*/, uint32_t /*row*/> ParseRowId(RowId rowid) { |
| 1074 | auto id = static_cast<uint64_t>(rowid); |
| 1075 | auto table_id = static_cast<uint8_t>(id >> kRowIdTableShift); |
| 1076 | auto row = static_cast<uint32_t>(id & ((1ull << kRowIdTableShift) - 1)); |
| 1077 | return std::make_pair(table_id, row); |
| 1078 | } |
| 1079 | |
Eric Seckler | 5703ede | 2019-07-10 10:13:02 +0100 | [diff] [blame] | 1080 | const VirtualTracks& virtual_tracks() const { return virtual_tracks_; } |
| 1081 | VirtualTracks* mutable_virtual_tracks() { return &virtual_tracks_; } |
| 1082 | |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 1083 | const Slices& slices() const { return slices_; } |
Lalit Maganti | fde2904 | 2018-10-04 13:28:52 +0100 | [diff] [blame] | 1084 | Slices* mutable_slices() { return &slices_; } |
| 1085 | |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 1086 | const NestableSlices& nestable_slices() const { return nestable_slices_; } |
| 1087 | NestableSlices* mutable_nestable_slices() { return &nestable_slices_; } |
| 1088 | |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 1089 | const ThreadSlices& thread_slices() const { return thread_slices_; } |
| 1090 | ThreadSlices* mutable_thread_slices() { return &thread_slices_; } |
| 1091 | |
Eric Seckler | c3430c6 | 2019-07-22 10:49:58 +0100 | [diff] [blame^] | 1092 | const VirtualTrackSlices& virtual_track_slices() const { |
| 1093 | return virtual_track_slices_; |
| 1094 | } |
| 1095 | VirtualTrackSlices* mutable_virtual_track_slices() { |
| 1096 | return &virtual_track_slices_; |
| 1097 | } |
| 1098 | |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 1099 | const CounterDefinitions& counter_definitions() const { |
| 1100 | return counter_definitions_; |
| 1101 | } |
| 1102 | CounterDefinitions* mutable_counter_definitions() { |
| 1103 | return &counter_definitions_; |
| 1104 | } |
| 1105 | |
| 1106 | const CounterValues& counter_values() const { return counter_values_; } |
| 1107 | CounterValues* mutable_counter_values() { return &counter_values_; } |
Isabelle Taylor | 14674d4 | 2018-09-07 11:33:11 +0100 | [diff] [blame] | 1108 | |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 1109 | const SqlStats& sql_stats() const { return sql_stats_; } |
| 1110 | SqlStats* mutable_sql_stats() { return &sql_stats_; } |
| 1111 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 1112 | const Instants& instants() const { return instants_; } |
| 1113 | Instants* mutable_instants() { return &instants_; } |
| 1114 | |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 1115 | const AndroidLogs& android_logs() const { return android_log_; } |
| 1116 | AndroidLogs* mutable_android_log() { return &android_log_; } |
| 1117 | |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 1118 | const StatsMap& stats() const { return stats_; } |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame] | 1119 | |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 1120 | const Metadata& metadata() const { return metadata_; } |
Ryan Savitski | 0476ee9 | 2019-07-09 14:29:33 +0100 | [diff] [blame] | 1121 | Metadata* mutable_metadata() { return &metadata_; } |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 1122 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 1123 | const Args& args() const { return args_; } |
| 1124 | Args* mutable_args() { return &args_; } |
| 1125 | |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 1126 | const RawEvents& raw_events() const { return raw_events_; } |
| 1127 | RawEvents* mutable_raw_events() { return &raw_events_; } |
| 1128 | |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 1129 | const HeapProfileMappings& heap_profile_mappings() const { |
| 1130 | return heap_profile_mappings_; |
| 1131 | } |
| 1132 | HeapProfileMappings* mutable_heap_profile_mappings() { |
| 1133 | return &heap_profile_mappings_; |
| 1134 | } |
| 1135 | |
| 1136 | const HeapProfileFrames& heap_profile_frames() const { |
| 1137 | return heap_profile_frames_; |
| 1138 | } |
| 1139 | HeapProfileFrames* mutable_heap_profile_frames() { |
| 1140 | return &heap_profile_frames_; |
| 1141 | } |
| 1142 | |
| 1143 | const HeapProfileCallsites& heap_profile_callsites() const { |
| 1144 | return heap_profile_callsites_; |
| 1145 | } |
| 1146 | HeapProfileCallsites* mutable_heap_profile_callsites() { |
| 1147 | return &heap_profile_callsites_; |
| 1148 | } |
| 1149 | |
| 1150 | const HeapProfileAllocations& heap_profile_allocations() const { |
| 1151 | return heap_profile_allocations_; |
| 1152 | } |
| 1153 | HeapProfileAllocations* mutable_heap_profile_allocations() { |
| 1154 | return &heap_profile_allocations_; |
| 1155 | } |
| 1156 | |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 1157 | const StringPool& string_pool() const { return string_pool_; } |
Lalit Maganti | acda68b | 2018-10-29 15:23:25 +0000 | [diff] [blame] | 1158 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 1159 | // |unique_processes_| always contains at least 1 element becuase the 0th ID |
| 1160 | // is reserved to indicate an invalid process. |
Lalit Maganti | 9c6395b | 2019-01-17 00:25:09 +0000 | [diff] [blame] | 1161 | size_t process_count() const { return unique_processes_.size(); } |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 1162 | |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 1163 | // |unique_threads_| always contains at least 1 element becuase the 0th ID |
| 1164 | // is reserved to indicate an invalid thread. |
Lalit Maganti | 9c6395b | 2019-01-17 00:25:09 +0000 | [diff] [blame] | 1165 | size_t thread_count() const { return unique_threads_.size(); } |
Isabelle Taylor | e7003fb | 2018-07-17 11:39:01 +0100 | [diff] [blame] | 1166 | |
Hector Dearman | 1232336 | 2018-08-09 16:09:28 +0100 | [diff] [blame] | 1167 | // Number of interned strings in the pool. Includes the empty string w/ ID=0. |
| 1168 | size_t string_count() const { return string_pool_.size(); } |
| 1169 | |
Ioannis Ilkos | b8b1110 | 2019-01-29 17:56:55 +0000 | [diff] [blame] | 1170 | // Start / end ts (in nanoseconds) across the parsed trace events. |
| 1171 | // Returns (0, 0) if the trace is empty. |
| 1172 | std::pair<int64_t, int64_t> GetTraceTimestampBoundsNs() const; |
| 1173 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1174 | private: |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 1175 | static constexpr uint8_t kRowIdTableShift = 32; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 1176 | |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame] | 1177 | using StringHash = uint64_t; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1178 | |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 1179 | TraceStorage(const TraceStorage&) = delete; |
| 1180 | TraceStorage& operator=(const TraceStorage&) = delete; |
| 1181 | |
| 1182 | TraceStorage(TraceStorage&&) = default; |
| 1183 | TraceStorage& operator=(TraceStorage&&) = default; |
Lalit Maganti | 4fa7c6c | 2019-02-06 15:06:36 +0000 | [diff] [blame] | 1184 | |
Lalit Maganti | 05e8c13 | 2018-11-09 18:16:12 +0000 | [diff] [blame] | 1185 | // Stats about parsing the trace. |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 1186 | StatsMap stats_{}; |
Lalit Maganti | 35622b7 | 2018-06-06 12:03:11 +0100 | [diff] [blame] | 1187 | |
Ryan Savitski | 51413ad | 2019-07-09 14:25:21 +0100 | [diff] [blame] | 1188 | // Extra data extracted from the trace. Includes: |
| 1189 | // * metadata from chrome and benchmarking infrastructure |
| 1190 | // * descriptions of android packages |
| 1191 | Metadata metadata_{}; |
Mikhail Khokhlov | e466c00 | 2019-05-23 13:33:33 +0100 | [diff] [blame] | 1192 | |
Eric Seckler | 5703ede | 2019-07-10 10:13:02 +0100 | [diff] [blame] | 1193 | // Metadata for virtual slice tracks. |
| 1194 | VirtualTracks virtual_tracks_; |
| 1195 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1196 | // One entry for each CPU in the trace. |
Lalit Maganti | ff69c11 | 2018-09-24 12:07:47 +0100 | [diff] [blame] | 1197 | Slices slices_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1198 | |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 1199 | // Args for all other tables. |
| 1200 | Args args_; |
| 1201 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1202 | // One entry for each unique string in the trace. |
Lalit Maganti | 5c45431 | 2019-04-08 12:11:17 +0100 | [diff] [blame] | 1203 | StringPool string_pool_; |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 1204 | |
Isabelle Taylor | 47328cf | 2018-06-12 14:33:59 +0100 | [diff] [blame] | 1205 | // One entry for each UniquePid, with UniquePid as the index. |
Ioannis Ilkos | 9c03cbd | 2019-03-12 18:30:43 +0000 | [diff] [blame] | 1206 | // Never hold on to pointers to Process, as vector resize will |
| 1207 | // invalidate them. |
| 1208 | std::vector<Process> unique_processes_; |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 1209 | |
Isabelle Taylor | 68e4219 | 2018-06-19 16:19:31 +0100 | [diff] [blame] | 1210 | // One entry for each UniqueTid, with UniqueTid as the index. |
Isabelle Taylor | 3dd366c | 2018-06-22 16:21:41 +0100 | [diff] [blame] | 1211 | std::deque<Thread> unique_threads_; |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 1212 | |
| 1213 | // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros). |
| 1214 | NestableSlices nestable_slices_; |
Isabelle Taylor | 15314ea | 2018-09-19 11:35:19 +0100 | [diff] [blame] | 1215 | |
Eric Seckler | d3b89d5 | 2019-07-10 15:36:29 +0100 | [diff] [blame] | 1216 | // Additional attributes for threads slices (sub-type of NestableSlices). |
| 1217 | ThreadSlices thread_slices_; |
| 1218 | |
Eric Seckler | c3430c6 | 2019-07-22 10:49:58 +0100 | [diff] [blame^] | 1219 | // Additional attributes for virtual track slices (sub-type of |
| 1220 | // NestableSlices). |
| 1221 | VirtualTrackSlices virtual_track_slices_; |
| 1222 | |
Hector Dearman | 2442d61 | 2019-06-04 18:05:23 +0100 | [diff] [blame] | 1223 | // The type of counters in the trace. Can be thought of as the "metadata". |
Lalit Maganti | 8320e6d | 2019-03-14 18:49:33 +0000 | [diff] [blame] | 1224 | CounterDefinitions counter_definitions_; |
| 1225 | |
| 1226 | // The values from the Counter events from the trace. This includes CPU |
| 1227 | // frequency events as well systrace trace_marker counter events. |
| 1228 | CounterValues counter_values_; |
Primiano Tucci | 5cb84f8 | 2018-10-31 21:46:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | SqlStats sql_stats_; |
Lalit Maganti | 6e9c55e | 2018-11-29 12:00:39 +0000 | [diff] [blame] | 1231 | |
Isabelle Taylor | c8c1120 | 2018-11-05 11:36:22 +0000 | [diff] [blame] | 1232 | // These are instantaneous events in the trace. They have no duration |
| 1233 | // and do not have a value that make sense to track over time. |
| 1234 | // e.g. signal events |
| 1235 | Instants instants_; |
Lalit Maganti | 1d915a6 | 2019-01-07 12:10:42 +0000 | [diff] [blame] | 1236 | |
| 1237 | // Raw events are every ftrace event in the trace. The raw event includes |
| 1238 | // the timestamp and the pid. The args for the raw event will be in the |
| 1239 | // args table. This table can be used to generate a text version of the |
| 1240 | // trace. |
| 1241 | RawEvents raw_events_; |
Primiano Tucci | 2c761ef | 2019-01-07 20:20:46 +0000 | [diff] [blame] | 1242 | AndroidLogs android_log_; |
Florian Mayer | 438b5ab | 2019-05-02 11:18:06 +0100 | [diff] [blame] | 1243 | |
| 1244 | HeapProfileMappings heap_profile_mappings_; |
| 1245 | HeapProfileFrames heap_profile_frames_; |
| 1246 | HeapProfileCallsites heap_profile_callsites_; |
| 1247 | HeapProfileAllocations heap_profile_allocations_; |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1248 | }; |
| 1249 | |
| 1250 | } // namespace trace_processor |
| 1251 | } // namespace perfetto |
| 1252 | |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 1253 | namespace std { |
| 1254 | |
| 1255 | template <> |
| 1256 | struct hash<::perfetto::trace_processor::TraceStorage::HeapProfileFrames::Row> { |
| 1257 | using argument_type = |
| 1258 | ::perfetto::trace_processor::TraceStorage::HeapProfileFrames::Row; |
| 1259 | using result_type = size_t; |
| 1260 | |
| 1261 | result_type operator()(const argument_type& r) const { |
| 1262 | return std::hash<::perfetto::trace_processor::StringId>{}(r.name_id) ^ |
| 1263 | std::hash<int64_t>{}(r.mapping_row) ^ std::hash<int64_t>{}(r.rel_pc); |
| 1264 | } |
| 1265 | }; |
| 1266 | |
| 1267 | template <> |
| 1268 | struct hash< |
| 1269 | ::perfetto::trace_processor::TraceStorage::HeapProfileCallsites::Row> { |
| 1270 | using argument_type = |
| 1271 | ::perfetto::trace_processor::TraceStorage::HeapProfileCallsites::Row; |
| 1272 | using result_type = size_t; |
| 1273 | |
| 1274 | result_type operator()(const argument_type& r) const { |
| 1275 | return std::hash<int64_t>{}(r.depth) ^ std::hash<int64_t>{}(r.parent_id) ^ |
| 1276 | std::hash<int64_t>{}(r.frame_row); |
| 1277 | } |
| 1278 | }; |
| 1279 | |
| 1280 | template <> |
| 1281 | struct hash< |
| 1282 | ::perfetto::trace_processor::TraceStorage::HeapProfileMappings::Row> { |
| 1283 | using argument_type = |
| 1284 | ::perfetto::trace_processor::TraceStorage::HeapProfileMappings::Row; |
| 1285 | using result_type = size_t; |
| 1286 | |
| 1287 | result_type operator()(const argument_type& r) const { |
| 1288 | return std::hash<::perfetto::trace_processor::StringId>{}(r.build_id) ^ |
Florian Mayer | 1265573 | 2019-07-02 15:08:26 +0100 | [diff] [blame] | 1289 | std::hash<int64_t>{}(r.exact_offset) ^ |
| 1290 | std::hash<int64_t>{}(r.start_offset) ^ |
| 1291 | std::hash<int64_t>{}(r.start) ^ std::hash<int64_t>{}(r.end) ^ |
| 1292 | std::hash<int64_t>{}(r.load_bias) ^ |
Florian Mayer | bee5213 | 2019-05-02 13:59:56 +0100 | [diff] [blame] | 1293 | std::hash<::perfetto::trace_processor::StringId>{}(r.name_id); |
| 1294 | } |
| 1295 | }; |
| 1296 | |
| 1297 | } // namespace std |
| 1298 | |
Lalit Maganti | caed37e | 2018-06-01 03:03:08 +0100 | [diff] [blame] | 1299 | #endif // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_ |