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