blob: d65b4357de9fdee127f144382043a74a48d11850 [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"
Primiano Tucci2c5488f2019-06-01 03:27:28 +010029#include "perfetto/ext/base/hash.h"
30#include "perfetto/ext/base/optional.h"
31#include "perfetto/ext/base/string_view.h"
32#include "perfetto/ext/base/time.h"
33#include "perfetto/ext/base/utils.h"
Lalit Magantib0b53ee2019-01-24 17:53:39 +000034#include "src/trace_processor/ftrace_utils.h"
Mikhail Khokhlove466c002019-05-23 13:33:33 +010035#include "src/trace_processor/metadata.h"
Primiano Tucci0e38a142019-01-07 20:51:09 +000036#include "src/trace_processor/stats.h"
Lalit Maganti5c454312019-04-08 12:11:17 +010037#include "src/trace_processor/string_pool.h"
Mikhail Khokhlov85a0dd02019-05-17 14:22:28 +010038#include "src/trace_processor/variadic.h"
Lalit Maganti35622b72018-06-06 12:03:11 +010039
Lalit Maganticaed37e2018-06-01 03:03:08 +010040namespace perfetto {
41namespace trace_processor {
42
Isabelle Taylora0a22972018-08-03 12:06:12 +010043// 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.
46using UniquePid = uint32_t;
Primiano Tucci0d72a312018-08-07 14:42:45 +010047
Isabelle Taylora0a22972018-08-03 12:06:12 +010048// UniqueTid is an offset into |unique_threads_|. Necessary because tids can
49// be reused.
50using UniqueTid = uint32_t;
51
Primiano Tucci0d72a312018-08-07 14:42:45 +010052// StringId is an offset into |string_pool_|.
Lalit Maganti5c454312019-04-08 12:11:17 +010053using StringId = StringPool::Id;
Primiano Tucci0d72a312018-08-07 14:42:45 +010054
Lalit Maganti5ea9e932018-11-30 14:19:39 +000055// Identifiers for all the tables in the database.
56enum TableId : uint8_t {
57 // Intentionally don't have TableId == 0 so that RowId == 0 can refer to an
58 // invalid row id.
Lalit Maganti8320e6d2019-03-14 18:49:33 +000059 kCounterValues = 1,
Lalit Maganti1d915a62019-01-07 12:10:42 +000060 kRawEvents = 2,
Lalit Maganti66ed7ad2019-01-11 16:47:26 +000061 kInstants = 3,
Isabelle Taylorb9222c32019-01-31 10:58:37 +000062 kSched = 4,
Eric Seckler70cc4422019-05-28 16:00:23 +010063 kNestableSlices = 5,
Ryan Savitski51413ad2019-07-09 14:25:21 +010064 kMetadataTable = 6,
Lalit Maganti5ea9e932018-11-30 14:19:39 +000065};
66
67// The top 8 bits are set to the TableId and the bottom 32 to the row of the
68// table.
Lalit Maganti85ca4a82018-12-07 17:28:02 +000069using RowId = int64_t;
Lalit Maganti5ea9e932018-11-30 14:19:39 +000070static const RowId kInvalidRowId = 0;
71
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +000072using ArgSetId = uint32_t;
73static const ArgSetId kInvalidArgSetId = 0;
74
Eric Seckler5703ede2019-07-10 10:13:02 +010075using TrackId = uint32_t;
76
77enum class VirtualTrackScope : uint8_t {
78 // VirtualTrack with global scope, will not have a |upid| set.
79 kGlobal = 0,
80 // VirtualTrack associated with a specific process via |upid|.
81 kProcess = 1
82};
83
Isabelle Taylora97c5f52018-10-23 17:36:12 +010084enum RefType {
Primiano Tucci5403e4f2018-11-27 10:07:03 +000085 kRefNoRef = 0,
86 kRefUtid = 1,
87 kRefCpuId = 2,
88 kRefIrq = 3,
89 kRefSoftIrq = 4,
90 kRefUpid = 5,
Sidath Senanayake1f5f93a2019-06-06 22:24:15 +010091 kRefGpuId = 6,
Eric Seckler5703ede2019-07-10 10:13:02 +010092 kRefTrack = 7,
Primiano Tucci5403e4f2018-11-27 10:07:03 +000093 kRefMax
Isabelle Taylora97c5f52018-10-23 17:36:12 +010094};
Isabelle Taylor14674d42018-09-07 11:33:11 +010095
Eric Seckler972225e2019-04-18 11:07:12 +010096const std::vector<const char*>& GetRefTypeStringMap();
97
Lalit Maganticaed37e2018-06-01 03:03:08 +010098// Stores a data inside a trace file in a columnar form. This makes it efficient
99// to read or search across a single field of the trace (e.g. all the thread
100// names for a given CPU).
101class TraceStorage {
102 public:
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100103 TraceStorage();
Isabelle Taylora0a22972018-08-03 12:06:12 +0100104
105 virtual ~TraceStorage();
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100106
Isabelle Taylora0a22972018-08-03 12:06:12 +0100107 // Information about a unique process seen in a trace.
108 struct Process {
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100109 explicit Process(uint32_t p) : pid(p) {}
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000110 int64_t start_ns = 0;
Lalit Maganti637589a2019-07-04 17:25:29 +0100111 int64_t end_ns = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100112 StringId name_id = 0;
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100113 uint32_t pid = 0;
Lalit Maganti369b0572019-07-11 15:35:09 +0100114 base::Optional<UniquePid> parent_upid;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100115 };
116
117 // Information about a unique thread seen in a trace.
118 struct Thread {
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100119 explicit Thread(uint32_t t) : tid(t) {}
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000120 int64_t start_ns = 0;
Lalit Magantib5bd2332019-06-06 14:20:47 +0100121 int64_t end_ns = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100122 StringId name_id = 0;
Lalit Maganti770886a2018-11-16 17:40:21 +0000123 base::Optional<UniquePid> upid;
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100124 uint32_t tid = 0;
Isabelle Taylora0a22972018-08-03 12:06:12 +0100125 };
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100126
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000127 // Generic key value storage which can be referenced by other tables.
128 class Args {
129 public:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000130 struct Arg {
131 StringId flat_key = 0;
132 StringId key = 0;
133 Variadic value = Variadic::Integer(0);
134
135 // This is only used by the arg tracker and so is not part of the hash.
136 RowId row_id = 0;
137 };
138
139 struct ArgHasher {
140 uint64_t operator()(const Arg& arg) const noexcept {
Lalit Maganti1f464742019-02-28 13:49:31 +0000141 base::Hash hash;
142 hash.Update(arg.key);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000143 // We don't hash arg.flat_key because it's a subsequence of arg.key.
144 switch (arg.value.type) {
145 case Variadic::Type::kInt:
Lalit Maganti1f464742019-02-28 13:49:31 +0000146 hash.Update(arg.value.int_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000147 break;
Eric Secklerc93823e2019-06-03 16:49:19 +0100148 case Variadic::Type::kUint:
149 hash.Update(arg.value.uint_value);
150 break;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000151 case Variadic::Type::kString:
Lalit Maganti1f464742019-02-28 13:49:31 +0000152 hash.Update(arg.value.string_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000153 break;
154 case Variadic::Type::kReal:
Lalit Maganti1f464742019-02-28 13:49:31 +0000155 hash.Update(arg.value.real_value);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000156 break;
Eric Secklerc93823e2019-06-03 16:49:19 +0100157 case Variadic::Type::kPointer:
158 hash.Update(arg.value.pointer_value);
159 break;
160 case Variadic::Type::kBool:
161 hash.Update(arg.value.bool_value);
162 break;
163 case Variadic::Type::kJson:
164 hash.Update(arg.value.json_value);
165 break;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000166 }
Lalit Maganti1f464742019-02-28 13:49:31 +0000167 return hash.digest();
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000168 }
169 };
170
171 const std::deque<ArgSetId>& set_ids() const { return set_ids_; }
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000172 const std::deque<StringId>& flat_keys() const { return flat_keys_; }
173 const std::deque<StringId>& keys() const { return keys_; }
Lalit Maganti1d915a62019-01-07 12:10:42 +0000174 const std::deque<Variadic>& arg_values() const { return arg_values_; }
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000175 uint32_t args_count() const {
176 return static_cast<uint32_t>(set_ids_.size());
Lalit Maganti79472be2018-12-04 13:41:27 +0000177 }
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000178
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000179 ArgSetId AddArgSet(const std::vector<Arg>& args,
180 uint32_t begin,
181 uint32_t end) {
Lalit Maganti1f464742019-02-28 13:49:31 +0000182 base::Hash hash;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000183 for (uint32_t i = begin; i < end; i++) {
Lalit Maganti1f464742019-02-28 13:49:31 +0000184 hash.Update(ArgHasher()(args[i]));
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000185 }
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000186
Lalit Maganti1f464742019-02-28 13:49:31 +0000187 ArgSetHash digest = hash.digest();
188 auto it = arg_row_for_hash_.find(digest);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000189 if (it != arg_row_for_hash_.end()) {
190 return set_ids_[it->second];
191 }
192
193 // The +1 ensures that nothing has an id == kInvalidArgSetId == 0.
194 ArgSetId id = static_cast<uint32_t>(arg_row_for_hash_.size()) + 1;
Lalit Maganti1f464742019-02-28 13:49:31 +0000195 arg_row_for_hash_.emplace(digest, args_count());
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000196 for (uint32_t i = begin; i < end; i++) {
197 const auto& arg = args[i];
198 set_ids_.emplace_back(id);
199 flat_keys_.emplace_back(arg.flat_key);
200 keys_.emplace_back(arg.key);
201 arg_values_.emplace_back(arg.value);
202 }
203 return id;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000204 }
205
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000206 private:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000207 using ArgSetHash = uint64_t;
208
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000209 std::deque<ArgSetId> set_ids_;
Lalit Maganti5ea9e932018-11-30 14:19:39 +0000210 std::deque<StringId> flat_keys_;
211 std::deque<StringId> keys_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000212 std::deque<Variadic> arg_values_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000213
214 std::unordered_map<ArgSetHash, uint32_t> arg_row_for_hash_;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +0000215 };
216
Eric Seckler5703ede2019-07-10 10:13:02 +0100217 class VirtualTracks {
218 public:
219 inline uint32_t AddVirtualTrack(TrackId track_id,
220 StringId name,
221 VirtualTrackScope scope,
222 UniquePid upid = 0u) {
223 track_ids_.emplace_back(track_id);
224 names_.emplace_back(name);
225 scopes_.emplace_back(scope);
226 upids_.emplace_back(upid);
227 return virtual_track_count() - 1;
228 }
229
230 uint32_t virtual_track_count() const {
231 return static_cast<uint32_t>(track_ids_.size());
232 }
233
234 const std::deque<uint32_t>& track_ids() const { return track_ids_; }
235 const std::deque<StringId>& names() const { return names_; }
236 const std::deque<VirtualTrackScope>& scopes() const { return scopes_; }
237 const std::deque<UniquePid>& upids() const { return upids_; }
238
239 private:
240 std::deque<uint32_t> track_ids_;
241 std::deque<StringId> names_;
242 std::deque<VirtualTrackScope> scopes_;
243 std::deque<UniquePid> upids_;
244 };
245
Lalit Magantiff69c112018-09-24 12:07:47 +0100246 class Slices {
Lalit Maganti35622b72018-06-06 12:03:11 +0100247 public:
Lalit Magantifde29042018-10-04 13:28:52 +0100248 inline size_t AddSlice(uint32_t cpu,
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000249 int64_t start_ns,
250 int64_t duration_ns,
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000251 UniqueTid utid,
252 ftrace_utils::TaskState end_state,
253 int32_t priority) {
Lalit Magantiff69c112018-09-24 12:07:47 +0100254 cpus_.emplace_back(cpu);
Lalit Maganti35622b72018-06-06 12:03:11 +0100255 start_ns_.emplace_back(start_ns);
256 durations_.emplace_back(duration_ns);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100257 utids_.emplace_back(utid);
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000258 end_states_.emplace_back(end_state);
259 priorities_.emplace_back(priority);
Lalit Maganti58638932019-01-31 10:48:26 +0000260
261 if (utid >= rows_for_utids_.size())
262 rows_for_utids_.resize(utid + 1);
263 rows_for_utids_[utid].emplace_back(slice_count() - 1);
Lalit Magantifde29042018-10-04 13:28:52 +0100264 return slice_count() - 1;
265 }
266
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000267 void set_duration(size_t index, int64_t duration_ns) {
Lalit Magantifde29042018-10-04 13:28:52 +0100268 durations_[index] = duration_ns;
Lalit Maganti35622b72018-06-06 12:03:11 +0100269 }
270
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000271 void set_end_state(size_t index, ftrace_utils::TaskState end_state) {
272 end_states_[index] = end_state;
273 }
274
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100275 size_t slice_count() const { return start_ns_.size(); }
Lalit Maganti35622b72018-06-06 12:03:11 +0100276
Lalit Magantiff69c112018-09-24 12:07:47 +0100277 const std::deque<uint32_t>& cpus() const { return cpus_; }
278
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000279 const std::deque<int64_t>& start_ns() const { return start_ns_; }
Lalit Maganti35622b72018-06-06 12:03:11 +0100280
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000281 const std::deque<int64_t>& durations() const { return durations_; }
Lalit Maganti35622b72018-06-06 12:03:11 +0100282
Isabelle Taylor68e42192018-06-19 16:19:31 +0100283 const std::deque<UniqueTid>& utids() const { return utids_; }
284
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000285 const std::deque<ftrace_utils::TaskState>& end_state() const {
286 return end_states_;
287 }
288
289 const std::deque<int32_t>& priorities() const { return priorities_; }
290
Lalit Maganti58638932019-01-31 10:48:26 +0000291 const std::deque<std::vector<uint32_t>>& rows_for_utids() const {
Lalit Magantif0f09c32019-01-18 17:29:31 +0000292 return rows_for_utids_;
293 }
294
Lalit Maganti35622b72018-06-06 12:03:11 +0100295 private:
Hector Dearman947f12a2018-09-11 16:50:36 +0100296 // Each deque below has the same number of entries (the number of slices
Lalit Maganti35622b72018-06-06 12:03:11 +0100297 // in the trace for the CPU).
Lalit Magantiff69c112018-09-24 12:07:47 +0100298 std::deque<uint32_t> cpus_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000299 std::deque<int64_t> start_ns_;
300 std::deque<int64_t> durations_;
Isabelle Taylor68e42192018-06-19 16:19:31 +0100301 std::deque<UniqueTid> utids_;
Lalit Magantib0b53ee2019-01-24 17:53:39 +0000302 std::deque<ftrace_utils::TaskState> end_states_;
303 std::deque<int32_t> priorities_;
Lalit Maganti58638932019-01-31 10:48:26 +0000304
305 // One row per utid.
306 std::deque<std::vector<uint32_t>> rows_for_utids_;
Primiano Tucci0d72a312018-08-07 14:42:45 +0100307 };
Isabelle Taylor68e42192018-06-19 16:19:31 +0100308
Primiano Tucci0d72a312018-08-07 14:42:45 +0100309 class NestableSlices {
310 public:
Eric Seckler70cc4422019-05-28 16:00:23 +0100311 inline uint32_t AddSlice(int64_t start_ns,
312 int64_t duration_ns,
313 int64_t ref,
314 RefType type,
Lalit Maganti81a02cd2019-07-12 17:05:11 +0100315 StringId category,
Eric Seckler70cc4422019-05-28 16:00:23 +0100316 StringId name,
317 uint8_t depth,
318 int64_t stack_id,
319 int64_t parent_stack_id) {
Primiano Tucci0d72a312018-08-07 14:42:45 +0100320 start_ns_.emplace_back(start_ns);
321 durations_.emplace_back(duration_ns);
Eric Seckler972225e2019-04-18 11:07:12 +0100322 refs_.emplace_back(ref);
323 types_.emplace_back(type);
Lalit Maganti81a02cd2019-07-12 17:05:11 +0100324 categories_.emplace_back(category);
Primiano Tucci0d72a312018-08-07 14:42:45 +0100325 names_.emplace_back(name);
326 depths_.emplace_back(depth);
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100327 stack_ids_.emplace_back(stack_id);
328 parent_stack_ids_.emplace_back(parent_stack_id);
Eric Seckler70cc4422019-05-28 16:00:23 +0100329 arg_set_ids_.emplace_back(kInvalidArgSetId);
Lalit Maganti7b37bbf2018-11-09 15:58:54 +0000330 return slice_count() - 1;
331 }
332
Eric Seckler70cc4422019-05-28 16:00:23 +0100333 void set_duration(uint32_t index, int64_t duration_ns) {
Lalit Maganti7b37bbf2018-11-09 15:58:54 +0000334 durations_[index] = duration_ns;
335 }
336
Eric Seckler70cc4422019-05-28 16:00:23 +0100337 void set_stack_id(uint32_t index, int64_t stack_id) {
Lalit Maganti7b37bbf2018-11-09 15:58:54 +0000338 stack_ids_[index] = stack_id;
Primiano Tucci0d72a312018-08-07 14:42:45 +0100339 }
340
Eric Seckler70cc4422019-05-28 16:00:23 +0100341 void set_arg_set_id(uint32_t index, ArgSetId id) {
342 arg_set_ids_[index] = id;
343 }
344
345 uint32_t slice_count() const {
346 return static_cast<uint32_t>(start_ns_.size());
347 }
348
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000349 const std::deque<int64_t>& start_ns() const { return start_ns_; }
350 const std::deque<int64_t>& durations() const { return durations_; }
Eric Seckler972225e2019-04-18 11:07:12 +0100351 const std::deque<int64_t>& refs() const { return refs_; }
352 const std::deque<RefType>& types() const { return types_; }
Lalit Maganti81a02cd2019-07-12 17:05:11 +0100353 const std::deque<StringId>& categories() const { return categories_; }
Primiano Tucci0d72a312018-08-07 14:42:45 +0100354 const std::deque<StringId>& names() const { return names_; }
355 const std::deque<uint8_t>& depths() const { return depths_; }
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000356 const std::deque<int64_t>& stack_ids() const { return stack_ids_; }
357 const std::deque<int64_t>& parent_stack_ids() const {
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100358 return parent_stack_ids_;
359 }
Eric Seckler70cc4422019-05-28 16:00:23 +0100360 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
Primiano Tucci0d72a312018-08-07 14:42:45 +0100361
362 private:
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000363 std::deque<int64_t> start_ns_;
364 std::deque<int64_t> durations_;
Eric Seckler972225e2019-04-18 11:07:12 +0100365 std::deque<int64_t> refs_;
366 std::deque<RefType> types_;
Lalit Maganti81a02cd2019-07-12 17:05:11 +0100367 std::deque<StringId> categories_;
Primiano Tucci0d72a312018-08-07 14:42:45 +0100368 std::deque<StringId> names_;
369 std::deque<uint8_t> depths_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000370 std::deque<int64_t> stack_ids_;
371 std::deque<int64_t> parent_stack_ids_;
Eric Seckler70cc4422019-05-28 16:00:23 +0100372 std::deque<ArgSetId> arg_set_ids_;
Lalit Maganti35622b72018-06-06 12:03:11 +0100373 };
374
Eric Secklerd3b89d52019-07-10 15:36:29 +0100375 class ThreadSlices {
376 public:
377 inline uint32_t AddThreadSlice(uint32_t slice_id,
378 int64_t thread_timestamp_ns,
379 int64_t thread_duration_ns,
380 int64_t thread_instruction_count,
381 int64_t thread_instruction_delta) {
382 slice_ids_.emplace_back(slice_id);
383 thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
384 thread_duration_ns_.emplace_back(thread_duration_ns);
385 thread_instruction_counts_.emplace_back(thread_instruction_count);
386 thread_instruction_deltas_.emplace_back(thread_instruction_delta);
387 return slice_count() - 1;
388 }
389
Eric Secklerc3430c62019-07-22 10:49:58 +0100390 uint32_t slice_count() const {
391 return static_cast<uint32_t>(slice_ids_.size());
Eric Secklerd3b89d52019-07-10 15:36:29 +0100392 }
393
Eric Secklerc3430c62019-07-22 10:49:58 +0100394 const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
395 const std::deque<int64_t>& thread_timestamp_ns() const {
396 return thread_timestamp_ns_;
397 }
398 const std::deque<int64_t>& thread_duration_ns() const {
399 return thread_duration_ns_;
400 }
401 const std::deque<int64_t>& thread_instruction_counts() const {
402 return thread_instruction_counts_;
403 }
404 const std::deque<int64_t>& thread_instruction_deltas() const {
405 return thread_instruction_deltas_;
406 }
407
408 base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const {
409 auto it =
410 std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
411 if (it != slice_ids().end() && *it == slice_id) {
412 return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
413 }
414 return base::nullopt;
415 }
416
417 void UpdateThreadDurationForSliceId(uint32_t slice_id,
418 int64_t end_thread_timestamp_ns) {
419 uint32_t row = *FindRowForSliceId(slice_id);
420 int64_t begin_ns = thread_timestamp_ns_[row];
421 thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
422 }
423
424 private:
425 std::deque<uint32_t> slice_ids_;
426 std::deque<int64_t> thread_timestamp_ns_;
427 std::deque<int64_t> thread_duration_ns_;
428 std::deque<int64_t> thread_instruction_counts_;
429 std::deque<int64_t> thread_instruction_deltas_;
430 };
431
432 class VirtualTrackSlices {
433 public:
434 inline uint32_t AddVirtualTrackSlice(uint32_t slice_id,
435 int64_t thread_timestamp_ns,
436 int64_t thread_duration_ns,
437 int64_t thread_instruction_count,
438 int64_t thread_instruction_delta) {
439 slice_ids_.emplace_back(slice_id);
440 thread_timestamp_ns_.emplace_back(thread_timestamp_ns);
441 thread_duration_ns_.emplace_back(thread_duration_ns);
442 thread_instruction_counts_.emplace_back(thread_instruction_count);
443 thread_instruction_deltas_.emplace_back(thread_instruction_delta);
444 return slice_count() - 1;
Eric Secklerd3b89d52019-07-10 15:36:29 +0100445 }
446
447 uint32_t slice_count() const {
448 return static_cast<uint32_t>(slice_ids_.size());
449 }
450
451 const std::deque<uint32_t>& slice_ids() const { return slice_ids_; }
452 const std::deque<int64_t>& thread_timestamp_ns() const {
453 return thread_timestamp_ns_;
454 }
455 const std::deque<int64_t>& thread_duration_ns() const {
456 return thread_duration_ns_;
457 }
458 const std::deque<int64_t>& thread_instruction_counts() const {
459 return thread_instruction_counts_;
460 }
461 const std::deque<int64_t>& thread_instruction_deltas() const {
462 return thread_instruction_deltas_;
463 }
464
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100465 base::Optional<uint32_t> FindRowForSliceId(uint32_t slice_id) const {
Eric Secklerd3b89d52019-07-10 15:36:29 +0100466 auto it =
467 std::lower_bound(slice_ids().begin(), slice_ids().end(), slice_id);
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100468 if (it != slice_ids().end() && *it == slice_id) {
469 return static_cast<uint32_t>(std::distance(slice_ids().begin(), it));
470 }
471 return base::nullopt;
Eric Secklerd3b89d52019-07-10 15:36:29 +0100472 }
473
474 void UpdateThreadDurationForSliceId(uint32_t slice_id,
475 int64_t end_thread_timestamp_ns) {
Mikhail Khokhlov7db04912019-07-18 16:11:11 +0100476 uint32_t row = *FindRowForSliceId(slice_id);
Eric Secklerd3b89d52019-07-10 15:36:29 +0100477 int64_t begin_ns = thread_timestamp_ns_[row];
478 thread_duration_ns_[row] = end_thread_timestamp_ns - begin_ns;
479 }
480
481 private:
482 std::deque<uint32_t> slice_ids_;
483 std::deque<int64_t> thread_timestamp_ns_;
484 std::deque<int64_t> thread_duration_ns_;
485 std::deque<int64_t> thread_instruction_counts_;
486 std::deque<int64_t> thread_instruction_deltas_;
487 };
488
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000489 class CounterDefinitions {
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100490 public:
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000491 using Id = uint32_t;
Lalit Maganti521d97b2019-04-29 13:47:03 +0100492 static constexpr Id kInvalidId = std::numeric_limits<Id>::max();
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000493
494 inline Id AddCounterDefinition(StringId name_id,
495 int64_t ref,
496 RefType type) {
497 base::Hash hash;
498 hash.Update(name_id);
499 hash.Update(ref);
500 hash.Update(type);
501
502 // TODO(lalitm): this is a perf bottleneck and likely we can do something
503 // quite a bit better here.
504 uint64_t digest = hash.digest();
505 auto it = hash_to_row_idx_.find(digest);
506 if (it != hash_to_row_idx_.end())
507 return it->second;
508
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100509 name_ids_.emplace_back(name_id);
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100510 refs_.emplace_back(ref);
511 types_.emplace_back(type);
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000512 hash_to_row_idx_.emplace(digest, size() - 1);
513 return size() - 1;
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100514 }
Lalit Magantifde29042018-10-04 13:28:52 +0100515
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000516 uint32_t size() const { return static_cast<uint32_t>(name_ids_.size()); }
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100517
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100518 const std::deque<StringId>& name_ids() const { return name_ids_; }
519
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100520 const std::deque<int64_t>& refs() const { return refs_; }
521
522 const std::deque<RefType>& types() const { return types_; }
523
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000524 private:
525 std::deque<StringId> name_ids_;
526 std::deque<int64_t> refs_;
527 std::deque<RefType> types_;
528
529 std::unordered_map<uint64_t, uint32_t> hash_to_row_idx_;
530 };
531
532 class CounterValues {
533 public:
534 inline uint32_t AddCounterValue(CounterDefinitions::Id counter_id,
535 int64_t timestamp,
536 double value) {
537 counter_ids_.emplace_back(counter_id);
538 timestamps_.emplace_back(timestamp);
539 values_.emplace_back(value);
540 arg_set_ids_.emplace_back(kInvalidArgSetId);
Ioannis Ilkosf129c262019-04-25 14:53:51 +0100541
Lalit Maganti521d97b2019-04-29 13:47:03 +0100542 if (counter_id != CounterDefinitions::kInvalidId) {
543 if (counter_id >= rows_for_counter_id_.size()) {
544 rows_for_counter_id_.resize(counter_id + 1);
545 }
546 rows_for_counter_id_[counter_id].emplace_back(size() - 1);
547 }
548 return size() - 1;
549 }
550
551 void set_counter_id(uint32_t index, CounterDefinitions::Id counter_id) {
552 PERFETTO_DCHECK(counter_ids_[index] == CounterDefinitions::kInvalidId);
553
554 counter_ids_[index] = counter_id;
Ioannis Ilkosf129c262019-04-25 14:53:51 +0100555 if (counter_id >= rows_for_counter_id_.size()) {
556 rows_for_counter_id_.resize(counter_id + 1);
557 }
Lalit Maganti521d97b2019-04-29 13:47:03 +0100558
559 auto* new_rows = &rows_for_counter_id_[counter_id];
560 new_rows->insert(
561 std::upper_bound(new_rows->begin(), new_rows->end(), index), index);
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000562 }
563
564 void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; }
565
566 uint32_t size() const { return static_cast<uint32_t>(counter_ids_.size()); }
567
568 const std::deque<CounterDefinitions::Id>& counter_ids() const {
569 return counter_ids_;
570 }
571
572 const std::deque<int64_t>& timestamps() const { return timestamps_; }
573
574 const std::deque<double>& values() const { return values_; }
575
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000576 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
577
Ioannis Ilkosf129c262019-04-25 14:53:51 +0100578 const std::deque<std::vector<uint32_t>>& rows_for_counter_id() const {
579 return rows_for_counter_id_;
580 }
581
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100582 private:
Lalit Maganti8320e6d2019-03-14 18:49:33 +0000583 std::deque<CounterDefinitions::Id> counter_ids_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000584 std::deque<int64_t> timestamps_;
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100585 std::deque<double> values_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000586 std::deque<ArgSetId> arg_set_ids_;
Ioannis Ilkosf129c262019-04-25 14:53:51 +0100587
588 // Indexed by counter_id value and contains the row numbers corresponding to
589 // it.
590 std::deque<std::vector<uint32_t>> rows_for_counter_id_;
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100591 };
592
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700593 class SqlStats {
594 public:
595 static constexpr size_t kMaxLogEntries = 100;
Lalit Magantiaac2f652019-04-30 12:16:21 +0100596 uint32_t RecordQueryBegin(const std::string& query,
597 int64_t time_queued,
598 int64_t time_started);
599 void RecordQueryFirstNext(uint32_t row, int64_t time_first_next);
600 void RecordQueryEnd(uint32_t row, int64_t time_end);
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700601 size_t size() const { return queries_.size(); }
602 const std::deque<std::string>& queries() const { return queries_; }
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000603 const std::deque<int64_t>& times_queued() const { return times_queued_; }
604 const std::deque<int64_t>& times_started() const { return times_started_; }
Lalit Magantiaac2f652019-04-30 12:16:21 +0100605 const std::deque<int64_t>& times_first_next() const {
606 return times_first_next_;
607 }
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000608 const std::deque<int64_t>& times_ended() const { return times_ended_; }
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700609
610 private:
Lalit Magantiaac2f652019-04-30 12:16:21 +0100611 uint32_t popped_queries_ = 0;
612
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700613 std::deque<std::string> queries_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000614 std::deque<int64_t> times_queued_;
615 std::deque<int64_t> times_started_;
Lalit Magantiaac2f652019-04-30 12:16:21 +0100616 std::deque<int64_t> times_first_next_;
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000617 std::deque<int64_t> times_ended_;
Primiano Tucci5cb84f82018-10-31 21:46:36 -0700618 };
619
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000620 class Instants {
621 public:
Lalit Maganti66ed7ad2019-01-11 16:47:26 +0000622 inline uint32_t AddInstantEvent(int64_t timestamp,
623 StringId name_id,
624 double value,
625 int64_t ref,
626 RefType type) {
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000627 timestamps_.emplace_back(timestamp);
628 name_ids_.emplace_back(name_id);
629 values_.emplace_back(value);
630 refs_.emplace_back(ref);
631 types_.emplace_back(type);
Lalit Maganti1c21d172019-02-07 10:48:24 +0000632 arg_set_ids_.emplace_back(kInvalidArgSetId);
Lalit Maganti66ed7ad2019-01-11 16:47:26 +0000633 return static_cast<uint32_t>(instant_count() - 1);
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000634 }
635
Lalit Maganti521d97b2019-04-29 13:47:03 +0100636 void set_ref(uint32_t row, int64_t ref) { refs_[row] = ref; }
637
Lalit Maganti1c21d172019-02-07 10:48:24 +0000638 void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; }
639
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000640 size_t instant_count() const { return timestamps_.size(); }
641
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000642 const std::deque<int64_t>& timestamps() const { return timestamps_; }
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000643
644 const std::deque<StringId>& name_ids() const { return name_ids_; }
645
646 const std::deque<double>& values() const { return values_; }
647
648 const std::deque<int64_t>& refs() const { return refs_; }
649
650 const std::deque<RefType>& types() const { return types_; }
651
Lalit Maganti1c21d172019-02-07 10:48:24 +0000652 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
653
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000654 private:
Lalit Maganti85ca4a82018-12-07 17:28:02 +0000655 std::deque<int64_t> timestamps_;
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000656 std::deque<StringId> name_ids_;
657 std::deque<double> values_;
658 std::deque<int64_t> refs_;
659 std::deque<RefType> types_;
Lalit Maganti1c21d172019-02-07 10:48:24 +0000660 std::deque<ArgSetId> arg_set_ids_;
Isabelle Taylorc8c11202018-11-05 11:36:22 +0000661 };
662
Lalit Maganti1d915a62019-01-07 12:10:42 +0000663 class RawEvents {
664 public:
665 inline RowId AddRawEvent(int64_t timestamp,
666 StringId name_id,
Lalit Magantie87cc812019-01-10 15:20:06 +0000667 uint32_t cpu,
Lalit Maganti1d915a62019-01-07 12:10:42 +0000668 UniqueTid utid) {
669 timestamps_.emplace_back(timestamp);
670 name_ids_.emplace_back(name_id);
Lalit Magantie87cc812019-01-10 15:20:06 +0000671 cpus_.emplace_back(cpu);
Lalit Maganti1d915a62019-01-07 12:10:42 +0000672 utids_.emplace_back(utid);
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000673 arg_set_ids_.emplace_back(kInvalidArgSetId);
Lalit Maganti1d915a62019-01-07 12:10:42 +0000674 return CreateRowId(TableId::kRawEvents,
675 static_cast<uint32_t>(raw_event_count() - 1));
676 }
677
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000678 void set_arg_set_id(uint32_t row, ArgSetId id) { arg_set_ids_[row] = id; }
679
Lalit Maganti1d915a62019-01-07 12:10:42 +0000680 size_t raw_event_count() const { return timestamps_.size(); }
681
682 const std::deque<int64_t>& timestamps() const { return timestamps_; }
683
684 const std::deque<StringId>& name_ids() const { return name_ids_; }
685
Lalit Magantie87cc812019-01-10 15:20:06 +0000686 const std::deque<uint32_t>& cpus() const { return cpus_; }
687
Lalit Maganti1d915a62019-01-07 12:10:42 +0000688 const std::deque<UniqueTid>& utids() const { return utids_; }
689
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000690 const std::deque<ArgSetId>& arg_set_ids() const { return arg_set_ids_; }
691
Lalit Maganti1d915a62019-01-07 12:10:42 +0000692 private:
693 std::deque<int64_t> timestamps_;
694 std::deque<StringId> name_ids_;
Lalit Magantie87cc812019-01-10 15:20:06 +0000695 std::deque<uint32_t> cpus_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000696 std::deque<UniqueTid> utids_;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +0000697 std::deque<ArgSetId> arg_set_ids_;
Lalit Maganti1d915a62019-01-07 12:10:42 +0000698 };
699
Primiano Tucci2c761ef2019-01-07 20:20:46 +0000700 class AndroidLogs {
701 public:
702 inline size_t AddLogEvent(int64_t timestamp,
703 UniqueTid utid,
704 uint8_t prio,
705 StringId tag_id,
706 StringId msg_id) {
707 timestamps_.emplace_back(timestamp);
708 utids_.emplace_back(utid);
709 prios_.emplace_back(prio);
710 tag_ids_.emplace_back(tag_id);
711 msg_ids_.emplace_back(msg_id);
712 return size() - 1;
713 }
714
715 size_t size() const { return timestamps_.size(); }
716
717 const std::deque<int64_t>& timestamps() const { return timestamps_; }
718 const std::deque<UniqueTid>& utids() const { return utids_; }
719 const std::deque<uint8_t>& prios() const { return prios_; }
720 const std::deque<StringId>& tag_ids() const { return tag_ids_; }
721 const std::deque<StringId>& msg_ids() const { return msg_ids_; }
722
723 private:
724 std::deque<int64_t> timestamps_;
725 std::deque<UniqueTid> utids_;
726 std::deque<uint8_t> prios_;
727 std::deque<StringId> tag_ids_;
728 std::deque<StringId> msg_ids_;
729 };
730
Primiano Tucci0e38a142019-01-07 20:51:09 +0000731 struct Stats {
732 using IndexMap = std::map<int, int64_t>;
733 int64_t value = 0;
734 IndexMap indexed_values;
735 };
736 using StatsMap = std::array<Stats, stats::kNumKeys>;
737
Ryan Savitski51413ad2019-07-09 14:25:21 +0100738 class Metadata {
739 public:
740 const std::deque<metadata::KeyIDs>& keys() const { return keys_; }
741 const std::deque<Variadic>& values() const { return values_; }
742
743 RowId SetScalarMetadata(metadata::KeyIDs key, Variadic value) {
744 PERFETTO_DCHECK(key < metadata::kNumKeys);
745 PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kSingle);
746 PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]);
747
748 // Already set - on release builds, overwrite the previous value.
749 auto it = scalar_indices.find(key);
750 if (it != scalar_indices.end()) {
751 PERFETTO_DFATAL("Setting a scalar metadata entry more than once.");
752 uint32_t index = static_cast<uint32_t>(it->second);
753 values_[index] = value;
754 return TraceStorage::CreateRowId(kMetadataTable, index);
755 }
756 // First time setting this key.
757 keys_.push_back(key);
758 values_.push_back(value);
759 uint32_t index = static_cast<uint32_t>(keys_.size() - 1);
760 scalar_indices[key] = index;
761 return TraceStorage::CreateRowId(kMetadataTable, index);
762 }
763
764 RowId AppendMetadata(metadata::KeyIDs key, Variadic value) {
765 PERFETTO_DCHECK(key < metadata::kNumKeys);
766 PERFETTO_DCHECK(metadata::kKeyTypes[key] == metadata::kMulti);
767 PERFETTO_DCHECK(value.type == metadata::kValueTypes[key]);
768
769 keys_.push_back(key);
770 values_.push_back(value);
771 uint32_t index = static_cast<uint32_t>(keys_.size() - 1);
772 return TraceStorage::CreateRowId(kMetadataTable, index);
773 }
774
Ryan Savitski0476ee92019-07-09 14:29:33 +0100775 void OverwriteMetadata(uint32_t index, Variadic value) {
776 PERFETTO_DCHECK(index < values_.size());
777 values_[index] = value;
778 }
779
Ryan Savitski51413ad2019-07-09 14:25:21 +0100780 private:
781 std::deque<metadata::KeyIDs> keys_;
782 std::deque<Variadic> values_;
783 // Extraneous state to track locations of entries that should have at most
784 // one row. Used only to maintain uniqueness during insertions.
785 std::map<metadata::KeyIDs, uint32_t> scalar_indices;
786 };
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100787
Florian Mayer438b5ab2019-05-02 11:18:06 +0100788 class HeapProfileFrames {
789 public:
Florian Mayerbee52132019-05-02 13:59:56 +0100790 struct Row {
791 StringId name_id;
792 int64_t mapping_row;
793 int64_t rel_pc;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100794
Florian Mayerbee52132019-05-02 13:59:56 +0100795 bool operator==(const Row& other) const {
796 return std::tie(name_id, mapping_row, rel_pc) ==
797 std::tie(other.name_id, other.mapping_row, other.rel_pc);
798 }
799 };
800
Lalit Maganti9b2d52b2019-05-07 14:32:15 +0100801 uint32_t size() const { return static_cast<uint32_t>(names_.size()); }
802
Florian Mayerbee52132019-05-02 13:59:56 +0100803 int64_t Insert(const Row& row) {
804 names_.emplace_back(row.name_id);
805 mappings_.emplace_back(row.mapping_row);
806 rel_pcs_.emplace_back(row.rel_pc);
Florian Mayer438b5ab2019-05-02 11:18:06 +0100807 return static_cast<int64_t>(names_.size()) - 1;
808 }
809
810 const std::deque<StringId>& names() const { return names_; }
811 const std::deque<int64_t>& mappings() const { return mappings_; }
812 const std::deque<int64_t>& rel_pcs() const { return rel_pcs_; }
813
814 private:
815 std::deque<StringId> names_;
816 std::deque<int64_t> mappings_;
817 std::deque<int64_t> rel_pcs_;
818 };
819
820 class HeapProfileCallsites {
821 public:
Florian Mayerbee52132019-05-02 13:59:56 +0100822 struct Row {
823 int64_t depth;
824 int64_t parent_id;
825 int64_t frame_row;
826
827 bool operator==(const Row& other) const {
828 return std::tie(depth, parent_id, frame_row) ==
829 std::tie(other.depth, other.parent_id, other.frame_row);
Florian Mayer438b5ab2019-05-02 11:18:06 +0100830 }
Florian Mayerbee52132019-05-02 13:59:56 +0100831 };
832
Lalit Maganti9b2d52b2019-05-07 14:32:15 +0100833 uint32_t size() const { return static_cast<uint32_t>(frame_ids_.size()); }
834
Florian Mayerbee52132019-05-02 13:59:56 +0100835 int64_t Insert(const Row& row) {
836 frame_depths_.emplace_back(row.depth);
837 parent_callsite_ids_.emplace_back(row.parent_id);
838 frame_ids_.emplace_back(row.frame_row);
Florian Mayer438b5ab2019-05-02 11:18:06 +0100839 return static_cast<int64_t>(frame_depths_.size()) - 1;
840 }
841
842 const std::deque<int64_t>& frame_depths() const { return frame_depths_; }
843 const std::deque<int64_t>& parent_callsite_ids() const {
844 return parent_callsite_ids_;
845 }
846 const std::deque<int64_t>& frame_ids() const { return frame_ids_; }
847
848 private:
849 std::deque<int64_t> frame_depths_;
850 std::deque<int64_t> parent_callsite_ids_;
851 std::deque<int64_t> frame_ids_;
852 };
853
854 class HeapProfileMappings {
855 public:
Florian Mayerbee52132019-05-02 13:59:56 +0100856 struct Row {
857 StringId build_id;
Florian Mayer12655732019-07-02 15:08:26 +0100858 int64_t exact_offset;
859 int64_t start_offset;
Florian Mayerbee52132019-05-02 13:59:56 +0100860 int64_t start;
861 int64_t end;
862 int64_t load_bias;
863 StringId name_id;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100864
Florian Mayerbee52132019-05-02 13:59:56 +0100865 bool operator==(const Row& other) const {
Florian Mayer12655732019-07-02 15:08:26 +0100866 return std::tie(build_id, exact_offset, start_offset, start, end,
867 load_bias, name_id) ==
868 std::tie(other.build_id, other.exact_offset, other.start_offset,
869 other.start, other.end, other.load_bias, other.name_id);
Florian Mayerbee52132019-05-02 13:59:56 +0100870 }
871 };
872
Lalit Maganti9b2d52b2019-05-07 14:32:15 +0100873 uint32_t size() const { return static_cast<uint32_t>(names_.size()); }
874
Florian Mayerbee52132019-05-02 13:59:56 +0100875 int64_t Insert(const Row& row) {
876 build_ids_.emplace_back(row.build_id);
Florian Mayer12655732019-07-02 15:08:26 +0100877 exact_offsets_.emplace_back(row.exact_offset);
878 start_offsets_.emplace_back(row.start_offset);
Florian Mayerbee52132019-05-02 13:59:56 +0100879 starts_.emplace_back(row.start);
880 ends_.emplace_back(row.end);
881 load_biases_.emplace_back(row.load_bias);
882 names_.emplace_back(row.name_id);
Florian Mayer438b5ab2019-05-02 11:18:06 +0100883 return static_cast<int64_t>(build_ids_.size()) - 1;
884 }
885
886 const std::deque<StringId>& build_ids() const { return build_ids_; }
Florian Mayer12655732019-07-02 15:08:26 +0100887 const std::deque<int64_t>& exact_offsets() const { return exact_offsets_; }
888 const std::deque<int64_t>& start_offsets() const { return start_offsets_; }
Florian Mayer438b5ab2019-05-02 11:18:06 +0100889 const std::deque<int64_t>& starts() const { return starts_; }
890 const std::deque<int64_t>& ends() const { return ends_; }
891 const std::deque<int64_t>& load_biases() const { return load_biases_; }
892 const std::deque<StringId>& names() const { return names_; }
893
894 private:
895 std::deque<StringId> build_ids_;
Florian Mayer12655732019-07-02 15:08:26 +0100896 std::deque<int64_t> exact_offsets_;
897 std::deque<int64_t> start_offsets_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100898 std::deque<int64_t> starts_;
899 std::deque<int64_t> ends_;
900 std::deque<int64_t> load_biases_;
901 std::deque<StringId> names_;
902 };
903
904 class HeapProfileAllocations {
905 public:
Florian Mayerbee52132019-05-02 13:59:56 +0100906 struct Row {
907 int64_t timestamp;
Florian Mayerdf1968c2019-05-13 16:39:35 +0100908 UniquePid upid;
Florian Mayerbee52132019-05-02 13:59:56 +0100909 int64_t callsite_id;
910 int64_t count;
911 int64_t size;
912 };
913
Lalit Maganti9b2d52b2019-05-07 14:32:15 +0100914 uint32_t size() const { return static_cast<uint32_t>(timestamps_.size()); }
915
Florian Mayerbee52132019-05-02 13:59:56 +0100916 void Insert(const Row& row) {
917 timestamps_.emplace_back(row.timestamp);
Florian Mayerdf1968c2019-05-13 16:39:35 +0100918 upids_.emplace_back(row.upid);
Florian Mayerbee52132019-05-02 13:59:56 +0100919 callsite_ids_.emplace_back(row.callsite_id);
920 counts_.emplace_back(row.count);
921 sizes_.emplace_back(row.size);
Florian Mayer438b5ab2019-05-02 11:18:06 +0100922 }
923
924 const std::deque<int64_t>& timestamps() const { return timestamps_; }
Florian Mayerdf1968c2019-05-13 16:39:35 +0100925 const std::deque<UniquePid>& upids() const { return upids_; }
Florian Mayer438b5ab2019-05-02 11:18:06 +0100926 const std::deque<int64_t>& callsite_ids() const { return callsite_ids_; }
927 const std::deque<int64_t>& counts() const { return counts_; }
928 const std::deque<int64_t>& sizes() const { return sizes_; }
929
930 private:
931 std::deque<int64_t> timestamps_;
Florian Mayerdf1968c2019-05-13 16:39:35 +0100932 std::deque<UniquePid> upids_;
Florian Mayer438b5ab2019-05-02 11:18:06 +0100933 std::deque<int64_t> callsite_ids_;
934 std::deque<int64_t> counts_;
935 std::deque<int64_t> sizes_;
936 };
937
Isabelle Taylora0a22972018-08-03 12:06:12 +0100938 void ResetStorage();
Lalit Maganti35622b72018-06-06 12:03:11 +0100939
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100940 UniqueTid AddEmptyThread(uint32_t tid) {
941 unique_threads_.emplace_back(tid);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100942 return static_cast<UniqueTid>(unique_threads_.size() - 1);
943 }
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100944
Primiano Tuccib75dcee2018-08-08 12:21:36 +0100945 UniquePid AddEmptyProcess(uint32_t pid) {
946 unique_processes_.emplace_back(pid);
Isabelle Taylora0a22972018-08-03 12:06:12 +0100947 return static_cast<UniquePid>(unique_processes_.size() - 1);
948 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100949
Isabelle Taylora0a22972018-08-03 12:06:12 +0100950 // Return an unqiue identifier for the contents of each string.
951 // The string is copied internally and can be destroyed after this called.
Isabelle Taylor15314ea2018-09-19 11:35:19 +0100952 // Virtual for testing.
Lalit Maganti5c454312019-04-08 12:11:17 +0100953 virtual StringId InternString(base::StringView str) {
954 return string_pool_.InternString(str);
955 }
Isabelle Taylor47328cf2018-06-12 14:33:59 +0100956
Isabelle Taylora0a22972018-08-03 12:06:12 +0100957 Process* GetMutableProcess(UniquePid upid) {
Lalit Maganti676658b2018-11-20 18:24:31 +0000958 PERFETTO_DCHECK(upid < unique_processes_.size());
Isabelle Taylora0a22972018-08-03 12:06:12 +0100959 return &unique_processes_[upid];
960 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100961
Isabelle Taylora0a22972018-08-03 12:06:12 +0100962 Thread* GetMutableThread(UniqueTid utid) {
Florian Mayera1aaec22018-09-19 17:02:26 +0100963 PERFETTO_DCHECK(utid < unique_threads_.size());
Isabelle Taylora0a22972018-08-03 12:06:12 +0100964 return &unique_threads_[utid];
965 }
Isabelle Taylor3dd366c2018-06-22 16:21:41 +0100966
Primiano Tucci0e38a142019-01-07 20:51:09 +0000967 // Example usage: SetStats(stats::android_log_num_failed, 42);
968 void SetStats(size_t key, int64_t value) {
969 PERFETTO_DCHECK(key < stats::kNumKeys);
970 PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
971 stats_[key].value = value;
972 }
973
974 // Example usage: IncrementStats(stats::android_log_num_failed, -1);
975 void IncrementStats(size_t key, int64_t increment = 1) {
976 PERFETTO_DCHECK(key < stats::kNumKeys);
977 PERFETTO_DCHECK(stats::kTypes[key] == stats::kSingle);
978 stats_[key].value += increment;
979 }
980
Florian Mayer438b5ab2019-05-02 11:18:06 +0100981 // Example usage: IncrementIndexedStats(stats::cpu_failure, 1);
982 void IncrementIndexedStats(size_t key, int index, int64_t increment = 1) {
983 PERFETTO_DCHECK(key < stats::kNumKeys);
984 PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
985 stats_[key].indexed_values[index] += increment;
986 }
987
Primiano Tucci0e38a142019-01-07 20:51:09 +0000988 // Example usage: SetIndexedStats(stats::cpu_failure, 1, 42);
989 void SetIndexedStats(size_t key, int index, int64_t value) {
990 PERFETTO_DCHECK(key < stats::kNumKeys);
991 PERFETTO_DCHECK(stats::kTypes[key] == stats::kIndexed);
992 stats_[key].indexed_values[index] = value;
993 }
994
Mikhail Khokhlove466c002019-05-23 13:33:33 +0100995 // Example usage:
996 // SetMetadata(metadata::benchmark_name,
997 // Variadic::String(storage->InternString("foo"));
Ryan Savitski51413ad2019-07-09 14:25:21 +0100998 // Returns the RowId of the new entry.
Mikhail Khokhlovb1fe42a2019-05-23 13:58:05 +0100999 // Virtual for testing.
Ryan Savitski51413ad2019-07-09 14:25:21 +01001000 virtual RowId SetMetadata(metadata::KeyIDs key, Variadic value) {
1001 return metadata_.SetScalarMetadata(key, value);
Mikhail Khokhlove466c002019-05-23 13:33:33 +01001002 }
1003
1004 // Example usage:
1005 // AppendMetadata(metadata::benchmark_story_tags,
1006 // Variadic::String(storage->InternString("bar"));
Ryan Savitski51413ad2019-07-09 14:25:21 +01001007 // Returns the RowId of the new entry.
Mikhail Khokhlovb1fe42a2019-05-23 13:58:05 +01001008 // Virtual for testing.
Ryan Savitski51413ad2019-07-09 14:25:21 +01001009 virtual RowId AppendMetadata(metadata::KeyIDs key, Variadic value) {
1010 return metadata_.AppendMetadata(key, value);
Mikhail Khokhlove466c002019-05-23 13:33:33 +01001011 }
1012
Eric Seckler77b52782019-05-02 15:18:57 +01001013 class ScopedStatsTracer {
1014 public:
1015 ScopedStatsTracer(TraceStorage* storage, size_t key)
1016 : storage_(storage), key_(key), start_ns_(base::GetWallTimeNs()) {}
1017
1018 ~ScopedStatsTracer() {
1019 if (!storage_)
1020 return;
1021 auto delta_ns = base::GetWallTimeNs() - start_ns_;
1022 storage_->IncrementStats(key_, delta_ns.count());
1023 }
1024
1025 ScopedStatsTracer(ScopedStatsTracer&& other) noexcept { MoveImpl(&other); }
1026
1027 ScopedStatsTracer& operator=(ScopedStatsTracer&& other) {
1028 MoveImpl(&other);
1029 return *this;
1030 }
1031
1032 private:
1033 ScopedStatsTracer(const ScopedStatsTracer&) = delete;
1034 ScopedStatsTracer& operator=(const ScopedStatsTracer&) = delete;
1035
1036 void MoveImpl(ScopedStatsTracer* other) {
1037 storage_ = other->storage_;
1038 key_ = other->key_;
1039 start_ns_ = other->start_ns_;
1040 other->storage_ = nullptr;
1041 }
1042
1043 TraceStorage* storage_;
1044 size_t key_;
1045 base::TimeNanos start_ns_;
1046 };
1047
1048 ScopedStatsTracer TraceExecutionTimeIntoStats(size_t key) {
1049 return ScopedStatsTracer(this, key);
1050 }
1051
Lalit Maganticaed37e2018-06-01 03:03:08 +01001052 // Reading methods.
Eric Secklerc93823e2019-06-03 16:49:19 +01001053 // Virtual for testing.
1054 virtual NullTermStringView GetString(StringId id) const {
Lalit Maganti5c454312019-04-08 12:11:17 +01001055 return string_pool_.Get(id);
Isabelle Taylora0a22972018-08-03 12:06:12 +01001056 }
1057
Lalit Magantie9d40532018-06-29 13:15:06 +01001058 const Process& GetProcess(UniquePid upid) const {
Lalit Maganti676658b2018-11-20 18:24:31 +00001059 PERFETTO_DCHECK(upid < unique_processes_.size());
Isabelle Taylor47328cf2018-06-12 14:33:59 +01001060 return unique_processes_[upid];
1061 }
1062
Lalit Magantie9d40532018-06-29 13:15:06 +01001063 const Thread& GetThread(UniqueTid utid) const {
Lalit Maganti1f64cfa2018-09-18 13:20:02 +01001064 // Allow utid == 0 for idle thread retrieval.
Florian Mayera1aaec22018-09-19 17:02:26 +01001065 PERFETTO_DCHECK(utid < unique_threads_.size());
Isabelle Taylor68e42192018-06-19 16:19:31 +01001066 return unique_threads_[utid];
1067 }
1068
Lalit Maganti5ea9e932018-11-30 14:19:39 +00001069 static RowId CreateRowId(TableId table, uint32_t row) {
Lalit Maganti85ca4a82018-12-07 17:28:02 +00001070 return (static_cast<RowId>(table) << kRowIdTableShift) | row;
Lalit Maganti5ea9e932018-11-30 14:19:39 +00001071 }
1072
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +00001073 static std::pair<int8_t /*table*/, uint32_t /*row*/> ParseRowId(RowId rowid) {
1074 auto id = static_cast<uint64_t>(rowid);
1075 auto table_id = static_cast<uint8_t>(id >> kRowIdTableShift);
1076 auto row = static_cast<uint32_t>(id & ((1ull << kRowIdTableShift) - 1));
1077 return std::make_pair(table_id, row);
1078 }
1079
Eric Seckler5703ede2019-07-10 10:13:02 +01001080 const VirtualTracks& virtual_tracks() const { return virtual_tracks_; }
1081 VirtualTracks* mutable_virtual_tracks() { return &virtual_tracks_; }
1082
Lalit Magantiff69c112018-09-24 12:07:47 +01001083 const Slices& slices() const { return slices_; }
Lalit Magantifde29042018-10-04 13:28:52 +01001084 Slices* mutable_slices() { return &slices_; }
1085
Primiano Tucci0d72a312018-08-07 14:42:45 +01001086 const NestableSlices& nestable_slices() const { return nestable_slices_; }
1087 NestableSlices* mutable_nestable_slices() { return &nestable_slices_; }
1088
Eric Secklerd3b89d52019-07-10 15:36:29 +01001089 const ThreadSlices& thread_slices() const { return thread_slices_; }
1090 ThreadSlices* mutable_thread_slices() { return &thread_slices_; }
1091
Eric Secklerc3430c62019-07-22 10:49:58 +01001092 const VirtualTrackSlices& virtual_track_slices() const {
1093 return virtual_track_slices_;
1094 }
1095 VirtualTrackSlices* mutable_virtual_track_slices() {
1096 return &virtual_track_slices_;
1097 }
1098
Lalit Maganti8320e6d2019-03-14 18:49:33 +00001099 const CounterDefinitions& counter_definitions() const {
1100 return counter_definitions_;
1101 }
1102 CounterDefinitions* mutable_counter_definitions() {
1103 return &counter_definitions_;
1104 }
1105
1106 const CounterValues& counter_values() const { return counter_values_; }
1107 CounterValues* mutable_counter_values() { return &counter_values_; }
Isabelle Taylor14674d42018-09-07 11:33:11 +01001108
Primiano Tucci5cb84f82018-10-31 21:46:36 -07001109 const SqlStats& sql_stats() const { return sql_stats_; }
1110 SqlStats* mutable_sql_stats() { return &sql_stats_; }
1111
Isabelle Taylorc8c11202018-11-05 11:36:22 +00001112 const Instants& instants() const { return instants_; }
1113 Instants* mutable_instants() { return &instants_; }
1114
Primiano Tucci2c761ef2019-01-07 20:20:46 +00001115 const AndroidLogs& android_logs() const { return android_log_; }
1116 AndroidLogs* mutable_android_log() { return &android_log_; }
1117
Primiano Tucci0e38a142019-01-07 20:51:09 +00001118 const StatsMap& stats() const { return stats_; }
Lalit Maganti05e8c132018-11-09 18:16:12 +00001119
Ryan Savitski51413ad2019-07-09 14:25:21 +01001120 const Metadata& metadata() const { return metadata_; }
Ryan Savitski0476ee92019-07-09 14:29:33 +01001121 Metadata* mutable_metadata() { return &metadata_; }
Mikhail Khokhlove466c002019-05-23 13:33:33 +01001122
Lalit Maganti6e9c55e2018-11-29 12:00:39 +00001123 const Args& args() const { return args_; }
1124 Args* mutable_args() { return &args_; }
1125
Lalit Maganti1d915a62019-01-07 12:10:42 +00001126 const RawEvents& raw_events() const { return raw_events_; }
1127 RawEvents* mutable_raw_events() { return &raw_events_; }
1128
Florian Mayer438b5ab2019-05-02 11:18:06 +01001129 const HeapProfileMappings& heap_profile_mappings() const {
1130 return heap_profile_mappings_;
1131 }
1132 HeapProfileMappings* mutable_heap_profile_mappings() {
1133 return &heap_profile_mappings_;
1134 }
1135
1136 const HeapProfileFrames& heap_profile_frames() const {
1137 return heap_profile_frames_;
1138 }
1139 HeapProfileFrames* mutable_heap_profile_frames() {
1140 return &heap_profile_frames_;
1141 }
1142
1143 const HeapProfileCallsites& heap_profile_callsites() const {
1144 return heap_profile_callsites_;
1145 }
1146 HeapProfileCallsites* mutable_heap_profile_callsites() {
1147 return &heap_profile_callsites_;
1148 }
1149
1150 const HeapProfileAllocations& heap_profile_allocations() const {
1151 return heap_profile_allocations_;
1152 }
1153 HeapProfileAllocations* mutable_heap_profile_allocations() {
1154 return &heap_profile_allocations_;
1155 }
1156
Lalit Maganti5c454312019-04-08 12:11:17 +01001157 const StringPool& string_pool() const { return string_pool_; }
Lalit Magantiacda68b2018-10-29 15:23:25 +00001158
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001159 // |unique_processes_| always contains at least 1 element becuase the 0th ID
1160 // is reserved to indicate an invalid process.
Lalit Maganti9c6395b2019-01-17 00:25:09 +00001161 size_t process_count() const { return unique_processes_.size(); }
Primiano Tucci0d72a312018-08-07 14:42:45 +01001162
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001163 // |unique_threads_| always contains at least 1 element becuase the 0th ID
1164 // is reserved to indicate an invalid thread.
Lalit Maganti9c6395b2019-01-17 00:25:09 +00001165 size_t thread_count() const { return unique_threads_.size(); }
Isabelle Taylore7003fb2018-07-17 11:39:01 +01001166
Hector Dearman12323362018-08-09 16:09:28 +01001167 // Number of interned strings in the pool. Includes the empty string w/ ID=0.
1168 size_t string_count() const { return string_pool_.size(); }
1169
Ioannis Ilkosb8b11102019-01-29 17:56:55 +00001170 // Start / end ts (in nanoseconds) across the parsed trace events.
1171 // Returns (0, 0) if the trace is empty.
1172 std::pair<int64_t, int64_t> GetTraceTimestampBoundsNs() const;
1173
Lalit Maganticaed37e2018-06-01 03:03:08 +01001174 private:
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +00001175 static constexpr uint8_t kRowIdTableShift = 32;
Isabelle Taylora0a22972018-08-03 12:06:12 +01001176
Primiano Tucci2da5d2e2018-08-10 14:23:31 +01001177 using StringHash = uint64_t;
Lalit Maganticaed37e2018-06-01 03:03:08 +01001178
Lalit Maganti5c454312019-04-08 12:11:17 +01001179 TraceStorage(const TraceStorage&) = delete;
1180 TraceStorage& operator=(const TraceStorage&) = delete;
1181
1182 TraceStorage(TraceStorage&&) = default;
1183 TraceStorage& operator=(TraceStorage&&) = default;
Lalit Maganti4fa7c6c2019-02-06 15:06:36 +00001184
Lalit Maganti05e8c132018-11-09 18:16:12 +00001185 // Stats about parsing the trace.
Primiano Tucci0e38a142019-01-07 20:51:09 +00001186 StatsMap stats_{};
Lalit Maganti35622b72018-06-06 12:03:11 +01001187
Ryan Savitski51413ad2019-07-09 14:25:21 +01001188 // Extra data extracted from the trace. Includes:
1189 // * metadata from chrome and benchmarking infrastructure
1190 // * descriptions of android packages
1191 Metadata metadata_{};
Mikhail Khokhlove466c002019-05-23 13:33:33 +01001192
Eric Seckler5703ede2019-07-10 10:13:02 +01001193 // Metadata for virtual slice tracks.
1194 VirtualTracks virtual_tracks_;
1195
Lalit Maganticaed37e2018-06-01 03:03:08 +01001196 // One entry for each CPU in the trace.
Lalit Magantiff69c112018-09-24 12:07:47 +01001197 Slices slices_;
Lalit Maganticaed37e2018-06-01 03:03:08 +01001198
Lalit Maganti6e9c55e2018-11-29 12:00:39 +00001199 // Args for all other tables.
1200 Args args_;
1201
Lalit Maganticaed37e2018-06-01 03:03:08 +01001202 // One entry for each unique string in the trace.
Lalit Maganti5c454312019-04-08 12:11:17 +01001203 StringPool string_pool_;
Isabelle Taylor47328cf2018-06-12 14:33:59 +01001204
Isabelle Taylor47328cf2018-06-12 14:33:59 +01001205 // One entry for each UniquePid, with UniquePid as the index.
Ioannis Ilkos9c03cbd2019-03-12 18:30:43 +00001206 // Never hold on to pointers to Process, as vector resize will
1207 // invalidate them.
1208 std::vector<Process> unique_processes_;
Isabelle Taylor68e42192018-06-19 16:19:31 +01001209
Isabelle Taylor68e42192018-06-19 16:19:31 +01001210 // One entry for each UniqueTid, with UniqueTid as the index.
Isabelle Taylor3dd366c2018-06-22 16:21:41 +01001211 std::deque<Thread> unique_threads_;
Primiano Tucci0d72a312018-08-07 14:42:45 +01001212
1213 // Slices coming from userspace events (e.g. Chromium TRACE_EVENT macros).
1214 NestableSlices nestable_slices_;
Isabelle Taylor15314ea2018-09-19 11:35:19 +01001215
Eric Secklerd3b89d52019-07-10 15:36:29 +01001216 // Additional attributes for threads slices (sub-type of NestableSlices).
1217 ThreadSlices thread_slices_;
1218
Eric Secklerc3430c62019-07-22 10:49:58 +01001219 // Additional attributes for virtual track slices (sub-type of
1220 // NestableSlices).
1221 VirtualTrackSlices virtual_track_slices_;
1222
Hector Dearman2442d612019-06-04 18:05:23 +01001223 // The type of counters in the trace. Can be thought of as the "metadata".
Lalit Maganti8320e6d2019-03-14 18:49:33 +00001224 CounterDefinitions counter_definitions_;
1225
1226 // The values from the Counter events from the trace. This includes CPU
1227 // frequency events as well systrace trace_marker counter events.
1228 CounterValues counter_values_;
Primiano Tucci5cb84f82018-10-31 21:46:36 -07001229
1230 SqlStats sql_stats_;
Lalit Maganti6e9c55e2018-11-29 12:00:39 +00001231
Isabelle Taylorc8c11202018-11-05 11:36:22 +00001232 // These are instantaneous events in the trace. They have no duration
1233 // and do not have a value that make sense to track over time.
1234 // e.g. signal events
1235 Instants instants_;
Lalit Maganti1d915a62019-01-07 12:10:42 +00001236
1237 // Raw events are every ftrace event in the trace. The raw event includes
1238 // the timestamp and the pid. The args for the raw event will be in the
1239 // args table. This table can be used to generate a text version of the
1240 // trace.
1241 RawEvents raw_events_;
Primiano Tucci2c761ef2019-01-07 20:20:46 +00001242 AndroidLogs android_log_;
Florian Mayer438b5ab2019-05-02 11:18:06 +01001243
1244 HeapProfileMappings heap_profile_mappings_;
1245 HeapProfileFrames heap_profile_frames_;
1246 HeapProfileCallsites heap_profile_callsites_;
1247 HeapProfileAllocations heap_profile_allocations_;
Lalit Maganticaed37e2018-06-01 03:03:08 +01001248};
1249
1250} // namespace trace_processor
1251} // namespace perfetto
1252
Florian Mayerbee52132019-05-02 13:59:56 +01001253namespace std {
1254
1255template <>
1256struct hash<::perfetto::trace_processor::TraceStorage::HeapProfileFrames::Row> {
1257 using argument_type =
1258 ::perfetto::trace_processor::TraceStorage::HeapProfileFrames::Row;
1259 using result_type = size_t;
1260
1261 result_type operator()(const argument_type& r) const {
1262 return std::hash<::perfetto::trace_processor::StringId>{}(r.name_id) ^
1263 std::hash<int64_t>{}(r.mapping_row) ^ std::hash<int64_t>{}(r.rel_pc);
1264 }
1265};
1266
1267template <>
1268struct hash<
1269 ::perfetto::trace_processor::TraceStorage::HeapProfileCallsites::Row> {
1270 using argument_type =
1271 ::perfetto::trace_processor::TraceStorage::HeapProfileCallsites::Row;
1272 using result_type = size_t;
1273
1274 result_type operator()(const argument_type& r) const {
1275 return std::hash<int64_t>{}(r.depth) ^ std::hash<int64_t>{}(r.parent_id) ^
1276 std::hash<int64_t>{}(r.frame_row);
1277 }
1278};
1279
1280template <>
1281struct hash<
1282 ::perfetto::trace_processor::TraceStorage::HeapProfileMappings::Row> {
1283 using argument_type =
1284 ::perfetto::trace_processor::TraceStorage::HeapProfileMappings::Row;
1285 using result_type = size_t;
1286
1287 result_type operator()(const argument_type& r) const {
1288 return std::hash<::perfetto::trace_processor::StringId>{}(r.build_id) ^
Florian Mayer12655732019-07-02 15:08:26 +01001289 std::hash<int64_t>{}(r.exact_offset) ^
1290 std::hash<int64_t>{}(r.start_offset) ^
1291 std::hash<int64_t>{}(r.start) ^ std::hash<int64_t>{}(r.end) ^
1292 std::hash<int64_t>{}(r.load_bias) ^
Florian Mayerbee52132019-05-02 13:59:56 +01001293 std::hash<::perfetto::trace_processor::StringId>{}(r.name_id);
1294 }
1295};
1296
1297} // namespace std
1298
Lalit Maganticaed37e2018-06-01 03:03:08 +01001299#endif // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_