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