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