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