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