blob: 081cffd10ccbbe38c16b50184115776febf58b7a [file] [log] [blame]
Lalit Maganticaed37e2018-06-01 03:03:08 +01001/*
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 Maganti35622b72018-06-06 12:03:11 +010020#include <array>
Lalit Maganticaed37e2018-06-01 03:03:08 +010021#include <deque>
Isabelle Taylor47328cf2018-06-12 14:33:59 +010022#include <map>
Lalit Maganticaed37e2018-06-01 03:03:08 +010023#include <string>
24#include <unordered_map>
Ioannis Ilkosb8b11102019-01-29 17:56:55 +000025#include <utility>
Lalit Maganticaed37e2018-06-01 03:03:08 +010026#include <vector>
27
Lalit Maganti35622b72018-06-06 12:03:11 +010028#include "perfetto/base/logging.h"
Eric Seckler83dcc8c2019-08-21 12:18:43 +010029#include "perfetto/base/time.h"
Primiano Tucci2c5488f2019-06-01 03:27:28 +010030#include "perfetto/ext/base/hash.h"
31#include "perfetto/ext/base/optional.h"
32#include "perfetto/ext/base/string_view.h"
Primiano Tucci2c5488f2019-06-01 03:27:28 +010033#include "perfetto/ext/base/utils.h"
Eric Secklerf93b8cf2019-11-20 21:33:01 +000034#include "perfetto/trace_processor/basic_types.h"
Lalit Maganti9ecfab32019-12-17 17:45:38 +000035#include "src/trace_processor/containers/string_pool.h"
Lalit Magantib0b53ee2019-01-24 17:53:39 +000036#include "src/trace_processor/ftrace_utils.h"
Mikhail Khokhlove466c002019-05-23 13:33:33 +010037#include "src/trace_processor/metadata.h"
Primiano Tucci0e38a142019-01-07 20:51:09 +000038#include "src/trace_processor/stats.h"
Lalit Maganti4b3b3ad2019-12-04 19:27:35 +000039#include "src/trace_processor/tables/counter_tables.h"
Ioannis Ilkose0b47f52019-09-18 11:14:57 +010040#include "src/trace_processor/tables/profiler_tables.h"
Lalit Maganti20539c22019-09-04 12:36:10 +010041#include "src/trace_processor/tables/slice_tables.h"
42#include "src/trace_processor/tables/track_tables.h"
Mikhail Khokhlov85a0dd02019-05-17 14:22:28 +010043#include "src/trace_processor/variadic.h"
Lalit Maganti35622b72018-06-06 12:03:11 +010044
Lalit Maganticaed37e2018-06-01 03:03:08 +010045namespace perfetto {
46namespace trace_processor {
47
Isabelle Taylora0a22972018-08-03 12:06:12 +010048// UniquePid is an offset into |unique_processes_|. This is necessary because
49// Unix pids are reused and thus not guaranteed to be unique over a long
50// period of time.
51using UniquePid = uint32_t;
Primiano Tucci0d72a312018-08-07 14:42:45 +010052
Isabelle Taylora0a22972018-08-03 12:06:12 +010053// UniqueTid is an offset into |unique_threads_|. Necessary because tids can
54// be reused.
55using UniqueTid = uint32_t;
56
Primiano Tucci0d72a312018-08-07 14:42:45 +010057// StringId is an offset into |string_pool_|.
Lalit Maganti5c454312019-04-08 12:11:17 +010058using StringId = StringPool::Id;
Lalit Maganti1a2936f2019-08-29 17:42:33 +010059static const StringId kNullStringId = StringId(0);
Primiano Tucci0d72a312018-08-07 14:42:45 +010060
Lalit Maganti5ea9e932018-11-30 14:19:39 +000061// Identifiers for all the tables in the database.
62enum TableId : uint8_t {
63 // Intentionally don't have TableId == 0 so that RowId == 0 can refer to an
64 // invalid row id.
Lalit Maganti8320e6d2019-03-14 18:49:33 +000065 kCounterValues = 1,
Lalit Maganti1d915a62019-01-07 12:10:42 +000066 kRawEvents = 2,
Lalit Maganti66ed7ad2019-01-11 16:47:26 +000067 kInstants = 3,
Isabelle Taylorb9222c32019-01-31 10:58:37 +000068 kSched = 4,
Eric Seckler70cc4422019-05-28 16:00:23 +010069 kNestableSlices = 5,
Ryan Savitski51413ad2019-07-09 14:25:21 +010070 kMetadataTable = 6,
Lalit Maganti53bdbb22019-09-25 11:11:18 +010071 kTrack = 7,
Mohammad Reza Zakerinasabb06d1852019-09-11 14:41:36 -040072 kVulkanMemoryAllocation = 8,
Lalit Maganti5ea9e932018-11-30 14:19:39 +000073};
74
75// The top 8 bits are set to the TableId and the bottom 32 to the row of the
76// table.
Lalit Maganti85ca4a82018-12-07 17:28:02 +000077using RowId = int64_t;
Lalit Maganti5ea9e932018-11-30 14:19:39 +000078static const RowId kInvalidRowId = 0;
79
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +000080using ArgSetId = uint32_t;
81static const ArgSetId kInvalidArgSetId = 0;
82
Eric Seckler5703ede2019-07-10 10:13:02 +010083using TrackId = uint32_t;
84
Lalit Maganti809b2f92019-11-07 13:27:26 +000085// TODO(lalitm): this is a temporary hack while migrating the counters table and
86// will be removed when the migration is complete.
87static const TrackId kInvalidTrackId = std::numeric_limits<TrackId>::max();
88
Lalit Maganti21b21632019-09-28 16:50:23 +010089enum class RefType {
Primiano Tucci5403e4f2018-11-27 10:07:03 +000090 kRefNoRef = 0,
91 kRefUtid = 1,
92 kRefCpuId = 2,
93 kRefIrq = 3,
94 kRefSoftIrq = 4,
95 kRefUpid = 5,
Sidath Senanayake1f5f93a2019-06-06 22:24:15 +010096 kRefGpuId = 6,
Eric Seckler5703ede2019-07-10 10:13:02 +010097 kRefTrack = 7,
Primiano Tucci5403e4f2018-11-27 10:07:03 +000098 kRefMax
Isabelle Taylora97c5f52018-10-23 17:36:12 +010099};
Isabelle Taylor14674d42018-09-07 11:33:11 +0100100
Lalit Magantib134d252019-12-10 12:21:27 +0000101const std::vector<NullTermStringView>& GetRefTypeStringMap();
Eric Seckler972225e2019-04-18 11:07:12 +0100102
Lalit Maganticaed37e2018-06-01 03:03:08 +0100103// Stores a data inside a trace file in a columnar form. This makes it efficient
104// to read or search across a single field of the trace (e.g. all the thread
105// names for a given CPU).
106class TraceStorage {
107 public:
Eric Secklerf93b8cf2019-11-20 21:33:01 +0000108 TraceStorage(const Config& = Config());
Isabelle Taylora0a22972018-08-03 12:06:12 +0100109
110 virtual ~TraceStorage();
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100111
Isabelle Taylora0a22972018-08-03 12:06:12 +0100112 // Information about a unique process seen in a trace.
113 struct Process {
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100114 explicit Process(uint32_t p) : pid(p) {}
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000115 int64_t start_ns = 0;
Lalit Maganti637589a2019-07-04 17:25:29 +0100116 int64_t end_ns = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100117 StringId name_id = 0;
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100118 uint32_t pid = 0;
Lalit Maganti369b0572019-07-11 15:35:09 +0100119 base::Optional<UniquePid> parent_upid;
Ioannis Ilkosfd554bc2019-11-16 01:14:57 +0000120 base::Optional<uint32_t> uid;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100121 };
122
123 // Information about a unique thread seen in a trace.
124 struct Thread {
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100125 explicit Thread(uint32_t t) : tid(t) {}
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000126 int64_t start_ns = 0;
Lalit Magantib5bd2332019-06-06 14:20:47 +0100127 int64_t end_ns = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100128 StringId name_id = 0;
Lalit Maganti770886a2018-11-16 17:40:21 +0000129 base::Optional<UniquePid> upid;
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100130 uint32_t tid = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100131 };
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100132
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000133 // Generic key value storage which can be referenced by other tables.
134 class Args {
135 public:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000136 struct Arg {
137 StringId flat_key = 0;
138 StringId key = 0;
139 Variadic value = Variadic::Integer(0);
140
141 // This is only used by the arg tracker and so is not part of the hash.
142 RowId row_id = 0;
143 };
144
145 struct ArgHasher {
146 uint64_t operator()(const Arg& arg) const noexcept {
Lalit Maganti1f464742019-02-28 13:49:31 +0000147 base::Hash hash;
148 hash.Update(arg.key);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000149 // We don't hash arg.flat_key because it's a subsequence of arg.key.
150 switch (arg.value.type) {
151 case Variadic::Type::kInt:
Lalit Maganti1f464742019-02-28 13:49:31 +0000152 hash.Update(arg.value.int_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000153 break;
Eric Secklerc93823e2019-06-03 16:49:19 +0100154 case Variadic::Type::kUint:
155 hash.Update(arg.value.uint_value);
156 break;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000157 case Variadic::Type::kString:
Lalit Maganti1f464742019-02-28 13:49:31 +0000158 hash.Update(arg.value.string_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000159 break;
160 case Variadic::Type::kReal:
Lalit Maganti1f464742019-02-28 13:49:31 +0000161 hash.Update(arg.value.real_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000162 break;
Eric Secklerc93823e2019-06-03 16:49:19 +0100163 case Variadic::Type::kPointer:
164 hash.Update(arg.value.pointer_value);
165 break;
166 case Variadic::Type::kBool:
167 hash.Update(arg.value.bool_value);
168 break;
169 case Variadic::Type::kJson:
170 hash.Update(arg.value.json_value);
171 break;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000172 }
Lalit Maganti1f464742019-02-28 13:49:31 +0000173 return hash.digest();
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000174 }
175 };
176
177 const std::deque<ArgSetId>& set_ids() const { return set_ids_; }
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000178 const std::deque<StringId>& flat_keys() const { return flat_keys_; }
179 const std::deque<StringId>& keys() const { return keys_; }
Lalit Maganti1d915a62019-01-07 12:10:42 +0000180 const std::deque<Variadic>& arg_values() const { return arg_values_; }
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000181 uint32_t args_count() const {
182 return static_cast<uint32_t>(set_ids_.size());
Lalit Maganti79472be2018-12-04 13:41:27 +0000183 }
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000184
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000185 ArgSetId AddArgSet(const std::vector<Arg>& args,
186 uint32_t begin,
187 uint32_t end) {
Lalit Maganti1f464742019-02-28 13:49:31 +0000188 base::Hash hash;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000189 for (uint32_t i = begin; i < end; i++) {
Lalit Maganti1f464742019-02-28 13:49:31 +0000190 hash.Update(ArgHasher()(args[i]));
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000191 }
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000192
Lalit Maganti1f464742019-02-28 13:49:31 +0000193 ArgSetHash digest = hash.digest();
194 auto it = arg_row_for_hash_.find(digest);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000195 if (it != arg_row_for_hash_.end()) {
196 return set_ids_[it->second];
197 }
198
199 // The +1 ensures that nothing has an id == kInvalidArgSetId == 0.
200 ArgSetId id = static_cast<uint32_t>(arg_row_for_hash_.size()) + 1;
Lalit Maganti1f464742019-02-28 13:49:31 +0000201 arg_row_for_hash_.emplace(digest, args_count());
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000202 for (uint32_t i = begin; i < end; i++) {
203 const auto& arg = args[i];
204 set_ids_.emplace_back(id);
205 flat_keys_.emplace_back(arg.flat_key);
206 keys_.emplace_back(arg.key);
207 arg_values_.emplace_back(arg.value);
208 }
209 return id;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000210 }
211
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000212 private:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000213 using ArgSetHash = uint64_t;
214
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000215 std::deque<ArgSetId> set_ids_;
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000216 std::deque<StringId> flat_keys_;
217 std::deque<StringId> keys_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000218 std::deque<Variadic> arg_values_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000219
220 std::unordered_map<ArgSetHash, uint32_t> arg_row_for_hash_;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000221 };
222
Lalit Magantid11d3e02019-07-26 12:32:09 +0530223 class Tracks {
224 public:
225 inline uint32_t AddTrack(StringId name) {
226 names_.emplace_back(name);
227 return track_count() - 1;
228 }
229
230 uint32_t track_count() const {
231 return static_cast<uint32_t>(names_.size());
232 }
233
234 const std::deque<StringId>& names() const { return names_; }
235
236 private:
237 std::deque<StringId> names_;
238 };
239
Mikael Pessa803090c2019-08-23 16:03:34 -0700240 class GpuContexts {
241 public:
242 inline void AddGpuContext(uint64_t context_id,
243 UniquePid upid,
244 uint32_t priority) {
245 context_ids_.emplace_back(context_id);
246 upids_.emplace_back(upid);
247 priorities_.emplace_back(priority);
248 }
249
250 uint32_t gpu_context_count() const {
251 return static_cast<uint32_t>(context_ids_.size());
252 }
253
254 const std::deque<uint64_t>& context_ids() const { return context_ids_; }
255 const std::deque<UniquePid>& upids() const { return upids_; }
256 const std::deque<uint32_t>& priorities() const { return priorities_; }
257
258 private:
259 std::deque<uint64_t> context_ids_;
260 std::deque<UniquePid> upids_;
261 std::deque<uint32_t> priorities_;
262 };
263
Lalit Magantiff69c112018-09-24 12:07:47 +0100264 class Slices {
Lalit Maganti35622b72018-06-06 12:03:11 +0100265 public:
Lalit Magantifde29042018-10-04 13:28:52 +0100266 inline size_t AddSlice(uint32_t cpu,
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000267 int64_t start_ns,
268 int64_t duration_ns,
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000269 UniqueTid utid,
270 ftrace_utils::TaskState end_state,
271 int32_t priority) {
Lalit Magantiff69c112018-09-24 12:07:47 +0100272 cpus_.emplace_back(cpu);
Lalit Maganti35622b72018-06-06 12:03:11 +0100273 start_ns_.emplace_back(start_ns);
274 durations_.emplace_back(duration_ns);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100275 utids_.emplace_back(utid);
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000276 end_states_.emplace_back(end_state);
277 priorities_.emplace_back(priority);
Lalit Maganti58638932019-01-31 10:48:26 +0000278
279 if (utid >= rows_for_utids_.size())
280 rows_for_utids_.resize(utid + 1);
281 rows_for_utids_[utid].emplace_back(slice_count() - 1);
Lalit Magantifde29042018-10-04 13:28:52 +0100282 return slice_count() - 1;
283 }
284
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000285 void set_duration(size_t index, int64_t duration_ns) {
Lalit Magantifde29042018-10-04 13:28:52 +0100286 durations_[index] = duration_ns;
Lalit Maganti35622b72018-06-06 12:03:11 +0100287 }
288
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000289 void set_end_state(size_t index, ftrace_utils::TaskState end_state) {
290 end_states_[index] = end_state;
291 }
292
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100293 size_t slice_count() const { return start_ns_.size(); }
Lalit Maganti35622b72018-06-06 12:03:11 +0100294
Lalit Magantiff69c112018-09-24 12:07:47 +0100295 const std::deque<uint32_t>& cpus() const { return cpus_; }
296
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000297 const std::deque<int64_t>& start_ns() const { return start_ns_; }
Lalit Maganti35622b72018-06-06 12:03:11 +0100298
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000299 const std::deque<int64_t>& durations() const { return durations_; }
Lalit Maganti35622b72018-06-06 12:03:11 +0100300
Isabelle Taylor68e42192018-06-19 16:19:31 +0100301 const std::deque<UniqueTid>& utids() const { return utids_; }
302
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000303 const std::deque<ftrace_utils::TaskState>& end_state() const {
304 return end_states_;
305 }
306
307 const std::deque<int32_t>& priorities() const { return priorities_; }
308
Lalit Maganti58638932019-01-31 10:48:26 +0000309 const std::deque<std::vector<uint32_t>>& rows_for_utids() const {
Lalit Magantif0f09c32019-01-18 17:29:31 +0000310 return rows_for_utids_;
311 }
312
Lalit Maganti35622b72018-06-06 12:03:11 +0100313 private:
Hector Dearman947f12a2018-09-11 16:50:36 +0100314 // Each deque below has the same number of entries (the number of slices
Lalit Maganti35622b72018-06-06 12:03:11 +0100315 // in the trace for the CPU).
Lalit Magantiff69c112018-09-24 12:07:47 +0100316 std::deque<uint32_t> cpus_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000317 std::deque<int64_t> start_ns_;
318 std::deque<int64_t> durations_;
Isabelle Taylor68e42192018-06-19 16:19:31 +0100319 std::deque<UniqueTid> utids_;
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000320 std::deque<ftrace_utils::TaskState> end_states_;
321 std::deque<int32_t> priorities_;
Lalit Maganti58638932019-01-31 10:48:26 +0000322
323 // One row per utid.
324 std::deque<std::vector<uint32_t>> rows_for_utids_;
Primiano Tucci0d72a312018-08-07 14:42:45 +0100325 };
Isabelle Taylor68e42192018-06-19 16:19:31 +0100326
Eric Secklerd3b89d52019-07-10 15:36:29 +0100327 class ThreadSlices {
328 public:
329 inline uint32_t AddThreadSlice(uint32_t slice_id,
330 int64_t thread_timestamp_ns,
331 int64_t thread_duration_ns,
332 int64_t thread_instruction_count,
333 int64_t thread_instruction_delta) {
334 slice_ids_.emplace_back(slice_id);
335 thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
336 thread_duration_ns_.emplace_back(thread_duration_ns);
337 thread_instruction_counts_.emplace_back(thread_instruction_count);
338 thread_instruction_deltas_.emplace_back(thread_instruction_delta);
339 return slice_count() - 1;
340 }
341
Eric Secklerc3430c62019-07-22 10:49:58 +0100342 uint32_t slice_count() const {
343 return static_cast<uint32_t>(slice_ids_.size());
Eric Secklerd3b89d52019-07-10 15:36:29 +0100344 }
345
Eric Secklerc3430c62019-07-22 10:49:58 +0100346 const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
347 const std::deque<int64_t>& thread_timestamp_ns() const {
348 return thread_timestamp_ns_;
349 }
350 const std::deque<int64_t>& thread_duration_ns() const {
351 return thread_duration_ns_;
352 }
353 const std::deque<int64_t>& thread_instruction_counts() const {
354 return thread_instruction_counts_;
355 }
356 const std::deque<int64_t>& thread_instruction_deltas() const {
357 return thread_instruction_deltas_;
358 }
359
360 base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const {
361 auto it =
362 std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
363 if (it != slice_ids().end() && *it == slice_id) {
364 return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
365 }
366 return base::nullopt;
367 }
368
Eric Seckler54f30a32019-07-19 15:10:29 +0100369 void UpdateThreadDeltasForSliceId(uint32_t slice_id,
370 int64_t end_thread_timestamp_ns,
371 int64_t end_thread_instruction_count) {
Eric Secklerc3430c62019-07-22 10:49:58 +0100372 uint32_t row = *FindRowForSliceId(slice_id);
373 int64_t begin_ns = thread_timestamp_ns_[row];
374 thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
Eric Seckler54f30a32019-07-19 15:10:29 +0100375 int64_t begin_ticount = thread_instruction_counts_[row];
376 thread_instruction_deltas_[row] =
377 end_thread_instruction_count - begin_ticount;
Eric Secklerc3430c62019-07-22 10:49:58 +0100378 }
379
380 private:
381 std::deque<uint32_t> slice_ids_;
382 std::deque<int64_t> thread_timestamp_ns_;
383 std::deque<int64_t> thread_duration_ns_;
384 std::deque<int64_t> thread_instruction_counts_;
385 std::deque<int64_t> thread_instruction_deltas_;
386 };
387
388 class VirtualTrackSlices {
389 public:
390 inline uint32_t AddVirtualTrackSlice(uint32_t slice_id,
391 int64_t thread_timestamp_ns,
392 int64_t thread_duration_ns,
393 int64_t thread_instruction_count,
394 int64_t thread_instruction_delta) {
395 slice_ids_.emplace_back(slice_id);
396 thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
397 thread_duration_ns_.emplace_back(thread_duration_ns);
398 thread_instruction_counts_.emplace_back(thread_instruction_count);
399 thread_instruction_deltas_.emplace_back(thread_instruction_delta);
400 return slice_count() - 1;
Eric Secklerd3b89d52019-07-10 15:36:29 +0100401 }
402
403 uint32_t slice_count() const {
404 return static_cast<uint32_t>(slice_ids_.size());
405 }
406
407 const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
408 const std::deque<int64_t>& thread_timestamp_ns() const {
409 return thread_timestamp_ns_;
410 }
411 const std::deque<int64_t>& thread_duration_ns() const {
412 return thread_duration_ns_;
413 }
414 const std::deque<int64_t>& thread_instruction_counts() const {
415 return thread_instruction_counts_;
416 }
417 const std::deque<int64_t>& thread_instruction_deltas() const {
418 return thread_instruction_deltas_;
419 }
420
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100421 base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const {
Eric Secklerd3b89d52019-07-10 15:36:29 +0100422 auto it =
423 std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100424 if (it != slice_ids().end() && *it == slice_id) {
425 return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
426 }
427 return base::nullopt;
Eric Secklerd3b89d52019-07-10 15:36:29 +0100428 }
429
Eric Seckler54f30a32019-07-19 15:10:29 +0100430 void UpdateThreadDeltasForSliceId(uint32_t slice_id,
431 int64_t end_thread_timestamp_ns,
432 int64_t end_thread_instruction_count) {
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100433 uint32_t row = *FindRowForSliceId(slice_id);
Eric Secklerd3b89d52019-07-10 15:36:29 +0100434 int64_t begin_ns = thread_timestamp_ns_[row];
435 thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
Eric Seckler54f30a32019-07-19 15:10:29 +0100436 int64_t begin_ticount = thread_instruction_counts_[row];
437 thread_instruction_deltas_[row] =
438 end_thread_instruction_count - begin_ticount;
Eric Secklerd3b89d52019-07-10 15:36:29 +0100439 }
440
441 private:
442 std::deque<uint32_t> slice_ids_;
443 std::deque<int64_t> thread_timestamp_ns_;
444 std::deque<int64_t> thread_duration_ns_;
445 std::deque<int64_t> thread_instruction_counts_;
446 std::deque<int64_t> thread_instruction_deltas_;
447 };
448
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700449 class SqlStats {
450 public:
451 static constexpr size_t kMaxLogEntries = 100;
Lalit Magantiaac2f652019-04-30 12:16:21 +0100452 uint32_t RecordQueryBegin(const std::string& query,
453 int64_t time_queued,
454 int64_t time_started);
455 void RecordQueryFirstNext(uint32_t row, int64_t time_first_next);
456 void RecordQueryEnd(uint32_t row, int64_t time_end);
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700457 size_t size() const { return queries_.size(); }
458 const std::deque<std::string>& queries() const { return queries_; }
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000459 const std::deque<int64_t>& times_queued() const { return times_queued_; }
460 const std::deque<int64_t>& times_started() const { return times_started_; }
Lalit Magantiaac2f652019-04-30 12:16:21 +0100461 const std::deque<int64_t>& times_first_next() const {
462 return times_first_next_;
463 }
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000464 const std::deque<int64_t>& times_ended() const { return times_ended_; }
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700465
466 private:
Lalit Magantiaac2f652019-04-30 12:16:21 +0100467 uint32_t popped_queries_ = 0;
468
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700469 std::deque<std::string> queries_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000470 std::deque<int64_t> times_queued_;
471 std::deque<int64_t> times_started_;
Lalit Magantiaac2f652019-04-30 12:16:21 +0100472 std::deque<int64_t> times_first_next_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000473 std::deque<int64_t> times_ended_;
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700474 };
475
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000476 class Instants {
477 public:
Lalit Maganti66ed7ad2019-01-11 16:47:26 +0000478 inline uint32_t AddInstantEvent(int64_t timestamp,
479 StringId name_id,
480 double value,
481 int64_t ref,
482 RefType type) {
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000483 timestamps_.emplace_back(timestamp);
484 name_ids_.emplace_back(name_id);
485 values_.emplace_back(value);
486 refs_.emplace_back(ref);
487 types_.emplace_back(type);
Lalit Maganti1c21d172019-02-07 10:48:24 +0000488 arg_set_ids_.emplace_back(kInvalidArgSetId);
Lalit Maganti66ed7ad2019-01-11 16:47:26 +0000489 return static_cast<uint32_t>(instant_count() - 1);
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000490 }
491
Lalit Maganti521d97b2019-04-29 13:47:03 +0100492 void set_ref(uint32_t row, int64_t ref) { refs_[row] = ref; }
493
Lalit Maganti1c21d172019-02-07 10:48:24 +0000494 void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; }
495
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000496 size_t instant_count() const { return timestamps_.size(); }
497
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000498 const std::deque<int64_t>& timestamps() const { return timestamps_; }
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000499
500 const std::deque<StringId>& name_ids() const { return name_ids_; }
501
502 const std::deque<double>& values() const { return values_; }
503
504 const std::deque<int64_t>& refs() const { return refs_; }
505
506 const std::deque<RefType>& types() const { return types_; }
507
Lalit Maganti1c21d172019-02-07 10:48:24 +0000508 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
509
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000510 private:
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000511 std::deque<int64_t> timestamps_;
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000512 std::deque<StringId> name_ids_;
513 std::deque<double> values_;
514 std::deque<int64_t> refs_;
515 std::deque<RefType> types_;
Lalit Maganti1c21d172019-02-07 10:48:24 +0000516 std::deque<ArgSetId> arg_set_ids_;
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000517 };
518
Lalit Maganti1d915a62019-01-07 12:10:42 +0000519 class RawEvents {
520 public:
521 inline RowId AddRawEvent(int64_t timestamp,
522 StringId name_id,
Lalit Magantie87cc812019-01-10 15:20:06 +0000523 uint32_t cpu,
Lalit Maganti1d915a62019-01-07 12:10:42 +0000524 UniqueTid utid) {
525 timestamps_.emplace_back(timestamp);
526 name_ids_.emplace_back(name_id);
Lalit Magantie87cc812019-01-10 15:20:06 +0000527 cpus_.emplace_back(cpu);
Lalit Maganti1d915a62019-01-07 12:10:42 +0000528 utids_.emplace_back(utid);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000529 arg_set_ids_.emplace_back(kInvalidArgSetId);
Lalit Maganti1d915a62019-01-07 12:10:42 +0000530 return CreateRowId(TableId::kRawEvents,
531 static_cast<uint32_t>(raw_event_count() - 1));
532 }
533
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000534 void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; }
535
Lalit Maganti1d915a62019-01-07 12:10:42 +0000536 size_t raw_event_count() const { return timestamps_.size(); }
537
538 const std::deque<int64_t>& timestamps() const { return timestamps_; }
539
540 const std::deque<StringId>& name_ids() const { return name_ids_; }
541
Lalit Magantie87cc812019-01-10 15:20:06 +0000542 const std::deque<uint32_t>& cpus() const { return cpus_; }
543
Lalit Maganti1d915a62019-01-07 12:10:42 +0000544 const std::deque<UniqueTid>& utids() const { return utids_; }
545
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000546 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
547
Lalit Maganti1d915a62019-01-07 12:10:42 +0000548 private:
549 std::deque<int64_t> timestamps_;
550 std::deque<StringId> name_ids_;
Lalit Magantie87cc812019-01-10 15:20:06 +0000551 std::deque<uint32_t> cpus_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000552 std::deque<UniqueTid> utids_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000553 std::deque<ArgSetId> arg_set_ids_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000554 };
555
Primiano Tucci2c761ef2019-01-07 20:20:46 +0000556 class AndroidLogs {
557 public:
558 inline size_t AddLogEvent(int64_t timestamp,
559 UniqueTid utid,
560 uint8_t prio,
561 StringId tag_id,
562 StringId msg_id) {
563 timestamps_.emplace_back(timestamp);
564 utids_.emplace_back(utid);
565 prios_.emplace_back(prio);
566 tag_ids_.emplace_back(tag_id);
567 msg_ids_.emplace_back(msg_id);
568 return size() - 1;
569 }
570
571 size_t size() const { return timestamps_.size(); }
572
573 const std::deque<int64_t>& timestamps() const { return timestamps_; }
574 const std::deque<UniqueTid>& utids() const { return utids_; }
575 const std::deque<uint8_t>& prios() const { return prios_; }
576 const std::deque<StringId>& tag_ids() const { return tag_ids_; }
577 const std::deque<StringId>& msg_ids() const { return msg_ids_; }
578
579 private:
580 std::deque<int64_t> timestamps_;
581 std::deque<UniqueTid> utids_;
582 std::deque<uint8_t> prios_;
583 std::deque<StringId> tag_ids_;
584 std::deque<StringId> msg_ids_;
585 };
586
Primiano Tucci0e38a142019-01-07 20:51:09 +0000587 struct Stats {
588 using IndexMap = std::map<int, int64_t>;
589 int64_t value = 0;
590 IndexMap indexed_values;
591 };
592 using StatsMap = std::array<Stats, stats::kNumKeys>;
593
Ryan Savitski51413ad2019-07-09 14:25:21 +0100594 class Metadata {
595 public:
596 const std::deque<metadata::KeyIDs>& keys() const { return keys_; }
597 const std::deque<Variadic>& values() const { return values_; }
598
599 RowId SetScalarMetadata(metadata::KeyIDs key, Variadic value) {
600 PERFETTO_DCHECK(key < metadata::kNumKeys);
601 PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kSingle);
602 PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]);
603
604 // Already set - on release builds, overwrite the previous value.
605 auto it = scalar_indices.find(key);
606 if (it != scalar_indices.end()) {
607 PERFETTO_DFATAL("Setting a scalar metadata entry more than once.");
608 uint32_t index = static_cast<uint32_t>(it->second);
609 values_[index] = value;
610 return TraceStorage::CreateRowId(kMetadataTable, index);
611 }
612 // First time setting this key.
613 keys_.push_back(key);
614 values_.push_back(value);
615 uint32_t index = static_cast<uint32_t>(keys_.size() - 1);
616 scalar_indices[key] = index;
617 return TraceStorage::CreateRowId(kMetadataTable, index);
618 }
619
620 RowId AppendMetadata(metadata::KeyIDs key, Variadic value) {
621 PERFETTO_DCHECK(key < metadata::kNumKeys);
622 PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kMulti);
623 PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]);
624
625 keys_.push_back(key);
626 values_.push_back(value);
627 uint32_t index = static_cast<uint32_t>(keys_.size() - 1);
628 return TraceStorage::CreateRowId(kMetadataTable, index);
629 }
630
Isabelle Taylor13a75852019-11-20 10:29:40 +0000631 const Variadic& GetScalarMetadata(metadata::KeyIDs key) const {
632 PERFETTO_DCHECK(scalar_indices.count(key) == 1);
633 return values_.at(scalar_indices.at(key));
634 }
635
636 bool MetadataExists(metadata::KeyIDs key) const {
637 return scalar_indices.count(key) >= 1;
638 }
639
Ryan Savitski0476ee92019-07-09 14:29:33 +0100640 void OverwriteMetadata(uint32_t index, Variadic value) {
641 PERFETTO_DCHECK(index < values_.size());
642 values_[index] = value;
643 }
644
Ryan Savitski51413ad2019-07-09 14:25:21 +0100645 private:
646 std::deque<metadata::KeyIDs> keys_;
647 std::deque<Variadic> values_;
648 // Extraneous state to track locations of entries that should have at most
649 // one row. Used only to maintain uniqueness during insertions.
650 std::map<metadata::KeyIDs, uint32_t> scalar_indices;
651 };
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100652
Oystein Eftevaag5419c582019-08-21 13:58:49 -0700653 class StackProfileFrames {
Florian Mayer438b5ab2019-05-02 11:18:06 +0100654 public:
Florian Mayerbee52132019-05-02 13:59:56 +0100655 struct Row {
656 StringId name_id;
657 int64_t mapping_row;
658 int64_t rel_pc;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100659
Florian Mayerbee52132019-05-02 13:59:56 +0100660 bool operator==(const Row& other) const {
661 return std::tie(name_id, mapping_row, rel_pc) ==
662 std::tie(other.name_id, other.mapping_row, other.rel_pc);
663 }
664 };
665
Lalit Maganti9b2d52b2019-05-07 14:32:15 +0100666 uint32_t size() const { return static_cast<uint32_t>(names_.size()); }
667
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +0100668 uint32_t Insert(const Row& row) {
Florian Mayerbee52132019-05-02 13:59:56 +0100669 names_.emplace_back(row.name_id);
670 mappings_.emplace_back(row.mapping_row);
671 rel_pcs_.emplace_back(row.rel_pc);
Ioannis Ilkose0b47f52019-09-18 11:14:57 +0100672 symbol_set_ids_.emplace_back(0);
Florian Mayera480cd62019-09-24 10:36:56 +0100673 size_t row_number = names_.size() - 1;
Oystein Eftevaag5a76f102019-11-07 10:18:16 -0800674 index_[std::make_pair(row.mapping_row, row.rel_pc)].emplace_back(
675 row_number);
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +0100676 return static_cast<uint32_t>(row_number);
Florian Mayera480cd62019-09-24 10:36:56 +0100677 }
678
Oystein Eftevaag5a76f102019-11-07 10:18:16 -0800679 std::vector<int64_t> FindFrameRow(size_t mapping_row,
680 uint64_t rel_pc) const {
Florian Mayera480cd62019-09-24 10:36:56 +0100681 auto it = index_.find(std::make_pair(mapping_row, rel_pc));
682 if (it == index_.end())
Oystein Eftevaag5a76f102019-11-07 10:18:16 -0800683 return {};
684 return it->second;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100685 }
686
Ioannis Ilkose0b47f52019-09-18 11:14:57 +0100687 void SetSymbolSetId(size_t row_idx, uint32_t symbol_set_id) {
688 PERFETTO_CHECK(row_idx < symbol_set_ids_.size());
689 symbol_set_ids_[row_idx] = symbol_set_id;
Ioannis Ilkose6727552019-08-14 15:10:59 +0100690 }
691
Florian Mayer438b5ab2019-05-02 11:18:06 +0100692 const std::deque<StringId>& names() const { return names_; }
693 const std::deque<int64_t>& mappings() const { return mappings_; }
694 const std::deque<int64_t>& rel_pcs() const { return rel_pcs_; }
Ioannis Ilkose0b47f52019-09-18 11:14:57 +0100695 const std::deque<uint32_t>& symbol_set_ids() const {
696 return symbol_set_ids_;
697 }
Florian Mayer438b5ab2019-05-02 11:18:06 +0100698
699 private:
700 std::deque<StringId> names_;
701 std::deque<int64_t> mappings_;
702 std::deque<int64_t> rel_pcs_;
Ioannis Ilkose0b47f52019-09-18 11:14:57 +0100703 std::deque<uint32_t> symbol_set_ids_;
Florian Mayera480cd62019-09-24 10:36:56 +0100704
Oystein Eftevaag5a76f102019-11-07 10:18:16 -0800705 std::map<std::pair<size_t /* mapping row */, uint64_t /* rel_pc */>,
706 std::vector<int64_t>>
Florian Mayera480cd62019-09-24 10:36:56 +0100707 index_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100708 };
709
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100710 UniqueTid AddEmptyThread(uint32_t tid) {
711 unique_threads_.emplace_back(tid);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100712 return static_cast<UniqueTid>(unique_threads_.size() - 1);
713 }
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100714
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100715 UniquePid AddEmptyProcess(uint32_t pid) {
716 unique_processes_.emplace_back(pid);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100717 return static_cast<UniquePid>(unique_processes_.size() - 1);
718 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100719
Isabelle Taylora0a22972018-08-03 12:06:12 +0100720 // Return an unqiue identifier for the contents of each string.
721 // The string is copied internally and can be destroyed after this called.
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100722 // Virtual for testing.
Lalit Maganti5c454312019-04-08 12:11:17 +0100723 virtual StringId InternString(base::StringView str) {
724 return string_pool_.InternString(str);
725 }
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100726
Isabelle Taylora0a22972018-08-03 12:06:12 +0100727 Process* GetMutableProcess(UniquePid upid) {
Lalit Maganti676658b2018-11-20 18:24:31 +0000728 PERFETTO_DCHECK(upid < unique_processes_.size());
Isabelle Taylora0a22972018-08-03 12:06:12 +0100729 return &unique_processes_[upid];
730 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100731
Isabelle Taylora0a22972018-08-03 12:06:12 +0100732 Thread* GetMutableThread(UniqueTid utid) {
Florian Mayera1aaec22018-09-19 17:02:26 +0100733 PERFETTO_DCHECK(utid < unique_threads_.size());
Isabelle Taylora0a22972018-08-03 12:06:12 +0100734 return &unique_threads_[utid];
735 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100736
Primiano Tucci0e38a142019-01-07 20:51:09 +0000737 // Example usage: SetStats(stats::android_log_num_failed, 42);
738 void SetStats(size_t key, int64_t value) {
739 PERFETTO_DCHECK(key < stats::kNumKeys);
740 PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
741 stats_[key].value = value;
742 }
743
744 // Example usage: IncrementStats(stats::android_log_num_failed, -1);
745 void IncrementStats(size_t key, int64_t increment = 1) {
746 PERFETTO_DCHECK(key < stats::kNumKeys);
747 PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
748 stats_[key].value += increment;
749 }
750
Florian Mayer438b5ab2019-05-02 11:18:06 +0100751 // Example usage: IncrementIndexedStats(stats::cpu_failure, 1);
752 void IncrementIndexedStats(size_t key, int index, int64_t increment = 1) {
753 PERFETTO_DCHECK(key < stats::kNumKeys);
754 PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
755 stats_[key].indexed_values[index] += increment;
756 }
757
Primiano Tucci0e38a142019-01-07 20:51:09 +0000758 // Example usage: SetIndexedStats(stats::cpu_failure, 1, 42);
759 void SetIndexedStats(size_t key, int index, int64_t value) {
760 PERFETTO_DCHECK(key < stats::kNumKeys);
761 PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
762 stats_[key].indexed_values[index] = value;
763 }
764
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100765 // Example usage:
766 // SetMetadata(metadata::benchmark_name,
767 // Variadic::String(storage->InternString("foo"));
Ryan Savitski51413ad2019-07-09 14:25:21 +0100768 // Returns the RowId of the new entry.
Mikhail Khokhlovb1fe42a2019-05-23 13:58:05 +0100769 // Virtual for testing.
Ryan Savitski51413ad2019-07-09 14:25:21 +0100770 virtual RowId SetMetadata(metadata::KeyIDs key, Variadic value) {
771 return metadata_.SetScalarMetadata(key, value);
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100772 }
773
774 // Example usage:
775 // AppendMetadata(metadata::benchmark_story_tags,
776 // Variadic::String(storage->InternString("bar"));
Ryan Savitski51413ad2019-07-09 14:25:21 +0100777 // Returns the RowId of the new entry.
Mikhail Khokhlovb1fe42a2019-05-23 13:58:05 +0100778 // Virtual for testing.
Ryan Savitski51413ad2019-07-09 14:25:21 +0100779 virtual RowId AppendMetadata(metadata::KeyIDs key, Variadic value) {
780 return metadata_.AppendMetadata(key, value);
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100781 }
782
Eric Seckler77b52782019-05-02 15:18:57 +0100783 class ScopedStatsTracer {
784 public:
785 ScopedStatsTracer(TraceStorage* storage, size_t key)
786 : storage_(storage), key_(key), start_ns_(base::GetWallTimeNs()) {}
787
788 ~ScopedStatsTracer() {
789 if (!storage_)
790 return;
791 auto delta_ns = base::GetWallTimeNs() - start_ns_;
792 storage_->IncrementStats(key_, delta_ns.count());
793 }
794
795 ScopedStatsTracer(ScopedStatsTracer&& other) noexcept { MoveImpl(&other); }
796
797 ScopedStatsTracer& operator=(ScopedStatsTracer&& other) {
798 MoveImpl(&other);
799 return *this;
800 }
801
802 private:
803 ScopedStatsTracer(const ScopedStatsTracer&) = delete;
804 ScopedStatsTracer& operator=(const ScopedStatsTracer&) = delete;
805
806 void MoveImpl(ScopedStatsTracer* other) {
807 storage_ = other->storage_;
808 key_ = other->key_;
809 start_ns_ = other->start_ns_;
810 other->storage_ = nullptr;
811 }
812
813 TraceStorage* storage_;
814 size_t key_;
815 base::TimeNanos start_ns_;
816 };
817
818 ScopedStatsTracer TraceExecutionTimeIntoStats(size_t key) {
819 return ScopedStatsTracer(this, key);
820 }
821
Lalit Maganticaed37e2018-06-01 03:03:08 +0100822 // Reading methods.
Eric Secklerc93823e2019-06-03 16:49:19 +0100823 // Virtual for testing.
824 virtual NullTermStringView GetString(StringId id) const {
Lalit Maganti5c454312019-04-08 12:11:17 +0100825 return string_pool_.Get(id);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100826 }
827
Lalit Magantie9d40532018-06-29 13:15:06 +0100828 const Process& GetProcess(UniquePid upid) const {
Lalit Maganti676658b2018-11-20 18:24:31 +0000829 PERFETTO_DCHECK(upid < unique_processes_.size());
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100830 return unique_processes_[upid];
831 }
832
Eric Secklerb32cacf2019-09-27 16:51:19 +0100833 // Virtual for testing.
834 virtual const Thread& GetThread(UniqueTid utid) const {
Lalit Maganti1f64cfa2018-09-18 13:20:02 +0100835 // Allow utid == 0 for idle thread retrieval.
Florian Mayera1aaec22018-09-19 17:02:26 +0100836 PERFETTO_DCHECK(utid < unique_threads_.size());
Isabelle Taylor68e42192018-06-19 16:19:31 +0100837 return unique_threads_[utid];
838 }
839
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000840 static RowId CreateRowId(TableId table, uint32_t row) {
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000841 return (static_cast<RowId>(table) << kRowIdTableShift) | row;
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000842 }
843
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000844 static std::pair<int8_t /*table*/, uint32_t /*row*/> ParseRowId(RowId rowid) {
845 auto id = static_cast<uint64_t>(rowid);
846 auto table_id = static_cast<uint8_t>(id >> kRowIdTableShift);
847 auto row = static_cast<uint32_t>(id & ((1ull << kRowIdTableShift) - 1));
848 return std::make_pair(table_id, row);
849 }
850
Lalit Magantiac68e9c2019-09-09 18:12:15 +0100851 const tables::TrackTable& track_table() const { return track_table_; }
852 tables::TrackTable* mutable_track_table() { return &track_table_; }
Lalit Magantid11d3e02019-07-26 12:32:09 +0530853
Lalit Maganti53bdbb22019-09-25 11:11:18 +0100854 const tables::ProcessTrackTable& process_track_table() const {
855 return process_track_table_;
Lalit Maganti4ea78d92019-09-20 20:20:41 +0100856 }
Lalit Maganti53bdbb22019-09-25 11:11:18 +0100857 tables::ProcessTrackTable* mutable_process_track_table() {
858 return &process_track_table_;
Lalit Maganti4ea78d92019-09-20 20:20:41 +0100859 }
Eric Seckler5703ede2019-07-10 10:13:02 +0100860
Lalit Magantifedc15b2019-09-26 18:37:52 +0100861 const tables::ThreadTrackTable& thread_track_table() const {
862 return thread_track_table_;
863 }
864 tables::ThreadTrackTable* mutable_thread_track_table() {
865 return &thread_track_table_;
866 }
867
Lalit Maganti809b2f92019-11-07 13:27:26 +0000868 const tables::CounterTrackTable& counter_track_table() const {
869 return counter_track_table_;
870 }
871 tables::CounterTrackTable* mutable_counter_track_table() {
872 return &counter_track_table_;
873 }
874
875 const tables::ThreadCounterTrackTable& thread_counter_track_table() const {
876 return thread_counter_track_table_;
877 }
878 tables::ThreadCounterTrackTable* mutable_thread_counter_track_table() {
879 return &thread_counter_track_table_;
880 }
881
882 const tables::ProcessCounterTrackTable& process_counter_track_table() const {
883 return process_counter_track_table_;
884 }
885 tables::ProcessCounterTrackTable* mutable_process_counter_track_table() {
886 return &process_counter_track_table_;
887 }
888
889 const tables::CpuCounterTrackTable& cpu_counter_track_table() const {
890 return cpu_counter_track_table_;
891 }
892 tables::CpuCounterTrackTable* mutable_cpu_counter_track_table() {
893 return &cpu_counter_track_table_;
894 }
895
896 const tables::IrqCounterTrackTable& irq_counter_track_table() const {
897 return irq_counter_track_table_;
898 }
899 tables::IrqCounterTrackTable* mutable_irq_counter_track_table() {
900 return &irq_counter_track_table_;
901 }
902
903 const tables::SoftirqCounterTrackTable& softirq_counter_track_table() const {
904 return softirq_counter_track_table_;
905 }
906 tables::SoftirqCounterTrackTable* mutable_softirq_counter_track_table() {
907 return &softirq_counter_track_table_;
908 }
909
910 const tables::GpuCounterTrackTable& gpu_counter_track_table() const {
911 return gpu_counter_track_table_;
912 }
913 tables::GpuCounterTrackTable* mutable_gpu_counter_track_table() {
914 return &gpu_counter_track_table_;
915 }
916
Lalit Magantiff69c112018-09-24 12:07:47 +0100917 const Slices& slices() const { return slices_; }
Lalit Magantifde29042018-10-04 13:28:52 +0100918 Slices* mutable_slices() { return &slices_; }
919
Lalit Maganti1308e3f2019-12-09 20:24:20 +0000920 const tables::SliceTable& slice_table() const { return slice_table_; }
921 tables::SliceTable* mutable_slice_table() { return &slice_table_; }
Primiano Tucci0d72a312018-08-07 14:42:45 +0100922
Eric Secklerd3b89d52019-07-10 15:36:29 +0100923 const ThreadSlices& thread_slices() const { return thread_slices_; }
924 ThreadSlices* mutable_thread_slices() { return &thread_slices_; }
925
Eric Secklerc3430c62019-07-22 10:49:58 +0100926 const VirtualTrackSlices& virtual_track_slices() const {
927 return virtual_track_slices_;
928 }
929 VirtualTrackSlices* mutable_virtual_track_slices() {
930 return &virtual_track_slices_;
931 }
932
Lalit Maganti20539c22019-09-04 12:36:10 +0100933 const tables::GpuSliceTable& gpu_slice_table() const {
934 return gpu_slice_table_;
935 }
936 tables::GpuSliceTable* mutable_gpu_slice_table() { return &gpu_slice_table_; }
Mikael Pessa7160ccc2019-07-25 11:19:26 -0700937
Lalit Maganti4b3b3ad2019-12-04 19:27:35 +0000938 const tables::CounterTable& counter_table() const { return counter_table_; }
939 tables::CounterTable* mutable_counter_table() { return &counter_table_; }
Isabelle Taylor14674d42018-09-07 11:33:11 +0100940
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700941 const SqlStats& sql_stats() const { return sql_stats_; }
942 SqlStats* mutable_sql_stats() { return &sql_stats_; }
943
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000944 const Instants& instants() const { return instants_; }
945 Instants* mutable_instants() { return &instants_; }
946
Primiano Tucci2c761ef2019-01-07 20:20:46 +0000947 const AndroidLogs& android_logs() const { return android_log_; }
948 AndroidLogs* mutable_android_log() { return &android_log_; }
949
Primiano Tucci0e38a142019-01-07 20:51:09 +0000950 const StatsMap& stats() const { return stats_; }
Lalit Maganti05e8c132018-11-09 18:16:12 +0000951
Ryan Savitski51413ad2019-07-09 14:25:21 +0100952 const Metadata& metadata() const { return metadata_; }
Ryan Savitski0476ee92019-07-09 14:29:33 +0100953 Metadata* mutable_metadata() { return &metadata_; }
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100954
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000955 const Args& args() const { return args_; }
956 Args* mutable_args() { return &args_; }
957
Lalit Maganti1d915a62019-01-07 12:10:42 +0000958 const RawEvents& raw_events() const { return raw_events_; }
959 RawEvents* mutable_raw_events() { return &raw_events_; }
960
Lalit Maganti45980c92019-12-20 13:17:44 +0000961 const tables::StackProfileMappingTable& stack_profile_mapping_table() const {
962 return stack_profile_mapping_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100963 }
Lalit Maganti45980c92019-12-20 13:17:44 +0000964 tables::StackProfileMappingTable* mutable_stack_profile_mapping_table() {
965 return &stack_profile_mapping_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100966 }
967
Oystein Eftevaag5419c582019-08-21 13:58:49 -0700968 const StackProfileFrames& stack_profile_frames() const {
969 return stack_profile_frames_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100970 }
Oystein Eftevaag5419c582019-08-21 13:58:49 -0700971 StackProfileFrames* mutable_stack_profile_frames() {
972 return &stack_profile_frames_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100973 }
974
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +0100975 const tables::StackProfileCallsiteTable& stack_profile_callsite_table()
976 const {
977 return stack_profile_callsite_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100978 }
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +0100979 tables::StackProfileCallsiteTable* mutable_stack_profile_callsite_table() {
980 return &stack_profile_callsite_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100981 }
982
Lalit Magantia5ffb202019-12-17 18:10:52 +0000983 const tables::HeapProfileAllocationTable& heap_profile_allocation_table()
984 const {
985 return heap_profile_allocation_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100986 }
Lalit Magantia5ffb202019-12-17 18:10:52 +0000987 tables::HeapProfileAllocationTable* mutable_heap_profile_allocation_table() {
988 return &heap_profile_allocation_table_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100989 }
Lalit Maganti0fd14ef2019-12-18 18:18:44 +0000990 const tables::CpuProfileStackSampleTable& cpu_profile_stack_sample_table()
991 const {
992 return cpu_profile_stack_sample_table_;
Oystein Eftevaag7f64c102019-08-29 10:27:31 -0700993 }
Lalit Maganti0fd14ef2019-12-18 18:18:44 +0000994 tables::CpuProfileStackSampleTable* mutable_cpu_profile_stack_sample_table() {
995 return &cpu_profile_stack_sample_table_;
Oystein Eftevaag7f64c102019-08-29 10:27:31 -0700996 }
Florian Mayer438b5ab2019-05-02 11:18:06 +0100997
Ioannis Ilkose0b47f52019-09-18 11:14:57 +0100998 const tables::SymbolTable& symbol_table() const { return symbol_table_; }
999
1000 tables::SymbolTable* mutable_symbol_table() { return &symbol_table_; }
1001
Florian Mayer25e013e2019-10-01 14:06:15 +01001002 const tables::HeapGraphObjectTable& heap_graph_object_table() const {
1003 return heap_graph_object_table_;
1004 }
1005
1006 tables::HeapGraphObjectTable* mutable_heap_graph_object_table() {
1007 return &heap_graph_object_table_;
1008 }
1009
Florian Mayer9c01d162019-10-09 17:55:32 +01001010 const tables::HeapGraphReferenceTable& heap_graph_reference_table() const {
1011 return heap_graph_reference_table_;
1012 }
1013
1014 tables::HeapGraphReferenceTable* mutable_heap_graph_reference_table() {
1015 return &heap_graph_reference_table_;
1016 }
1017
Lalit Maganti20539c22019-09-04 12:36:10 +01001018 const tables::GpuTrackTable& gpu_track_table() const {
1019 return gpu_track_table_;
1020 }
1021 tables::GpuTrackTable* mutable_gpu_track_table() { return &gpu_track_table_; }
Mikael Pessa7160ccc2019-07-25 11:19:26 -07001022
Mohammad Reza Zakerinasabb06d1852019-09-11 14:41:36 -04001023 const tables::VulkanMemoryAllocationsTable& vulkan_memory_allocations_table()
1024 const {
1025 return vulkan_memory_allocations_table_;
1026 }
1027
1028 tables::VulkanMemoryAllocationsTable*
1029 mutable_vulkan_memory_allocations_table() {
1030 return &vulkan_memory_allocations_table_;
1031 }
1032
Lalit Maganti5c454312019-04-08 12:11:17 +01001033 const StringPool& string_pool() const { return string_pool_; }
Lalit Magantiacda68b2018-10-29 15:23:25 +00001034
Hector Dearman5145e502019-09-18 16:52:24 +01001035 // |unique_processes_| always contains at least 1 element because the 0th ID
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001036 // is reserved to indicate an invalid process.
Lalit Maganti9c6395b2019-01-17 00:25:09 +00001037 size_t process_count() const { return unique_processes_.size(); }
Primiano Tucci0d72a312018-08-07 14:42:45 +01001038
Hector Dearman5145e502019-09-18 16:52:24 +01001039 // |unique_threads_| always contains at least 1 element because the 0th ID
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001040 // is reserved to indicate an invalid thread.
Lalit Maganti9c6395b2019-01-17 00:25:09 +00001041 size_t thread_count() const { return unique_threads_.size(); }
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001042
Hector Dearman12323362018-08-09 16:09:28 +01001043 // Number of interned strings in the pool. Includes the empty string w/ ID=0.
1044 size_t string_count() const { return string_pool_.size(); }
1045
Ioannis Ilkosb8b11102019-01-29 17:56:55 +00001046 // Start / end ts (in nanoseconds) across the parsed trace events.
1047 // Returns (0, 0) if the trace is empty.
1048 std::pair<int64_t, int64_t> GetTraceTimestampBoundsNs() const;
1049
Lalit Maganti45980c92019-12-20 13:17:44 +00001050 // TODO(lalitm): remove this when we have a better home.
1051 std::vector<int64_t> FindMappingRow(StringId name, StringId build_id) const {
1052 auto it = stack_profile_mapping_index_.find(std::make_pair(name, build_id));
1053 if (it == stack_profile_mapping_index_.end())
1054 return {};
1055 return it->second;
1056 }
1057
1058 // TODO(lalitm): remove this when we have a better home.
1059 void InsertMappingRow(StringId name, StringId build_id, uint32_t row) {
1060 auto pair = std::make_pair(name, build_id);
1061 stack_profile_mapping_index_[pair].emplace_back(row);
1062 }
1063
Lalit Maganticaed37e2018-06-01 03:03:08 +01001064 private:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +00001065 static constexpr uint8_t kRowIdTableShift = 32;
Isabelle Taylora0a22972018-08-03 12:06:12 +01001066
Primiano Tucci2da5d2e2018-08-10 14:23:31 +01001067 using StringHash = uint64_t;
Lalit Maganticaed37e2018-06-01 03:03:08 +01001068
Lalit Maganti5c454312019-04-08 12:11:17 +01001069 TraceStorage(const TraceStorage&) = delete;
1070 TraceStorage& operator=(const TraceStorage&) = delete;
1071
Lalit Maganti20539c22019-09-04 12:36:10 +01001072 TraceStorage(TraceStorage&&) = delete;
1073 TraceStorage& operator=(TraceStorage&&) = delete;
1074
Lalit Maganti45980c92019-12-20 13:17:44 +00001075 // TODO(lalitm): remove this when we find a better home for this.
1076 using MappingKey = std::pair<StringId /* name */, StringId /* build id */>;
1077 std::map<MappingKey, std::vector<int64_t>> stack_profile_mapping_index_;
1078
Lalit Maganti20539c22019-09-04 12:36:10 +01001079 // One entry for each unique string in the trace.
1080 StringPool string_pool_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +00001081
Lalit Maganti05e8c132018-11-09 18:16:12 +00001082 // Stats about parsing the trace.
Primiano Tucci0e38a142019-01-07 20:51:09 +00001083 StatsMap stats_{};
Lalit Maganti35622b72018-06-06 12:03:11 +01001084
Ryan Savitski51413ad2019-07-09 14:25:21 +01001085 // Extra data extracted from the trace. Includes:
1086 // * metadata from chrome and benchmarking infrastructure
1087 // * descriptions of android packages
1088 Metadata metadata_{};
Mikhail Khokhlove466c002019-05-23 13:33:33 +01001089
Lalit Magantid11d3e02019-07-26 12:32:09 +05301090 // Metadata for tracks.
Lalit Magantiac68e9c2019-09-09 18:12:15 +01001091 tables::TrackTable track_table_{&string_pool_, nullptr};
Lalit Maganti4ea78d92019-09-20 20:20:41 +01001092 tables::GpuTrackTable gpu_track_table_{&string_pool_, &track_table_};
Lalit Maganti53bdbb22019-09-25 11:11:18 +01001093 tables::ProcessTrackTable process_track_table_{&string_pool_, &track_table_};
Lalit Magantifedc15b2019-09-26 18:37:52 +01001094 tables::ThreadTrackTable thread_track_table_{&string_pool_, &track_table_};
Eric Seckler5703ede2019-07-10 10:13:02 +01001095
Lalit Maganti809b2f92019-11-07 13:27:26 +00001096 // Track tables for counter events.
1097 tables::CounterTrackTable counter_track_table_{&string_pool_, &track_table_};
1098 tables::ThreadCounterTrackTable thread_counter_track_table_{
1099 &string_pool_, &counter_track_table_};
1100 tables::ProcessCounterTrackTable process_counter_track_table_{
1101 &string_pool_, &counter_track_table_};
1102 tables::CpuCounterTrackTable cpu_counter_track_table_{&string_pool_,
1103 &counter_track_table_};
1104 tables::IrqCounterTrackTable irq_counter_track_table_{&string_pool_,
1105 &counter_track_table_};
1106 tables::SoftirqCounterTrackTable softirq_counter_track_table_{
1107 &string_pool_, &counter_track_table_};
1108 tables::GpuCounterTrackTable gpu_counter_track_table_{&string_pool_,
1109 &counter_track_table_};
1110
Mikael Pessa803090c2019-08-23 16:03:34 -07001111 // Metadata for gpu tracks.
Mikael Pessa803090c2019-08-23 16:03:34 -07001112 GpuContexts gpu_contexts_;
1113
Lalit Maganticaed37e2018-06-01 03:03:08 +01001114 // One entry for each CPU in the trace.
Lalit Magantiff69c112018-09-24 12:07:47 +01001115 Slices slices_;
Lalit Maganticaed37e2018-06-01 03:03:08 +01001116
Lalit Maganti6e9c55e2018-11-29 12:00:39 +00001117 // Args for all other tables.
1118 Args args_;
1119
Isabelle Taylor47328cf2018-06-12 14:33:59 +01001120 // One entry for each UniquePid, with UniquePid as the index.
Ioannis Ilkos9c03cbd2019-03-12 18:30:43 +00001121 // Never hold on to pointers to Process, as vector resize will
1122 // invalidate them.
1123 std::vector<Process> unique_processes_;
Isabelle Taylor68e42192018-06-19 16:19:31 +01001124
Isabelle Taylor68e42192018-06-19 16:19:31 +01001125 // One entry for each UniqueTid, with UniqueTid as the index.
Isabelle Taylor3dd366c2018-06-22 16:21:41 +01001126 std::deque<Thread> unique_threads_;
Primiano Tucci0d72a312018-08-07 14:42:45 +01001127
1128 // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros).
Lalit Maganti1308e3f2019-12-09 20:24:20 +00001129 tables::SliceTable slice_table_{&string_pool_, nullptr};
Isabelle Taylor15314ea2018-09-19 11:35:19 +01001130
Eric Secklerd3b89d52019-07-10 15:36:29 +01001131 // Additional attributes for threads slices (sub-type of NestableSlices).
1132 ThreadSlices thread_slices_;
1133
Eric Secklerc3430c62019-07-22 10:49:58 +01001134 // Additional attributes for virtual track slices (sub-type of
1135 // NestableSlices).
1136 VirtualTrackSlices virtual_track_slices_;
1137
Mikael Pessa803090c2019-08-23 16:03:34 -07001138 // Additional attributes for gpu track slices (sub-type of
1139 // NestableSlices).
Lalit Maganti20539c22019-09-04 12:36:10 +01001140 tables::GpuSliceTable gpu_slice_table_{&string_pool_, nullptr};
Mikael Pessa803090c2019-08-23 16:03:34 -07001141
Lalit Maganti8320e6d2019-03-14 18:49:33 +00001142 // The values from the Counter events from the trace. This includes CPU
1143 // frequency events as well systrace trace_marker counter events.
Lalit Maganti4b3b3ad2019-12-04 19:27:35 +00001144 tables::CounterTable counter_table_{&string_pool_, nullptr};
Primiano Tucci5cb84f82018-10-31 21:46:36 -07001145
1146 SqlStats sql_stats_;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +00001147
Isabelle Taylorc8c11202018-11-05 11:36:22 +00001148 // These are instantaneous events in the trace. They have no duration
1149 // and do not have a value that make sense to track over time.
1150 // e.g. signal events
1151 Instants instants_;
Lalit Maganti1d915a62019-01-07 12:10:42 +00001152
1153 // Raw events are every ftrace event in the trace. The raw event includes
1154 // the timestamp and the pid. The args for the raw event will be in the
1155 // args table. This table can be used to generate a text version of the
1156 // trace.
1157 RawEvents raw_events_;
Primiano Tucci2c761ef2019-01-07 20:20:46 +00001158 AndroidLogs android_log_;
Florian Mayer438b5ab2019-05-02 11:18:06 +01001159
Lalit Maganti45980c92019-12-20 13:17:44 +00001160 tables::StackProfileMappingTable stack_profile_mapping_table_{&string_pool_,
1161 nullptr};
Oystein Eftevaag5419c582019-08-21 13:58:49 -07001162 StackProfileFrames stack_profile_frames_;
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +01001163 tables::StackProfileCallsiteTable stack_profile_callsite_table_{&string_pool_,
1164 nullptr};
Lalit Magantia5ffb202019-12-17 18:10:52 +00001165 tables::HeapProfileAllocationTable heap_profile_allocation_table_{
1166 &string_pool_, nullptr};
Lalit Maganti0fd14ef2019-12-18 18:18:44 +00001167 tables::CpuProfileStackSampleTable cpu_profile_stack_sample_table_{
1168 &string_pool_, nullptr};
Ioannis Ilkose0b47f52019-09-18 11:14:57 +01001169
1170 // Symbol tables (mappings from frames to symbol names)
1171 tables::SymbolTable symbol_table_{&string_pool_, nullptr};
Florian Mayer25e013e2019-10-01 14:06:15 +01001172 tables::HeapGraphObjectTable heap_graph_object_table_{&string_pool_, nullptr};
Florian Mayer9c01d162019-10-09 17:55:32 +01001173 tables::HeapGraphReferenceTable heap_graph_reference_table_{&string_pool_,
1174 nullptr};
Mohammad Reza Zakerinasabb06d1852019-09-11 14:41:36 -04001175
1176 tables::VulkanMemoryAllocationsTable vulkan_memory_allocations_table_{
1177 &string_pool_, nullptr};
Lalit Maganticaed37e2018-06-01 03:03:08 +01001178};
1179
1180} // namespace trace_processor
1181} // namespace perfetto
1182
Florian Mayerbee52132019-05-02 13:59:56 +01001183namespace std {
1184
1185template <>
Oystein Eftevaag5419c582019-08-21 13:58:49 -07001186struct hash<
1187 ::perfetto::trace_processor::TraceStorage::StackProfileFrames::Row> {
Florian Mayerbee52132019-05-02 13:59:56 +01001188 using argument_type =
Oystein Eftevaag5419c582019-08-21 13:58:49 -07001189 ::perfetto::trace_processor::TraceStorage::StackProfileFrames::Row;
Florian Mayerbee52132019-05-02 13:59:56 +01001190 using result_type = size_t;
1191
1192 result_type operator()(const argument_type& r) const {
1193 return std::hash<::perfetto::trace_processor::StringId>{}(r.name_id) ^
1194 std::hash<int64_t>{}(r.mapping_row) ^ std::hash<int64_t>{}(r.rel_pc);
1195 }
1196};
1197
1198template <>
1199struct hash<
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +01001200 ::perfetto::trace_processor::tables::StackProfileCallsiteTable::Row> {
Florian Mayerbee52132019-05-02 13:59:56 +01001201 using argument_type =
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +01001202 ::perfetto::trace_processor::tables::StackProfileCallsiteTable::Row;
Florian Mayerbee52132019-05-02 13:59:56 +01001203 using result_type = size_t;
1204
1205 result_type operator()(const argument_type& r) const {
1206 return std::hash<int64_t>{}(r.depth) ^ std::hash<int64_t>{}(r.parent_id) ^
Lalit Magantiaa0ff5b2019-10-25 10:35:48 +01001207 std::hash<int64_t>{}(r.frame_id);
Florian Mayerbee52132019-05-02 13:59:56 +01001208 }
1209};
1210
1211template <>
1212struct hash<
Lalit Maganti45980c92019-12-20 13:17:44 +00001213 ::perfetto::trace_processor::tables::StackProfileMappingTable::Row> {
Florian Mayerbee52132019-05-02 13:59:56 +01001214 using argument_type =
Lalit Maganti45980c92019-12-20 13:17:44 +00001215 ::perfetto::trace_processor::tables::StackProfileMappingTable::Row;
Florian Mayerbee52132019-05-02 13:59:56 +01001216 using result_type = size_t;
1217
1218 result_type operator()(const argument_type& r) const {
1219 return std::hash<::perfetto::trace_processor::StringId>{}(r.build_id) ^
Florian Mayer12655732019-07-02 15:08:26 +01001220 std::hash<int64_t>{}(r.exact_offset) ^
1221 std::hash<int64_t>{}(r.start_offset) ^
1222 std::hash<int64_t>{}(r.start) ^ std::hash<int64_t>{}(r.end) ^
1223 std::hash<int64_t>{}(r.load_bias) ^
Lalit Maganti45980c92019-12-20 13:17:44 +00001224 std::hash<::perfetto::trace_processor::StringId>{}(r.name);
Florian Mayerbee52132019-05-02 13:59:56 +01001225 }
1226};
1227
1228} // namespace std
1229
Lalit Maganticaed37e2018-06-01 03:03:08 +01001230#endif // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_