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