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