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