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