1 #ifndef SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_PY_H_
2 #define SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_PY_H_
3 
4 #include <array>
5 #include <cstddef>
6 #include <cstdint>
7 #include <memory>
8 #include <optional>
9 #include <type_traits>
10 #include <utility>
11 #include <vector>
12 
13 #include "perfetto/base/logging.h"
14 #include "perfetto/trace_processor/basic_types.h"
15 #include "perfetto/trace_processor/ref_counted.h"
16 #include "src/trace_processor/containers/bit_vector.h"
17 #include "src/trace_processor/containers/row_map.h"
18 #include "src/trace_processor/containers/string_pool.h"
19 #include "src/trace_processor/db/column/arrangement_overlay.h"
20 #include "src/trace_processor/db/column/data_layer.h"
21 #include "src/trace_processor/db/column/dense_null_overlay.h"
22 #include "src/trace_processor/db/column/numeric_storage.h"
23 #include "src/trace_processor/db/column/id_storage.h"
24 #include "src/trace_processor/db/column/null_overlay.h"
25 #include "src/trace_processor/db/column/range_overlay.h"
26 #include "src/trace_processor/db/column/selector_overlay.h"
27 #include "src/trace_processor/db/column/set_id_storage.h"
28 #include "src/trace_processor/db/column/string_storage.h"
29 #include "src/trace_processor/db/column/types.h"
30 #include "src/trace_processor/db/column_storage.h"
31 #include "src/trace_processor/db/column.h"
32 #include "src/trace_processor/db/table.h"
33 #include "src/trace_processor/db/typed_column.h"
34 #include "src/trace_processor/db/typed_column_internal.h"
35 #include "src/trace_processor/tables/macros_internal.h"
36 
37 #include "src/trace_processor/tables/track_tables_py.h"
38 
39 namespace perfetto::trace_processor::tables {
40 
41 class StackProfileMappingTable : public macros_internal::MacroTable {
42  public:
43   static constexpr uint32_t kColumnCount = 9;
44 
45   struct Id : public BaseId {
46     Id() = default;
IdId47     explicit constexpr Id(uint32_t v) : BaseId(v) {}
48   };
49   static_assert(std::is_trivially_destructible_v<Id>,
50                 "Inheritance used without trivial destruction");
51 
52   struct ColumnIndex {
53     static constexpr uint32_t id = 0;
54     static constexpr uint32_t type = 1;
55     static constexpr uint32_t build_id = 2;
56     static constexpr uint32_t exact_offset = 3;
57     static constexpr uint32_t start_offset = 4;
58     static constexpr uint32_t start = 5;
59     static constexpr uint32_t end = 6;
60     static constexpr uint32_t load_bias = 7;
61     static constexpr uint32_t name = 8;
62   };
63   struct ColumnType {
64     using id = IdColumn<StackProfileMappingTable::Id>;
65     using type = TypedColumn<StringPool::Id>;
66     using build_id = TypedColumn<StringPool::Id>;
67     using exact_offset = TypedColumn<int64_t>;
68     using start_offset = TypedColumn<int64_t>;
69     using start = TypedColumn<int64_t>;
70     using end = TypedColumn<int64_t>;
71     using load_bias = TypedColumn<int64_t>;
72     using name = TypedColumn<StringPool::Id>;
73   };
74   struct Row : public macros_internal::RootParentTable::Row {
75     Row(StringPool::Id in_build_id = {},
76         int64_t in_exact_offset = {},
77         int64_t in_start_offset = {},
78         int64_t in_start = {},
79         int64_t in_end = {},
80         int64_t in_load_bias = {},
81         StringPool::Id in_name = {},
82         std::nullptr_t = nullptr)
RowRow83         : macros_internal::RootParentTable::Row(),
84           build_id(in_build_id),
85           exact_offset(in_exact_offset),
86           start_offset(in_start_offset),
87           start(in_start),
88           end(in_end),
89           load_bias(in_load_bias),
90           name(in_name) {
91       type_ = "stack_profile_mapping";
92     }
93     StringPool::Id build_id;
94     int64_t exact_offset;
95     int64_t start_offset;
96     int64_t start;
97     int64_t end;
98     int64_t load_bias;
99     StringPool::Id name;
100 
101     bool operator==(const StackProfileMappingTable::Row& other) const {
102       return type() == other.type() && ColumnType::build_id::Equals(build_id, other.build_id) &&
103        ColumnType::exact_offset::Equals(exact_offset, other.exact_offset) &&
104        ColumnType::start_offset::Equals(start_offset, other.start_offset) &&
105        ColumnType::start::Equals(start, other.start) &&
106        ColumnType::end::Equals(end, other.end) &&
107        ColumnType::load_bias::Equals(load_bias, other.load_bias) &&
108        ColumnType::name::Equals(name, other.name);
109     }
110   };
111   struct ColumnFlag {
112     static constexpr uint32_t build_id = ColumnType::build_id::default_flags();
113     static constexpr uint32_t exact_offset = ColumnType::exact_offset::default_flags();
114     static constexpr uint32_t start_offset = ColumnType::start_offset::default_flags();
115     static constexpr uint32_t start = ColumnType::start::default_flags();
116     static constexpr uint32_t end = ColumnType::end::default_flags();
117     static constexpr uint32_t load_bias = ColumnType::load_bias::default_flags();
118     static constexpr uint32_t name = ColumnType::name::default_flags();
119   };
120 
121   class RowNumber;
122   class ConstRowReference;
123   class RowReference;
124 
125   class RowNumber : public macros_internal::AbstractRowNumber<
126       StackProfileMappingTable, ConstRowReference, RowReference> {
127    public:
RowNumber(uint32_t row_number)128     explicit RowNumber(uint32_t row_number)
129         : AbstractRowNumber(row_number) {}
130   };
131   static_assert(std::is_trivially_destructible_v<RowNumber>,
132                 "Inheritance used without trivial destruction");
133 
134   class ConstRowReference : public macros_internal::AbstractConstRowReference<
135     StackProfileMappingTable, RowNumber> {
136    public:
ConstRowReference(const StackProfileMappingTable * table,uint32_t row_number)137     ConstRowReference(const StackProfileMappingTable* table, uint32_t row_number)
138         : AbstractConstRowReference(table, row_number) {}
139 
id()140     ColumnType::id::type id() const {
141       return table()->id()[row_number_];
142     }
type()143     ColumnType::type::type type() const {
144       return table()->type()[row_number_];
145     }
build_id()146     ColumnType::build_id::type build_id() const {
147       return table()->build_id()[row_number_];
148     }
exact_offset()149     ColumnType::exact_offset::type exact_offset() const {
150       return table()->exact_offset()[row_number_];
151     }
start_offset()152     ColumnType::start_offset::type start_offset() const {
153       return table()->start_offset()[row_number_];
154     }
start()155     ColumnType::start::type start() const {
156       return table()->start()[row_number_];
157     }
end()158     ColumnType::end::type end() const {
159       return table()->end()[row_number_];
160     }
load_bias()161     ColumnType::load_bias::type load_bias() const {
162       return table()->load_bias()[row_number_];
163     }
name()164     ColumnType::name::type name() const {
165       return table()->name()[row_number_];
166     }
167   };
168   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
169                 "Inheritance used without trivial destruction");
170   class RowReference : public ConstRowReference {
171    public:
RowReference(const StackProfileMappingTable * table,uint32_t row_number)172     RowReference(const StackProfileMappingTable* table, uint32_t row_number)
173         : ConstRowReference(table, row_number) {}
174 
set_build_id(ColumnType::build_id::non_optional_type v)175     void set_build_id(
176         ColumnType::build_id::non_optional_type v) {
177       return mutable_table()->mutable_build_id()->Set(row_number_, v);
178     }
set_exact_offset(ColumnType::exact_offset::non_optional_type v)179     void set_exact_offset(
180         ColumnType::exact_offset::non_optional_type v) {
181       return mutable_table()->mutable_exact_offset()->Set(row_number_, v);
182     }
set_start_offset(ColumnType::start_offset::non_optional_type v)183     void set_start_offset(
184         ColumnType::start_offset::non_optional_type v) {
185       return mutable_table()->mutable_start_offset()->Set(row_number_, v);
186     }
set_start(ColumnType::start::non_optional_type v)187     void set_start(
188         ColumnType::start::non_optional_type v) {
189       return mutable_table()->mutable_start()->Set(row_number_, v);
190     }
set_end(ColumnType::end::non_optional_type v)191     void set_end(
192         ColumnType::end::non_optional_type v) {
193       return mutable_table()->mutable_end()->Set(row_number_, v);
194     }
set_load_bias(ColumnType::load_bias::non_optional_type v)195     void set_load_bias(
196         ColumnType::load_bias::non_optional_type v) {
197       return mutable_table()->mutable_load_bias()->Set(row_number_, v);
198     }
set_name(ColumnType::name::non_optional_type v)199     void set_name(
200         ColumnType::name::non_optional_type v) {
201       return mutable_table()->mutable_name()->Set(row_number_, v);
202     }
203 
204    private:
mutable_table()205     StackProfileMappingTable* mutable_table() const {
206       return const_cast<StackProfileMappingTable*>(table());
207     }
208   };
209   static_assert(std::is_trivially_destructible_v<RowReference>,
210                 "Inheritance used without trivial destruction");
211 
212   class ConstIterator;
213   class ConstIterator : public macros_internal::AbstractConstIterator<
214     ConstIterator, StackProfileMappingTable, RowNumber, ConstRowReference> {
215    public:
id()216     ColumnType::id::type id() const {
217       const auto& col = table()->id();
218       return col.GetAtIdx(
219         iterator_.StorageIndexForColumn(col.index_in_table()));
220     }
type()221     ColumnType::type::type type() const {
222       const auto& col = table()->type();
223       return col.GetAtIdx(
224         iterator_.StorageIndexForColumn(col.index_in_table()));
225     }
build_id()226     ColumnType::build_id::type build_id() const {
227       const auto& col = table()->build_id();
228       return col.GetAtIdx(
229         iterator_.StorageIndexForColumn(col.index_in_table()));
230     }
exact_offset()231     ColumnType::exact_offset::type exact_offset() const {
232       const auto& col = table()->exact_offset();
233       return col.GetAtIdx(
234         iterator_.StorageIndexForColumn(col.index_in_table()));
235     }
start_offset()236     ColumnType::start_offset::type start_offset() const {
237       const auto& col = table()->start_offset();
238       return col.GetAtIdx(
239         iterator_.StorageIndexForColumn(col.index_in_table()));
240     }
start()241     ColumnType::start::type start() const {
242       const auto& col = table()->start();
243       return col.GetAtIdx(
244         iterator_.StorageIndexForColumn(col.index_in_table()));
245     }
end()246     ColumnType::end::type end() const {
247       const auto& col = table()->end();
248       return col.GetAtIdx(
249         iterator_.StorageIndexForColumn(col.index_in_table()));
250     }
load_bias()251     ColumnType::load_bias::type load_bias() const {
252       const auto& col = table()->load_bias();
253       return col.GetAtIdx(
254         iterator_.StorageIndexForColumn(col.index_in_table()));
255     }
name()256     ColumnType::name::type name() const {
257       const auto& col = table()->name();
258       return col.GetAtIdx(
259         iterator_.StorageIndexForColumn(col.index_in_table()));
260     }
261 
262    protected:
ConstIterator(const StackProfileMappingTable * table,Table::Iterator iterator)263     explicit ConstIterator(const StackProfileMappingTable* table,
264                            Table::Iterator iterator)
265         : AbstractConstIterator(table, std::move(iterator)) {}
266 
CurrentRowNumber()267     uint32_t CurrentRowNumber() const {
268       return iterator_.StorageIndexForLastOverlay();
269     }
270 
271    private:
272     friend class StackProfileMappingTable;
273     friend class macros_internal::AbstractConstIterator<
274       ConstIterator, StackProfileMappingTable, RowNumber, ConstRowReference>;
275   };
276   class Iterator : public ConstIterator {
277     public:
row_reference()278      RowReference row_reference() const {
279        return {const_cast<StackProfileMappingTable*>(table()), CurrentRowNumber()};
280      }
281 
282     private:
283      friend class StackProfileMappingTable;
284 
Iterator(StackProfileMappingTable * table,Table::Iterator iterator)285      explicit Iterator(StackProfileMappingTable* table, Table::Iterator iterator)
286         : ConstIterator(table, std::move(iterator)) {}
287   };
288 
289   struct IdAndRow {
290     Id id;
291     uint32_t row;
292     RowReference row_reference;
293     RowNumber row_number;
294   };
295 
GetColumns(StackProfileMappingTable * self,const macros_internal::MacroTable * parent)296   static std::vector<ColumnLegacy> GetColumns(
297       StackProfileMappingTable* self,
298       const macros_internal::MacroTable* parent) {
299     std::vector<ColumnLegacy> columns =
300         CopyColumnsFromParentOrAddRootColumns(self, parent);
301     uint32_t olay_idx = OverlayCount(parent);
302     AddColumnToVector(columns, "build_id", &self->build_id_, ColumnFlag::build_id,
303                       static_cast<uint32_t>(columns.size()), olay_idx);
304     AddColumnToVector(columns, "exact_offset", &self->exact_offset_, ColumnFlag::exact_offset,
305                       static_cast<uint32_t>(columns.size()), olay_idx);
306     AddColumnToVector(columns, "start_offset", &self->start_offset_, ColumnFlag::start_offset,
307                       static_cast<uint32_t>(columns.size()), olay_idx);
308     AddColumnToVector(columns, "start", &self->start_, ColumnFlag::start,
309                       static_cast<uint32_t>(columns.size()), olay_idx);
310     AddColumnToVector(columns, "end", &self->end_, ColumnFlag::end,
311                       static_cast<uint32_t>(columns.size()), olay_idx);
312     AddColumnToVector(columns, "load_bias", &self->load_bias_, ColumnFlag::load_bias,
313                       static_cast<uint32_t>(columns.size()), olay_idx);
314     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
315                       static_cast<uint32_t>(columns.size()), olay_idx);
316     return columns;
317   }
318 
StackProfileMappingTable(StringPool * pool)319   PERFETTO_NO_INLINE explicit StackProfileMappingTable(StringPool* pool)
320       : macros_internal::MacroTable(
321           pool,
322           GetColumns(this, nullptr),
323           nullptr),
324         build_id_(ColumnStorage<ColumnType::build_id::stored_type>::Create<false>()),
325         exact_offset_(ColumnStorage<ColumnType::exact_offset::stored_type>::Create<false>()),
326         start_offset_(ColumnStorage<ColumnType::start_offset::stored_type>::Create<false>()),
327         start_(ColumnStorage<ColumnType::start::stored_type>::Create<false>()),
328         end_(ColumnStorage<ColumnType::end::stored_type>::Create<false>()),
329         load_bias_(ColumnStorage<ColumnType::load_bias::stored_type>::Create<false>()),
330         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>())
331 ,
332         id_storage_layer_(new column::IdStorage()),
333         type_storage_layer_(
334           new column::StringStorage(string_pool(), &type_.vector())),
335         build_id_storage_layer_(
336           new column::StringStorage(string_pool(), &build_id_.vector())),
337         exact_offset_storage_layer_(
338         new column::NumericStorage<ColumnType::exact_offset::non_optional_stored_type>(
339           &exact_offset_.vector(),
340           ColumnTypeHelper<ColumnType::exact_offset::stored_type>::ToColumnType(),
341           false)),
342         start_offset_storage_layer_(
343         new column::NumericStorage<ColumnType::start_offset::non_optional_stored_type>(
344           &start_offset_.vector(),
345           ColumnTypeHelper<ColumnType::start_offset::stored_type>::ToColumnType(),
346           false)),
347         start_storage_layer_(
348         new column::NumericStorage<ColumnType::start::non_optional_stored_type>(
349           &start_.vector(),
350           ColumnTypeHelper<ColumnType::start::stored_type>::ToColumnType(),
351           false)),
352         end_storage_layer_(
353         new column::NumericStorage<ColumnType::end::non_optional_stored_type>(
354           &end_.vector(),
355           ColumnTypeHelper<ColumnType::end::stored_type>::ToColumnType(),
356           false)),
357         load_bias_storage_layer_(
358         new column::NumericStorage<ColumnType::load_bias::non_optional_stored_type>(
359           &load_bias_.vector(),
360           ColumnTypeHelper<ColumnType::load_bias::stored_type>::ToColumnType(),
361           false)),
362         name_storage_layer_(
363           new column::StringStorage(string_pool(), &name_.vector()))
364          {
365     static_assert(
366         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::build_id::stored_type>(
367           ColumnFlag::build_id),
368         "Column type and flag combination is not valid");
369       static_assert(
370         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::exact_offset::stored_type>(
371           ColumnFlag::exact_offset),
372         "Column type and flag combination is not valid");
373       static_assert(
374         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::start_offset::stored_type>(
375           ColumnFlag::start_offset),
376         "Column type and flag combination is not valid");
377       static_assert(
378         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::start::stored_type>(
379           ColumnFlag::start),
380         "Column type and flag combination is not valid");
381       static_assert(
382         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::end::stored_type>(
383           ColumnFlag::end),
384         "Column type and flag combination is not valid");
385       static_assert(
386         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::load_bias::stored_type>(
387           ColumnFlag::load_bias),
388         "Column type and flag combination is not valid");
389       static_assert(
390         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
391           ColumnFlag::name),
392         "Column type and flag combination is not valid");
393     OnConstructionCompletedRegularConstructor(
394       {id_storage_layer_,type_storage_layer_,build_id_storage_layer_,exact_offset_storage_layer_,start_offset_storage_layer_,start_storage_layer_,end_storage_layer_,load_bias_storage_layer_,name_storage_layer_},
395       {{},{},{},{},{},{},{},{},{}});
396   }
397   ~StackProfileMappingTable() override;
398 
Name()399   static const char* Name() { return "stack_profile_mapping"; }
400 
ComputeStaticSchema()401   static Table::Schema ComputeStaticSchema() {
402     Table::Schema schema;
403     schema.columns.emplace_back(Table::Schema::Column{
404         "id", SqlValue::Type::kLong, true, true, false, false});
405     schema.columns.emplace_back(Table::Schema::Column{
406         "type", SqlValue::Type::kString, false, false, false, false});
407     schema.columns.emplace_back(Table::Schema::Column{
408         "build_id", ColumnType::build_id::SqlValueType(), false,
409         false,
410         false,
411         false});
412     schema.columns.emplace_back(Table::Schema::Column{
413         "exact_offset", ColumnType::exact_offset::SqlValueType(), false,
414         false,
415         false,
416         false});
417     schema.columns.emplace_back(Table::Schema::Column{
418         "start_offset", ColumnType::start_offset::SqlValueType(), false,
419         false,
420         false,
421         false});
422     schema.columns.emplace_back(Table::Schema::Column{
423         "start", ColumnType::start::SqlValueType(), false,
424         false,
425         false,
426         false});
427     schema.columns.emplace_back(Table::Schema::Column{
428         "end", ColumnType::end::SqlValueType(), false,
429         false,
430         false,
431         false});
432     schema.columns.emplace_back(Table::Schema::Column{
433         "load_bias", ColumnType::load_bias::SqlValueType(), false,
434         false,
435         false,
436         false});
437     schema.columns.emplace_back(Table::Schema::Column{
438         "name", ColumnType::name::SqlValueType(), false,
439         false,
440         false,
441         false});
442     return schema;
443   }
444 
IterateRows()445   ConstIterator IterateRows() const {
446     return ConstIterator(this, Table::IterateRows());
447   }
448 
IterateRows()449   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
450 
FilterToIterator(const Query & q)451   ConstIterator FilterToIterator(const Query& q) const {
452     return ConstIterator(this, QueryToIterator(q));
453   }
454 
FilterToIterator(const Query & q)455   Iterator FilterToIterator(const Query& q) {
456     return Iterator(this, QueryToIterator(q));
457   }
458 
ShrinkToFit()459   void ShrinkToFit() {
460     type_.ShrinkToFit();
461     build_id_.ShrinkToFit();
462     exact_offset_.ShrinkToFit();
463     start_offset_.ShrinkToFit();
464     start_.ShrinkToFit();
465     end_.ShrinkToFit();
466     load_bias_.ShrinkToFit();
467     name_.ShrinkToFit();
468   }
469 
470   ConstRowReference operator[](uint32_t r) const {
471     return ConstRowReference(this, r);
472   }
473   RowReference operator[](uint32_t r) { return RowReference(this, r); }
474   ConstRowReference operator[](RowNumber r) const {
475     return ConstRowReference(this, r.row_number());
476   }
477   RowReference operator[](RowNumber r) {
478     return RowReference(this, r.row_number());
479   }
480 
FindById(Id find_id)481   std::optional<ConstRowReference> FindById(Id find_id) const {
482     std::optional<uint32_t> row = id().IndexOf(find_id);
483     return row ? std::make_optional(ConstRowReference(this, *row))
484                : std::nullopt;
485   }
486 
FindById(Id find_id)487   std::optional<RowReference> FindById(Id find_id) {
488     std::optional<uint32_t> row = id().IndexOf(find_id);
489     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
490   }
491 
Insert(const Row & row)492   IdAndRow Insert(const Row& row) {
493     uint32_t row_number = row_count();
494     Id id = Id{row_number};
495     type_.Append(string_pool()->InternString(row.type()));
496     mutable_build_id()->Append(row.build_id);
497     mutable_exact_offset()->Append(row.exact_offset);
498     mutable_start_offset()->Append(row.start_offset);
499     mutable_start()->Append(row.start);
500     mutable_end()->Append(row.end);
501     mutable_load_bias()->Append(row.load_bias);
502     mutable_name()->Append(row.name);
503     UpdateSelfOverlayAfterInsert();
504     return IdAndRow{id, row_number, RowReference(this, row_number),
505                      RowNumber(row_number)};
506   }
507 
508 
509 
id()510   const IdColumn<StackProfileMappingTable::Id>& id() const {
511     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
512   }
type()513   const TypedColumn<StringPool::Id>& type() const {
514     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
515   }
build_id()516   const TypedColumn<StringPool::Id>& build_id() const {
517     return static_cast<const ColumnType::build_id&>(columns()[ColumnIndex::build_id]);
518   }
exact_offset()519   const TypedColumn<int64_t>& exact_offset() const {
520     return static_cast<const ColumnType::exact_offset&>(columns()[ColumnIndex::exact_offset]);
521   }
start_offset()522   const TypedColumn<int64_t>& start_offset() const {
523     return static_cast<const ColumnType::start_offset&>(columns()[ColumnIndex::start_offset]);
524   }
start()525   const TypedColumn<int64_t>& start() const {
526     return static_cast<const ColumnType::start&>(columns()[ColumnIndex::start]);
527   }
end()528   const TypedColumn<int64_t>& end() const {
529     return static_cast<const ColumnType::end&>(columns()[ColumnIndex::end]);
530   }
load_bias()531   const TypedColumn<int64_t>& load_bias() const {
532     return static_cast<const ColumnType::load_bias&>(columns()[ColumnIndex::load_bias]);
533   }
name()534   const TypedColumn<StringPool::Id>& name() const {
535     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
536   }
537 
mutable_build_id()538   TypedColumn<StringPool::Id>* mutable_build_id() {
539     return static_cast<ColumnType::build_id*>(
540         GetColumn(ColumnIndex::build_id));
541   }
mutable_exact_offset()542   TypedColumn<int64_t>* mutable_exact_offset() {
543     return static_cast<ColumnType::exact_offset*>(
544         GetColumn(ColumnIndex::exact_offset));
545   }
mutable_start_offset()546   TypedColumn<int64_t>* mutable_start_offset() {
547     return static_cast<ColumnType::start_offset*>(
548         GetColumn(ColumnIndex::start_offset));
549   }
mutable_start()550   TypedColumn<int64_t>* mutable_start() {
551     return static_cast<ColumnType::start*>(
552         GetColumn(ColumnIndex::start));
553   }
mutable_end()554   TypedColumn<int64_t>* mutable_end() {
555     return static_cast<ColumnType::end*>(
556         GetColumn(ColumnIndex::end));
557   }
mutable_load_bias()558   TypedColumn<int64_t>* mutable_load_bias() {
559     return static_cast<ColumnType::load_bias*>(
560         GetColumn(ColumnIndex::load_bias));
561   }
mutable_name()562   TypedColumn<StringPool::Id>* mutable_name() {
563     return static_cast<ColumnType::name*>(
564         GetColumn(ColumnIndex::name));
565   }
566 
567  private:
568 
569 
570   ColumnStorage<ColumnType::build_id::stored_type> build_id_;
571   ColumnStorage<ColumnType::exact_offset::stored_type> exact_offset_;
572   ColumnStorage<ColumnType::start_offset::stored_type> start_offset_;
573   ColumnStorage<ColumnType::start::stored_type> start_;
574   ColumnStorage<ColumnType::end::stored_type> end_;
575   ColumnStorage<ColumnType::load_bias::stored_type> load_bias_;
576   ColumnStorage<ColumnType::name::stored_type> name_;
577 
578   RefPtr<column::StorageLayer> id_storage_layer_;
579   RefPtr<column::StorageLayer> type_storage_layer_;
580   RefPtr<column::StorageLayer> build_id_storage_layer_;
581   RefPtr<column::StorageLayer> exact_offset_storage_layer_;
582   RefPtr<column::StorageLayer> start_offset_storage_layer_;
583   RefPtr<column::StorageLayer> start_storage_layer_;
584   RefPtr<column::StorageLayer> end_storage_layer_;
585   RefPtr<column::StorageLayer> load_bias_storage_layer_;
586   RefPtr<column::StorageLayer> name_storage_layer_;
587 
588 
589 };
590 
591 
592 class StackProfileFrameTable : public macros_internal::MacroTable {
593  public:
594   static constexpr uint32_t kColumnCount = 7;
595 
596   struct Id : public BaseId {
597     Id() = default;
IdId598     explicit constexpr Id(uint32_t v) : BaseId(v) {}
599   };
600   static_assert(std::is_trivially_destructible_v<Id>,
601                 "Inheritance used without trivial destruction");
602 
603   struct ColumnIndex {
604     static constexpr uint32_t id = 0;
605     static constexpr uint32_t type = 1;
606     static constexpr uint32_t name = 2;
607     static constexpr uint32_t mapping = 3;
608     static constexpr uint32_t rel_pc = 4;
609     static constexpr uint32_t symbol_set_id = 5;
610     static constexpr uint32_t deobfuscated_name = 6;
611   };
612   struct ColumnType {
613     using id = IdColumn<StackProfileFrameTable::Id>;
614     using type = TypedColumn<StringPool::Id>;
615     using name = TypedColumn<StringPool::Id>;
616     using mapping = TypedColumn<StackProfileMappingTable::Id>;
617     using rel_pc = TypedColumn<int64_t>;
618     using symbol_set_id = TypedColumn<std::optional<uint32_t>>;
619     using deobfuscated_name = TypedColumn<std::optional<StringPool::Id>>;
620   };
621   struct Row : public macros_internal::RootParentTable::Row {
622     Row(StringPool::Id in_name = {},
623         StackProfileMappingTable::Id in_mapping = {},
624         int64_t in_rel_pc = {},
625         std::optional<uint32_t> in_symbol_set_id = {},
626         std::optional<StringPool::Id> in_deobfuscated_name = {},
627         std::nullptr_t = nullptr)
RowRow628         : macros_internal::RootParentTable::Row(),
629           name(in_name),
630           mapping(in_mapping),
631           rel_pc(in_rel_pc),
632           symbol_set_id(in_symbol_set_id),
633           deobfuscated_name(in_deobfuscated_name) {
634       type_ = "stack_profile_frame";
635     }
636     StringPool::Id name;
637     StackProfileMappingTable::Id mapping;
638     int64_t rel_pc;
639     std::optional<uint32_t> symbol_set_id;
640     std::optional<StringPool::Id> deobfuscated_name;
641 
642     bool operator==(const StackProfileFrameTable::Row& other) const {
643       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
644        ColumnType::mapping::Equals(mapping, other.mapping) &&
645        ColumnType::rel_pc::Equals(rel_pc, other.rel_pc) &&
646        ColumnType::symbol_set_id::Equals(symbol_set_id, other.symbol_set_id) &&
647        ColumnType::deobfuscated_name::Equals(deobfuscated_name, other.deobfuscated_name);
648     }
649   };
650   struct ColumnFlag {
651     static constexpr uint32_t name = ColumnType::name::default_flags();
652     static constexpr uint32_t mapping = ColumnType::mapping::default_flags();
653     static constexpr uint32_t rel_pc = ColumnType::rel_pc::default_flags();
654     static constexpr uint32_t symbol_set_id = static_cast<uint32_t>(ColumnLegacy::Flag::kDense) | ColumnType::symbol_set_id::default_flags();
655     static constexpr uint32_t deobfuscated_name = ColumnType::deobfuscated_name::default_flags();
656   };
657 
658   class RowNumber;
659   class ConstRowReference;
660   class RowReference;
661 
662   class RowNumber : public macros_internal::AbstractRowNumber<
663       StackProfileFrameTable, ConstRowReference, RowReference> {
664    public:
RowNumber(uint32_t row_number)665     explicit RowNumber(uint32_t row_number)
666         : AbstractRowNumber(row_number) {}
667   };
668   static_assert(std::is_trivially_destructible_v<RowNumber>,
669                 "Inheritance used without trivial destruction");
670 
671   class ConstRowReference : public macros_internal::AbstractConstRowReference<
672     StackProfileFrameTable, RowNumber> {
673    public:
ConstRowReference(const StackProfileFrameTable * table,uint32_t row_number)674     ConstRowReference(const StackProfileFrameTable* table, uint32_t row_number)
675         : AbstractConstRowReference(table, row_number) {}
676 
id()677     ColumnType::id::type id() const {
678       return table()->id()[row_number_];
679     }
type()680     ColumnType::type::type type() const {
681       return table()->type()[row_number_];
682     }
name()683     ColumnType::name::type name() const {
684       return table()->name()[row_number_];
685     }
mapping()686     ColumnType::mapping::type mapping() const {
687       return table()->mapping()[row_number_];
688     }
rel_pc()689     ColumnType::rel_pc::type rel_pc() const {
690       return table()->rel_pc()[row_number_];
691     }
symbol_set_id()692     ColumnType::symbol_set_id::type symbol_set_id() const {
693       return table()->symbol_set_id()[row_number_];
694     }
deobfuscated_name()695     ColumnType::deobfuscated_name::type deobfuscated_name() const {
696       return table()->deobfuscated_name()[row_number_];
697     }
698   };
699   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
700                 "Inheritance used without trivial destruction");
701   class RowReference : public ConstRowReference {
702    public:
RowReference(const StackProfileFrameTable * table,uint32_t row_number)703     RowReference(const StackProfileFrameTable* table, uint32_t row_number)
704         : ConstRowReference(table, row_number) {}
705 
set_name(ColumnType::name::non_optional_type v)706     void set_name(
707         ColumnType::name::non_optional_type v) {
708       return mutable_table()->mutable_name()->Set(row_number_, v);
709     }
set_mapping(ColumnType::mapping::non_optional_type v)710     void set_mapping(
711         ColumnType::mapping::non_optional_type v) {
712       return mutable_table()->mutable_mapping()->Set(row_number_, v);
713     }
set_rel_pc(ColumnType::rel_pc::non_optional_type v)714     void set_rel_pc(
715         ColumnType::rel_pc::non_optional_type v) {
716       return mutable_table()->mutable_rel_pc()->Set(row_number_, v);
717     }
set_symbol_set_id(ColumnType::symbol_set_id::non_optional_type v)718     void set_symbol_set_id(
719         ColumnType::symbol_set_id::non_optional_type v) {
720       return mutable_table()->mutable_symbol_set_id()->Set(row_number_, v);
721     }
set_deobfuscated_name(ColumnType::deobfuscated_name::non_optional_type v)722     void set_deobfuscated_name(
723         ColumnType::deobfuscated_name::non_optional_type v) {
724       return mutable_table()->mutable_deobfuscated_name()->Set(row_number_, v);
725     }
726 
727    private:
mutable_table()728     StackProfileFrameTable* mutable_table() const {
729       return const_cast<StackProfileFrameTable*>(table());
730     }
731   };
732   static_assert(std::is_trivially_destructible_v<RowReference>,
733                 "Inheritance used without trivial destruction");
734 
735   class ConstIterator;
736   class ConstIterator : public macros_internal::AbstractConstIterator<
737     ConstIterator, StackProfileFrameTable, RowNumber, ConstRowReference> {
738    public:
id()739     ColumnType::id::type id() const {
740       const auto& col = table()->id();
741       return col.GetAtIdx(
742         iterator_.StorageIndexForColumn(col.index_in_table()));
743     }
type()744     ColumnType::type::type type() const {
745       const auto& col = table()->type();
746       return col.GetAtIdx(
747         iterator_.StorageIndexForColumn(col.index_in_table()));
748     }
name()749     ColumnType::name::type name() const {
750       const auto& col = table()->name();
751       return col.GetAtIdx(
752         iterator_.StorageIndexForColumn(col.index_in_table()));
753     }
mapping()754     ColumnType::mapping::type mapping() const {
755       const auto& col = table()->mapping();
756       return col.GetAtIdx(
757         iterator_.StorageIndexForColumn(col.index_in_table()));
758     }
rel_pc()759     ColumnType::rel_pc::type rel_pc() const {
760       const auto& col = table()->rel_pc();
761       return col.GetAtIdx(
762         iterator_.StorageIndexForColumn(col.index_in_table()));
763     }
symbol_set_id()764     ColumnType::symbol_set_id::type symbol_set_id() const {
765       const auto& col = table()->symbol_set_id();
766       return col.GetAtIdx(
767         iterator_.StorageIndexForColumn(col.index_in_table()));
768     }
deobfuscated_name()769     ColumnType::deobfuscated_name::type deobfuscated_name() const {
770       const auto& col = table()->deobfuscated_name();
771       return col.GetAtIdx(
772         iterator_.StorageIndexForColumn(col.index_in_table()));
773     }
774 
775    protected:
ConstIterator(const StackProfileFrameTable * table,Table::Iterator iterator)776     explicit ConstIterator(const StackProfileFrameTable* table,
777                            Table::Iterator iterator)
778         : AbstractConstIterator(table, std::move(iterator)) {}
779 
CurrentRowNumber()780     uint32_t CurrentRowNumber() const {
781       return iterator_.StorageIndexForLastOverlay();
782     }
783 
784    private:
785     friend class StackProfileFrameTable;
786     friend class macros_internal::AbstractConstIterator<
787       ConstIterator, StackProfileFrameTable, RowNumber, ConstRowReference>;
788   };
789   class Iterator : public ConstIterator {
790     public:
row_reference()791      RowReference row_reference() const {
792        return {const_cast<StackProfileFrameTable*>(table()), CurrentRowNumber()};
793      }
794 
795     private:
796      friend class StackProfileFrameTable;
797 
Iterator(StackProfileFrameTable * table,Table::Iterator iterator)798      explicit Iterator(StackProfileFrameTable* table, Table::Iterator iterator)
799         : ConstIterator(table, std::move(iterator)) {}
800   };
801 
802   struct IdAndRow {
803     Id id;
804     uint32_t row;
805     RowReference row_reference;
806     RowNumber row_number;
807   };
808 
GetColumns(StackProfileFrameTable * self,const macros_internal::MacroTable * parent)809   static std::vector<ColumnLegacy> GetColumns(
810       StackProfileFrameTable* self,
811       const macros_internal::MacroTable* parent) {
812     std::vector<ColumnLegacy> columns =
813         CopyColumnsFromParentOrAddRootColumns(self, parent);
814     uint32_t olay_idx = OverlayCount(parent);
815     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
816                       static_cast<uint32_t>(columns.size()), olay_idx);
817     AddColumnToVector(columns, "mapping", &self->mapping_, ColumnFlag::mapping,
818                       static_cast<uint32_t>(columns.size()), olay_idx);
819     AddColumnToVector(columns, "rel_pc", &self->rel_pc_, ColumnFlag::rel_pc,
820                       static_cast<uint32_t>(columns.size()), olay_idx);
821     AddColumnToVector(columns, "symbol_set_id", &self->symbol_set_id_, ColumnFlag::symbol_set_id,
822                       static_cast<uint32_t>(columns.size()), olay_idx);
823     AddColumnToVector(columns, "deobfuscated_name", &self->deobfuscated_name_, ColumnFlag::deobfuscated_name,
824                       static_cast<uint32_t>(columns.size()), olay_idx);
825     return columns;
826   }
827 
StackProfileFrameTable(StringPool * pool)828   PERFETTO_NO_INLINE explicit StackProfileFrameTable(StringPool* pool)
829       : macros_internal::MacroTable(
830           pool,
831           GetColumns(this, nullptr),
832           nullptr),
833         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>()),
834         mapping_(ColumnStorage<ColumnType::mapping::stored_type>::Create<false>()),
835         rel_pc_(ColumnStorage<ColumnType::rel_pc::stored_type>::Create<false>()),
836         symbol_set_id_(ColumnStorage<ColumnType::symbol_set_id::stored_type>::Create<true>()),
837         deobfuscated_name_(ColumnStorage<ColumnType::deobfuscated_name::stored_type>::Create<false>())
838 ,
839         id_storage_layer_(new column::IdStorage()),
840         type_storage_layer_(
841           new column::StringStorage(string_pool(), &type_.vector())),
842         name_storage_layer_(
843           new column::StringStorage(string_pool(), &name_.vector())),
844         mapping_storage_layer_(
845         new column::NumericStorage<ColumnType::mapping::non_optional_stored_type>(
846           &mapping_.vector(),
847           ColumnTypeHelper<ColumnType::mapping::stored_type>::ToColumnType(),
848           false)),
849         rel_pc_storage_layer_(
850         new column::NumericStorage<ColumnType::rel_pc::non_optional_stored_type>(
851           &rel_pc_.vector(),
852           ColumnTypeHelper<ColumnType::rel_pc::stored_type>::ToColumnType(),
853           false)),
854         symbol_set_id_storage_layer_(
855           new column::NumericStorage<ColumnType::symbol_set_id::non_optional_stored_type>(
856             &symbol_set_id_.non_null_vector(),
857             ColumnTypeHelper<ColumnType::symbol_set_id::stored_type>::ToColumnType(),
858             false)),
859         deobfuscated_name_storage_layer_(
860           new column::StringStorage(string_pool(), &deobfuscated_name_.vector()))
861 ,
862         symbol_set_id_null_layer_(new column::DenseNullOverlay(symbol_set_id_.bv())) {
863     static_assert(
864         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
865           ColumnFlag::name),
866         "Column type and flag combination is not valid");
867       static_assert(
868         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::mapping::stored_type>(
869           ColumnFlag::mapping),
870         "Column type and flag combination is not valid");
871       static_assert(
872         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::rel_pc::stored_type>(
873           ColumnFlag::rel_pc),
874         "Column type and flag combination is not valid");
875       static_assert(
876         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::symbol_set_id::stored_type>(
877           ColumnFlag::symbol_set_id),
878         "Column type and flag combination is not valid");
879       static_assert(
880         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::deobfuscated_name::stored_type>(
881           ColumnFlag::deobfuscated_name),
882         "Column type and flag combination is not valid");
883     OnConstructionCompletedRegularConstructor(
884       {id_storage_layer_,type_storage_layer_,name_storage_layer_,mapping_storage_layer_,rel_pc_storage_layer_,symbol_set_id_storage_layer_,deobfuscated_name_storage_layer_},
885       {{},{},{},{},{},symbol_set_id_null_layer_,{}});
886   }
887   ~StackProfileFrameTable() override;
888 
Name()889   static const char* Name() { return "stack_profile_frame"; }
890 
ComputeStaticSchema()891   static Table::Schema ComputeStaticSchema() {
892     Table::Schema schema;
893     schema.columns.emplace_back(Table::Schema::Column{
894         "id", SqlValue::Type::kLong, true, true, false, false});
895     schema.columns.emplace_back(Table::Schema::Column{
896         "type", SqlValue::Type::kString, false, false, false, false});
897     schema.columns.emplace_back(Table::Schema::Column{
898         "name", ColumnType::name::SqlValueType(), false,
899         false,
900         false,
901         false});
902     schema.columns.emplace_back(Table::Schema::Column{
903         "mapping", ColumnType::mapping::SqlValueType(), false,
904         false,
905         false,
906         false});
907     schema.columns.emplace_back(Table::Schema::Column{
908         "rel_pc", ColumnType::rel_pc::SqlValueType(), false,
909         false,
910         false,
911         false});
912     schema.columns.emplace_back(Table::Schema::Column{
913         "symbol_set_id", ColumnType::symbol_set_id::SqlValueType(), false,
914         false,
915         false,
916         false});
917     schema.columns.emplace_back(Table::Schema::Column{
918         "deobfuscated_name", ColumnType::deobfuscated_name::SqlValueType(), false,
919         false,
920         false,
921         false});
922     return schema;
923   }
924 
IterateRows()925   ConstIterator IterateRows() const {
926     return ConstIterator(this, Table::IterateRows());
927   }
928 
IterateRows()929   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
930 
FilterToIterator(const Query & q)931   ConstIterator FilterToIterator(const Query& q) const {
932     return ConstIterator(this, QueryToIterator(q));
933   }
934 
FilterToIterator(const Query & q)935   Iterator FilterToIterator(const Query& q) {
936     return Iterator(this, QueryToIterator(q));
937   }
938 
ShrinkToFit()939   void ShrinkToFit() {
940     type_.ShrinkToFit();
941     name_.ShrinkToFit();
942     mapping_.ShrinkToFit();
943     rel_pc_.ShrinkToFit();
944     symbol_set_id_.ShrinkToFit();
945     deobfuscated_name_.ShrinkToFit();
946   }
947 
948   ConstRowReference operator[](uint32_t r) const {
949     return ConstRowReference(this, r);
950   }
951   RowReference operator[](uint32_t r) { return RowReference(this, r); }
952   ConstRowReference operator[](RowNumber r) const {
953     return ConstRowReference(this, r.row_number());
954   }
955   RowReference operator[](RowNumber r) {
956     return RowReference(this, r.row_number());
957   }
958 
FindById(Id find_id)959   std::optional<ConstRowReference> FindById(Id find_id) const {
960     std::optional<uint32_t> row = id().IndexOf(find_id);
961     return row ? std::make_optional(ConstRowReference(this, *row))
962                : std::nullopt;
963   }
964 
FindById(Id find_id)965   std::optional<RowReference> FindById(Id find_id) {
966     std::optional<uint32_t> row = id().IndexOf(find_id);
967     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
968   }
969 
Insert(const Row & row)970   IdAndRow Insert(const Row& row) {
971     uint32_t row_number = row_count();
972     Id id = Id{row_number};
973     type_.Append(string_pool()->InternString(row.type()));
974     mutable_name()->Append(row.name);
975     mutable_mapping()->Append(row.mapping);
976     mutable_rel_pc()->Append(row.rel_pc);
977     mutable_symbol_set_id()->Append(row.symbol_set_id);
978     mutable_deobfuscated_name()->Append(row.deobfuscated_name);
979     UpdateSelfOverlayAfterInsert();
980     return IdAndRow{id, row_number, RowReference(this, row_number),
981                      RowNumber(row_number)};
982   }
983 
984 
985 
id()986   const IdColumn<StackProfileFrameTable::Id>& id() const {
987     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
988   }
type()989   const TypedColumn<StringPool::Id>& type() const {
990     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
991   }
name()992   const TypedColumn<StringPool::Id>& name() const {
993     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
994   }
mapping()995   const TypedColumn<StackProfileMappingTable::Id>& mapping() const {
996     return static_cast<const ColumnType::mapping&>(columns()[ColumnIndex::mapping]);
997   }
rel_pc()998   const TypedColumn<int64_t>& rel_pc() const {
999     return static_cast<const ColumnType::rel_pc&>(columns()[ColumnIndex::rel_pc]);
1000   }
symbol_set_id()1001   const TypedColumn<std::optional<uint32_t>>& symbol_set_id() const {
1002     return static_cast<const ColumnType::symbol_set_id&>(columns()[ColumnIndex::symbol_set_id]);
1003   }
deobfuscated_name()1004   const TypedColumn<std::optional<StringPool::Id>>& deobfuscated_name() const {
1005     return static_cast<const ColumnType::deobfuscated_name&>(columns()[ColumnIndex::deobfuscated_name]);
1006   }
1007 
mutable_name()1008   TypedColumn<StringPool::Id>* mutable_name() {
1009     return static_cast<ColumnType::name*>(
1010         GetColumn(ColumnIndex::name));
1011   }
mutable_mapping()1012   TypedColumn<StackProfileMappingTable::Id>* mutable_mapping() {
1013     return static_cast<ColumnType::mapping*>(
1014         GetColumn(ColumnIndex::mapping));
1015   }
mutable_rel_pc()1016   TypedColumn<int64_t>* mutable_rel_pc() {
1017     return static_cast<ColumnType::rel_pc*>(
1018         GetColumn(ColumnIndex::rel_pc));
1019   }
mutable_symbol_set_id()1020   TypedColumn<std::optional<uint32_t>>* mutable_symbol_set_id() {
1021     return static_cast<ColumnType::symbol_set_id*>(
1022         GetColumn(ColumnIndex::symbol_set_id));
1023   }
mutable_deobfuscated_name()1024   TypedColumn<std::optional<StringPool::Id>>* mutable_deobfuscated_name() {
1025     return static_cast<ColumnType::deobfuscated_name*>(
1026         GetColumn(ColumnIndex::deobfuscated_name));
1027   }
1028 
1029  private:
1030 
1031 
1032   ColumnStorage<ColumnType::name::stored_type> name_;
1033   ColumnStorage<ColumnType::mapping::stored_type> mapping_;
1034   ColumnStorage<ColumnType::rel_pc::stored_type> rel_pc_;
1035   ColumnStorage<ColumnType::symbol_set_id::stored_type> symbol_set_id_;
1036   ColumnStorage<ColumnType::deobfuscated_name::stored_type> deobfuscated_name_;
1037 
1038   RefPtr<column::StorageLayer> id_storage_layer_;
1039   RefPtr<column::StorageLayer> type_storage_layer_;
1040   RefPtr<column::StorageLayer> name_storage_layer_;
1041   RefPtr<column::StorageLayer> mapping_storage_layer_;
1042   RefPtr<column::StorageLayer> rel_pc_storage_layer_;
1043   RefPtr<column::StorageLayer> symbol_set_id_storage_layer_;
1044   RefPtr<column::StorageLayer> deobfuscated_name_storage_layer_;
1045 
1046   RefPtr<column::OverlayLayer> symbol_set_id_null_layer_;
1047 };
1048 
1049 
1050 class StackProfileCallsiteTable : public macros_internal::MacroTable {
1051  public:
1052   static constexpr uint32_t kColumnCount = 5;
1053 
1054   struct Id : public BaseId {
1055     Id() = default;
IdId1056     explicit constexpr Id(uint32_t v) : BaseId(v) {}
1057   };
1058   static_assert(std::is_trivially_destructible_v<Id>,
1059                 "Inheritance used without trivial destruction");
1060 
1061   struct ColumnIndex {
1062     static constexpr uint32_t id = 0;
1063     static constexpr uint32_t type = 1;
1064     static constexpr uint32_t depth = 2;
1065     static constexpr uint32_t parent_id = 3;
1066     static constexpr uint32_t frame_id = 4;
1067   };
1068   struct ColumnType {
1069     using id = IdColumn<StackProfileCallsiteTable::Id>;
1070     using type = TypedColumn<StringPool::Id>;
1071     using depth = TypedColumn<uint32_t>;
1072     using parent_id = TypedColumn<std::optional<StackProfileCallsiteTable::Id>>;
1073     using frame_id = TypedColumn<StackProfileFrameTable::Id>;
1074   };
1075   struct Row : public macros_internal::RootParentTable::Row {
1076     Row(uint32_t in_depth = {},
1077         std::optional<StackProfileCallsiteTable::Id> in_parent_id = {},
1078         StackProfileFrameTable::Id in_frame_id = {},
1079         std::nullptr_t = nullptr)
RowRow1080         : macros_internal::RootParentTable::Row(),
1081           depth(in_depth),
1082           parent_id(in_parent_id),
1083           frame_id(in_frame_id) {
1084       type_ = "stack_profile_callsite";
1085     }
1086     uint32_t depth;
1087     std::optional<StackProfileCallsiteTable::Id> parent_id;
1088     StackProfileFrameTable::Id frame_id;
1089 
1090     bool operator==(const StackProfileCallsiteTable::Row& other) const {
1091       return type() == other.type() && ColumnType::depth::Equals(depth, other.depth) &&
1092        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
1093        ColumnType::frame_id::Equals(frame_id, other.frame_id);
1094     }
1095   };
1096   struct ColumnFlag {
1097     static constexpr uint32_t depth = ColumnType::depth::default_flags();
1098     static constexpr uint32_t parent_id = ColumnType::parent_id::default_flags();
1099     static constexpr uint32_t frame_id = ColumnType::frame_id::default_flags();
1100   };
1101 
1102   class RowNumber;
1103   class ConstRowReference;
1104   class RowReference;
1105 
1106   class RowNumber : public macros_internal::AbstractRowNumber<
1107       StackProfileCallsiteTable, ConstRowReference, RowReference> {
1108    public:
RowNumber(uint32_t row_number)1109     explicit RowNumber(uint32_t row_number)
1110         : AbstractRowNumber(row_number) {}
1111   };
1112   static_assert(std::is_trivially_destructible_v<RowNumber>,
1113                 "Inheritance used without trivial destruction");
1114 
1115   class ConstRowReference : public macros_internal::AbstractConstRowReference<
1116     StackProfileCallsiteTable, RowNumber> {
1117    public:
ConstRowReference(const StackProfileCallsiteTable * table,uint32_t row_number)1118     ConstRowReference(const StackProfileCallsiteTable* table, uint32_t row_number)
1119         : AbstractConstRowReference(table, row_number) {}
1120 
id()1121     ColumnType::id::type id() const {
1122       return table()->id()[row_number_];
1123     }
type()1124     ColumnType::type::type type() const {
1125       return table()->type()[row_number_];
1126     }
depth()1127     ColumnType::depth::type depth() const {
1128       return table()->depth()[row_number_];
1129     }
parent_id()1130     ColumnType::parent_id::type parent_id() const {
1131       return table()->parent_id()[row_number_];
1132     }
frame_id()1133     ColumnType::frame_id::type frame_id() const {
1134       return table()->frame_id()[row_number_];
1135     }
1136   };
1137   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
1138                 "Inheritance used without trivial destruction");
1139   class RowReference : public ConstRowReference {
1140    public:
RowReference(const StackProfileCallsiteTable * table,uint32_t row_number)1141     RowReference(const StackProfileCallsiteTable* table, uint32_t row_number)
1142         : ConstRowReference(table, row_number) {}
1143 
set_depth(ColumnType::depth::non_optional_type v)1144     void set_depth(
1145         ColumnType::depth::non_optional_type v) {
1146       return mutable_table()->mutable_depth()->Set(row_number_, v);
1147     }
set_parent_id(ColumnType::parent_id::non_optional_type v)1148     void set_parent_id(
1149         ColumnType::parent_id::non_optional_type v) {
1150       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
1151     }
set_frame_id(ColumnType::frame_id::non_optional_type v)1152     void set_frame_id(
1153         ColumnType::frame_id::non_optional_type v) {
1154       return mutable_table()->mutable_frame_id()->Set(row_number_, v);
1155     }
1156 
1157    private:
mutable_table()1158     StackProfileCallsiteTable* mutable_table() const {
1159       return const_cast<StackProfileCallsiteTable*>(table());
1160     }
1161   };
1162   static_assert(std::is_trivially_destructible_v<RowReference>,
1163                 "Inheritance used without trivial destruction");
1164 
1165   class ConstIterator;
1166   class ConstIterator : public macros_internal::AbstractConstIterator<
1167     ConstIterator, StackProfileCallsiteTable, RowNumber, ConstRowReference> {
1168    public:
id()1169     ColumnType::id::type id() const {
1170       const auto& col = table()->id();
1171       return col.GetAtIdx(
1172         iterator_.StorageIndexForColumn(col.index_in_table()));
1173     }
type()1174     ColumnType::type::type type() const {
1175       const auto& col = table()->type();
1176       return col.GetAtIdx(
1177         iterator_.StorageIndexForColumn(col.index_in_table()));
1178     }
depth()1179     ColumnType::depth::type depth() const {
1180       const auto& col = table()->depth();
1181       return col.GetAtIdx(
1182         iterator_.StorageIndexForColumn(col.index_in_table()));
1183     }
parent_id()1184     ColumnType::parent_id::type parent_id() const {
1185       const auto& col = table()->parent_id();
1186       return col.GetAtIdx(
1187         iterator_.StorageIndexForColumn(col.index_in_table()));
1188     }
frame_id()1189     ColumnType::frame_id::type frame_id() const {
1190       const auto& col = table()->frame_id();
1191       return col.GetAtIdx(
1192         iterator_.StorageIndexForColumn(col.index_in_table()));
1193     }
1194 
1195    protected:
ConstIterator(const StackProfileCallsiteTable * table,Table::Iterator iterator)1196     explicit ConstIterator(const StackProfileCallsiteTable* table,
1197                            Table::Iterator iterator)
1198         : AbstractConstIterator(table, std::move(iterator)) {}
1199 
CurrentRowNumber()1200     uint32_t CurrentRowNumber() const {
1201       return iterator_.StorageIndexForLastOverlay();
1202     }
1203 
1204    private:
1205     friend class StackProfileCallsiteTable;
1206     friend class macros_internal::AbstractConstIterator<
1207       ConstIterator, StackProfileCallsiteTable, RowNumber, ConstRowReference>;
1208   };
1209   class Iterator : public ConstIterator {
1210     public:
row_reference()1211      RowReference row_reference() const {
1212        return {const_cast<StackProfileCallsiteTable*>(table()), CurrentRowNumber()};
1213      }
1214 
1215     private:
1216      friend class StackProfileCallsiteTable;
1217 
Iterator(StackProfileCallsiteTable * table,Table::Iterator iterator)1218      explicit Iterator(StackProfileCallsiteTable* table, Table::Iterator iterator)
1219         : ConstIterator(table, std::move(iterator)) {}
1220   };
1221 
1222   struct IdAndRow {
1223     Id id;
1224     uint32_t row;
1225     RowReference row_reference;
1226     RowNumber row_number;
1227   };
1228 
GetColumns(StackProfileCallsiteTable * self,const macros_internal::MacroTable * parent)1229   static std::vector<ColumnLegacy> GetColumns(
1230       StackProfileCallsiteTable* self,
1231       const macros_internal::MacroTable* parent) {
1232     std::vector<ColumnLegacy> columns =
1233         CopyColumnsFromParentOrAddRootColumns(self, parent);
1234     uint32_t olay_idx = OverlayCount(parent);
1235     AddColumnToVector(columns, "depth", &self->depth_, ColumnFlag::depth,
1236                       static_cast<uint32_t>(columns.size()), olay_idx);
1237     AddColumnToVector(columns, "parent_id", &self->parent_id_, ColumnFlag::parent_id,
1238                       static_cast<uint32_t>(columns.size()), olay_idx);
1239     AddColumnToVector(columns, "frame_id", &self->frame_id_, ColumnFlag::frame_id,
1240                       static_cast<uint32_t>(columns.size()), olay_idx);
1241     return columns;
1242   }
1243 
StackProfileCallsiteTable(StringPool * pool)1244   PERFETTO_NO_INLINE explicit StackProfileCallsiteTable(StringPool* pool)
1245       : macros_internal::MacroTable(
1246           pool,
1247           GetColumns(this, nullptr),
1248           nullptr),
1249         depth_(ColumnStorage<ColumnType::depth::stored_type>::Create<false>()),
1250         parent_id_(ColumnStorage<ColumnType::parent_id::stored_type>::Create<false>()),
1251         frame_id_(ColumnStorage<ColumnType::frame_id::stored_type>::Create<false>())
1252 ,
1253         id_storage_layer_(new column::IdStorage()),
1254         type_storage_layer_(
1255           new column::StringStorage(string_pool(), &type_.vector())),
1256         depth_storage_layer_(
1257         new column::NumericStorage<ColumnType::depth::non_optional_stored_type>(
1258           &depth_.vector(),
1259           ColumnTypeHelper<ColumnType::depth::stored_type>::ToColumnType(),
1260           false)),
1261         parent_id_storage_layer_(
1262           new column::NumericStorage<ColumnType::parent_id::non_optional_stored_type>(
1263             &parent_id_.non_null_vector(),
1264             ColumnTypeHelper<ColumnType::parent_id::stored_type>::ToColumnType(),
1265             false)),
1266         frame_id_storage_layer_(
1267         new column::NumericStorage<ColumnType::frame_id::non_optional_stored_type>(
1268           &frame_id_.vector(),
1269           ColumnTypeHelper<ColumnType::frame_id::stored_type>::ToColumnType(),
1270           false))
1271 ,
1272         parent_id_null_layer_(new column::NullOverlay(parent_id_.bv())) {
1273     static_assert(
1274         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::depth::stored_type>(
1275           ColumnFlag::depth),
1276         "Column type and flag combination is not valid");
1277       static_assert(
1278         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::parent_id::stored_type>(
1279           ColumnFlag::parent_id),
1280         "Column type and flag combination is not valid");
1281       static_assert(
1282         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::frame_id::stored_type>(
1283           ColumnFlag::frame_id),
1284         "Column type and flag combination is not valid");
1285     OnConstructionCompletedRegularConstructor(
1286       {id_storage_layer_,type_storage_layer_,depth_storage_layer_,parent_id_storage_layer_,frame_id_storage_layer_},
1287       {{},{},{},parent_id_null_layer_,{}});
1288   }
1289   ~StackProfileCallsiteTable() override;
1290 
Name()1291   static const char* Name() { return "stack_profile_callsite"; }
1292 
ComputeStaticSchema()1293   static Table::Schema ComputeStaticSchema() {
1294     Table::Schema schema;
1295     schema.columns.emplace_back(Table::Schema::Column{
1296         "id", SqlValue::Type::kLong, true, true, false, false});
1297     schema.columns.emplace_back(Table::Schema::Column{
1298         "type", SqlValue::Type::kString, false, false, false, false});
1299     schema.columns.emplace_back(Table::Schema::Column{
1300         "depth", ColumnType::depth::SqlValueType(), false,
1301         false,
1302         false,
1303         false});
1304     schema.columns.emplace_back(Table::Schema::Column{
1305         "parent_id", ColumnType::parent_id::SqlValueType(), false,
1306         false,
1307         false,
1308         false});
1309     schema.columns.emplace_back(Table::Schema::Column{
1310         "frame_id", ColumnType::frame_id::SqlValueType(), false,
1311         false,
1312         false,
1313         false});
1314     return schema;
1315   }
1316 
IterateRows()1317   ConstIterator IterateRows() const {
1318     return ConstIterator(this, Table::IterateRows());
1319   }
1320 
IterateRows()1321   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
1322 
FilterToIterator(const Query & q)1323   ConstIterator FilterToIterator(const Query& q) const {
1324     return ConstIterator(this, QueryToIterator(q));
1325   }
1326 
FilterToIterator(const Query & q)1327   Iterator FilterToIterator(const Query& q) {
1328     return Iterator(this, QueryToIterator(q));
1329   }
1330 
ShrinkToFit()1331   void ShrinkToFit() {
1332     type_.ShrinkToFit();
1333     depth_.ShrinkToFit();
1334     parent_id_.ShrinkToFit();
1335     frame_id_.ShrinkToFit();
1336   }
1337 
1338   ConstRowReference operator[](uint32_t r) const {
1339     return ConstRowReference(this, r);
1340   }
1341   RowReference operator[](uint32_t r) { return RowReference(this, r); }
1342   ConstRowReference operator[](RowNumber r) const {
1343     return ConstRowReference(this, r.row_number());
1344   }
1345   RowReference operator[](RowNumber r) {
1346     return RowReference(this, r.row_number());
1347   }
1348 
FindById(Id find_id)1349   std::optional<ConstRowReference> FindById(Id find_id) const {
1350     std::optional<uint32_t> row = id().IndexOf(find_id);
1351     return row ? std::make_optional(ConstRowReference(this, *row))
1352                : std::nullopt;
1353   }
1354 
FindById(Id find_id)1355   std::optional<RowReference> FindById(Id find_id) {
1356     std::optional<uint32_t> row = id().IndexOf(find_id);
1357     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
1358   }
1359 
Insert(const Row & row)1360   IdAndRow Insert(const Row& row) {
1361     uint32_t row_number = row_count();
1362     Id id = Id{row_number};
1363     type_.Append(string_pool()->InternString(row.type()));
1364     mutable_depth()->Append(row.depth);
1365     mutable_parent_id()->Append(row.parent_id);
1366     mutable_frame_id()->Append(row.frame_id);
1367     UpdateSelfOverlayAfterInsert();
1368     return IdAndRow{id, row_number, RowReference(this, row_number),
1369                      RowNumber(row_number)};
1370   }
1371 
1372 
1373 
id()1374   const IdColumn<StackProfileCallsiteTable::Id>& id() const {
1375     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
1376   }
type()1377   const TypedColumn<StringPool::Id>& type() const {
1378     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
1379   }
depth()1380   const TypedColumn<uint32_t>& depth() const {
1381     return static_cast<const ColumnType::depth&>(columns()[ColumnIndex::depth]);
1382   }
parent_id()1383   const TypedColumn<std::optional<StackProfileCallsiteTable::Id>>& parent_id() const {
1384     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
1385   }
frame_id()1386   const TypedColumn<StackProfileFrameTable::Id>& frame_id() const {
1387     return static_cast<const ColumnType::frame_id&>(columns()[ColumnIndex::frame_id]);
1388   }
1389 
mutable_depth()1390   TypedColumn<uint32_t>* mutable_depth() {
1391     return static_cast<ColumnType::depth*>(
1392         GetColumn(ColumnIndex::depth));
1393   }
mutable_parent_id()1394   TypedColumn<std::optional<StackProfileCallsiteTable::Id>>* mutable_parent_id() {
1395     return static_cast<ColumnType::parent_id*>(
1396         GetColumn(ColumnIndex::parent_id));
1397   }
mutable_frame_id()1398   TypedColumn<StackProfileFrameTable::Id>* mutable_frame_id() {
1399     return static_cast<ColumnType::frame_id*>(
1400         GetColumn(ColumnIndex::frame_id));
1401   }
1402 
1403  private:
1404 
1405 
1406   ColumnStorage<ColumnType::depth::stored_type> depth_;
1407   ColumnStorage<ColumnType::parent_id::stored_type> parent_id_;
1408   ColumnStorage<ColumnType::frame_id::stored_type> frame_id_;
1409 
1410   RefPtr<column::StorageLayer> id_storage_layer_;
1411   RefPtr<column::StorageLayer> type_storage_layer_;
1412   RefPtr<column::StorageLayer> depth_storage_layer_;
1413   RefPtr<column::StorageLayer> parent_id_storage_layer_;
1414   RefPtr<column::StorageLayer> frame_id_storage_layer_;
1415 
1416   RefPtr<column::OverlayLayer> parent_id_null_layer_;
1417 };
1418 
1419 
1420 class CpuProfileStackSampleTable : public macros_internal::MacroTable {
1421  public:
1422   static constexpr uint32_t kColumnCount = 6;
1423 
1424   struct Id : public BaseId {
1425     Id() = default;
IdId1426     explicit constexpr Id(uint32_t v) : BaseId(v) {}
1427   };
1428   static_assert(std::is_trivially_destructible_v<Id>,
1429                 "Inheritance used without trivial destruction");
1430 
1431   struct ColumnIndex {
1432     static constexpr uint32_t id = 0;
1433     static constexpr uint32_t type = 1;
1434     static constexpr uint32_t ts = 2;
1435     static constexpr uint32_t callsite_id = 3;
1436     static constexpr uint32_t utid = 4;
1437     static constexpr uint32_t process_priority = 5;
1438   };
1439   struct ColumnType {
1440     using id = IdColumn<CpuProfileStackSampleTable::Id>;
1441     using type = TypedColumn<StringPool::Id>;
1442     using ts = TypedColumn<int64_t>;
1443     using callsite_id = TypedColumn<StackProfileCallsiteTable::Id>;
1444     using utid = TypedColumn<uint32_t>;
1445     using process_priority = TypedColumn<int32_t>;
1446   };
1447   struct Row : public macros_internal::RootParentTable::Row {
1448     Row(int64_t in_ts = {},
1449         StackProfileCallsiteTable::Id in_callsite_id = {},
1450         uint32_t in_utid = {},
1451         int32_t in_process_priority = {},
1452         std::nullptr_t = nullptr)
RowRow1453         : macros_internal::RootParentTable::Row(),
1454           ts(in_ts),
1455           callsite_id(in_callsite_id),
1456           utid(in_utid),
1457           process_priority(in_process_priority) {
1458       type_ = "cpu_profile_stack_sample";
1459     }
1460     int64_t ts;
1461     StackProfileCallsiteTable::Id callsite_id;
1462     uint32_t utid;
1463     int32_t process_priority;
1464 
1465     bool operator==(const CpuProfileStackSampleTable::Row& other) const {
1466       return type() == other.type() && ColumnType::ts::Equals(ts, other.ts) &&
1467        ColumnType::callsite_id::Equals(callsite_id, other.callsite_id) &&
1468        ColumnType::utid::Equals(utid, other.utid) &&
1469        ColumnType::process_priority::Equals(process_priority, other.process_priority);
1470     }
1471   };
1472   struct ColumnFlag {
1473     static constexpr uint32_t ts = ColumnType::ts::default_flags();
1474     static constexpr uint32_t callsite_id = ColumnType::callsite_id::default_flags();
1475     static constexpr uint32_t utid = ColumnType::utid::default_flags();
1476     static constexpr uint32_t process_priority = ColumnType::process_priority::default_flags();
1477   };
1478 
1479   class RowNumber;
1480   class ConstRowReference;
1481   class RowReference;
1482 
1483   class RowNumber : public macros_internal::AbstractRowNumber<
1484       CpuProfileStackSampleTable, ConstRowReference, RowReference> {
1485    public:
RowNumber(uint32_t row_number)1486     explicit RowNumber(uint32_t row_number)
1487         : AbstractRowNumber(row_number) {}
1488   };
1489   static_assert(std::is_trivially_destructible_v<RowNumber>,
1490                 "Inheritance used without trivial destruction");
1491 
1492   class ConstRowReference : public macros_internal::AbstractConstRowReference<
1493     CpuProfileStackSampleTable, RowNumber> {
1494    public:
ConstRowReference(const CpuProfileStackSampleTable * table,uint32_t row_number)1495     ConstRowReference(const CpuProfileStackSampleTable* table, uint32_t row_number)
1496         : AbstractConstRowReference(table, row_number) {}
1497 
id()1498     ColumnType::id::type id() const {
1499       return table()->id()[row_number_];
1500     }
type()1501     ColumnType::type::type type() const {
1502       return table()->type()[row_number_];
1503     }
ts()1504     ColumnType::ts::type ts() const {
1505       return table()->ts()[row_number_];
1506     }
callsite_id()1507     ColumnType::callsite_id::type callsite_id() const {
1508       return table()->callsite_id()[row_number_];
1509     }
utid()1510     ColumnType::utid::type utid() const {
1511       return table()->utid()[row_number_];
1512     }
process_priority()1513     ColumnType::process_priority::type process_priority() const {
1514       return table()->process_priority()[row_number_];
1515     }
1516   };
1517   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
1518                 "Inheritance used without trivial destruction");
1519   class RowReference : public ConstRowReference {
1520    public:
RowReference(const CpuProfileStackSampleTable * table,uint32_t row_number)1521     RowReference(const CpuProfileStackSampleTable* table, uint32_t row_number)
1522         : ConstRowReference(table, row_number) {}
1523 
set_ts(ColumnType::ts::non_optional_type v)1524     void set_ts(
1525         ColumnType::ts::non_optional_type v) {
1526       return mutable_table()->mutable_ts()->Set(row_number_, v);
1527     }
set_callsite_id(ColumnType::callsite_id::non_optional_type v)1528     void set_callsite_id(
1529         ColumnType::callsite_id::non_optional_type v) {
1530       return mutable_table()->mutable_callsite_id()->Set(row_number_, v);
1531     }
set_utid(ColumnType::utid::non_optional_type v)1532     void set_utid(
1533         ColumnType::utid::non_optional_type v) {
1534       return mutable_table()->mutable_utid()->Set(row_number_, v);
1535     }
set_process_priority(ColumnType::process_priority::non_optional_type v)1536     void set_process_priority(
1537         ColumnType::process_priority::non_optional_type v) {
1538       return mutable_table()->mutable_process_priority()->Set(row_number_, v);
1539     }
1540 
1541    private:
mutable_table()1542     CpuProfileStackSampleTable* mutable_table() const {
1543       return const_cast<CpuProfileStackSampleTable*>(table());
1544     }
1545   };
1546   static_assert(std::is_trivially_destructible_v<RowReference>,
1547                 "Inheritance used without trivial destruction");
1548 
1549   class ConstIterator;
1550   class ConstIterator : public macros_internal::AbstractConstIterator<
1551     ConstIterator, CpuProfileStackSampleTable, RowNumber, ConstRowReference> {
1552    public:
id()1553     ColumnType::id::type id() const {
1554       const auto& col = table()->id();
1555       return col.GetAtIdx(
1556         iterator_.StorageIndexForColumn(col.index_in_table()));
1557     }
type()1558     ColumnType::type::type type() const {
1559       const auto& col = table()->type();
1560       return col.GetAtIdx(
1561         iterator_.StorageIndexForColumn(col.index_in_table()));
1562     }
ts()1563     ColumnType::ts::type ts() const {
1564       const auto& col = table()->ts();
1565       return col.GetAtIdx(
1566         iterator_.StorageIndexForColumn(col.index_in_table()));
1567     }
callsite_id()1568     ColumnType::callsite_id::type callsite_id() const {
1569       const auto& col = table()->callsite_id();
1570       return col.GetAtIdx(
1571         iterator_.StorageIndexForColumn(col.index_in_table()));
1572     }
utid()1573     ColumnType::utid::type utid() const {
1574       const auto& col = table()->utid();
1575       return col.GetAtIdx(
1576         iterator_.StorageIndexForColumn(col.index_in_table()));
1577     }
process_priority()1578     ColumnType::process_priority::type process_priority() const {
1579       const auto& col = table()->process_priority();
1580       return col.GetAtIdx(
1581         iterator_.StorageIndexForColumn(col.index_in_table()));
1582     }
1583 
1584    protected:
ConstIterator(const CpuProfileStackSampleTable * table,Table::Iterator iterator)1585     explicit ConstIterator(const CpuProfileStackSampleTable* table,
1586                            Table::Iterator iterator)
1587         : AbstractConstIterator(table, std::move(iterator)) {}
1588 
CurrentRowNumber()1589     uint32_t CurrentRowNumber() const {
1590       return iterator_.StorageIndexForLastOverlay();
1591     }
1592 
1593    private:
1594     friend class CpuProfileStackSampleTable;
1595     friend class macros_internal::AbstractConstIterator<
1596       ConstIterator, CpuProfileStackSampleTable, RowNumber, ConstRowReference>;
1597   };
1598   class Iterator : public ConstIterator {
1599     public:
row_reference()1600      RowReference row_reference() const {
1601        return {const_cast<CpuProfileStackSampleTable*>(table()), CurrentRowNumber()};
1602      }
1603 
1604     private:
1605      friend class CpuProfileStackSampleTable;
1606 
Iterator(CpuProfileStackSampleTable * table,Table::Iterator iterator)1607      explicit Iterator(CpuProfileStackSampleTable* table, Table::Iterator iterator)
1608         : ConstIterator(table, std::move(iterator)) {}
1609   };
1610 
1611   struct IdAndRow {
1612     Id id;
1613     uint32_t row;
1614     RowReference row_reference;
1615     RowNumber row_number;
1616   };
1617 
GetColumns(CpuProfileStackSampleTable * self,const macros_internal::MacroTable * parent)1618   static std::vector<ColumnLegacy> GetColumns(
1619       CpuProfileStackSampleTable* self,
1620       const macros_internal::MacroTable* parent) {
1621     std::vector<ColumnLegacy> columns =
1622         CopyColumnsFromParentOrAddRootColumns(self, parent);
1623     uint32_t olay_idx = OverlayCount(parent);
1624     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
1625                       static_cast<uint32_t>(columns.size()), olay_idx);
1626     AddColumnToVector(columns, "callsite_id", &self->callsite_id_, ColumnFlag::callsite_id,
1627                       static_cast<uint32_t>(columns.size()), olay_idx);
1628     AddColumnToVector(columns, "utid", &self->utid_, ColumnFlag::utid,
1629                       static_cast<uint32_t>(columns.size()), olay_idx);
1630     AddColumnToVector(columns, "process_priority", &self->process_priority_, ColumnFlag::process_priority,
1631                       static_cast<uint32_t>(columns.size()), olay_idx);
1632     return columns;
1633   }
1634 
CpuProfileStackSampleTable(StringPool * pool)1635   PERFETTO_NO_INLINE explicit CpuProfileStackSampleTable(StringPool* pool)
1636       : macros_internal::MacroTable(
1637           pool,
1638           GetColumns(this, nullptr),
1639           nullptr),
1640         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
1641         callsite_id_(ColumnStorage<ColumnType::callsite_id::stored_type>::Create<false>()),
1642         utid_(ColumnStorage<ColumnType::utid::stored_type>::Create<false>()),
1643         process_priority_(ColumnStorage<ColumnType::process_priority::stored_type>::Create<false>())
1644 ,
1645         id_storage_layer_(new column::IdStorage()),
1646         type_storage_layer_(
1647           new column::StringStorage(string_pool(), &type_.vector())),
1648         ts_storage_layer_(
1649         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
1650           &ts_.vector(),
1651           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
1652           false)),
1653         callsite_id_storage_layer_(
1654         new column::NumericStorage<ColumnType::callsite_id::non_optional_stored_type>(
1655           &callsite_id_.vector(),
1656           ColumnTypeHelper<ColumnType::callsite_id::stored_type>::ToColumnType(),
1657           false)),
1658         utid_storage_layer_(
1659         new column::NumericStorage<ColumnType::utid::non_optional_stored_type>(
1660           &utid_.vector(),
1661           ColumnTypeHelper<ColumnType::utid::stored_type>::ToColumnType(),
1662           false)),
1663         process_priority_storage_layer_(
1664         new column::NumericStorage<ColumnType::process_priority::non_optional_stored_type>(
1665           &process_priority_.vector(),
1666           ColumnTypeHelper<ColumnType::process_priority::stored_type>::ToColumnType(),
1667           false))
1668          {
1669     static_assert(
1670         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
1671           ColumnFlag::ts),
1672         "Column type and flag combination is not valid");
1673       static_assert(
1674         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::callsite_id::stored_type>(
1675           ColumnFlag::callsite_id),
1676         "Column type and flag combination is not valid");
1677       static_assert(
1678         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::utid::stored_type>(
1679           ColumnFlag::utid),
1680         "Column type and flag combination is not valid");
1681       static_assert(
1682         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::process_priority::stored_type>(
1683           ColumnFlag::process_priority),
1684         "Column type and flag combination is not valid");
1685     OnConstructionCompletedRegularConstructor(
1686       {id_storage_layer_,type_storage_layer_,ts_storage_layer_,callsite_id_storage_layer_,utid_storage_layer_,process_priority_storage_layer_},
1687       {{},{},{},{},{},{}});
1688   }
1689   ~CpuProfileStackSampleTable() override;
1690 
Name()1691   static const char* Name() { return "cpu_profile_stack_sample"; }
1692 
ComputeStaticSchema()1693   static Table::Schema ComputeStaticSchema() {
1694     Table::Schema schema;
1695     schema.columns.emplace_back(Table::Schema::Column{
1696         "id", SqlValue::Type::kLong, true, true, false, false});
1697     schema.columns.emplace_back(Table::Schema::Column{
1698         "type", SqlValue::Type::kString, false, false, false, false});
1699     schema.columns.emplace_back(Table::Schema::Column{
1700         "ts", ColumnType::ts::SqlValueType(), false,
1701         false,
1702         false,
1703         false});
1704     schema.columns.emplace_back(Table::Schema::Column{
1705         "callsite_id", ColumnType::callsite_id::SqlValueType(), false,
1706         false,
1707         false,
1708         false});
1709     schema.columns.emplace_back(Table::Schema::Column{
1710         "utid", ColumnType::utid::SqlValueType(), false,
1711         false,
1712         false,
1713         false});
1714     schema.columns.emplace_back(Table::Schema::Column{
1715         "process_priority", ColumnType::process_priority::SqlValueType(), false,
1716         false,
1717         false,
1718         false});
1719     return schema;
1720   }
1721 
IterateRows()1722   ConstIterator IterateRows() const {
1723     return ConstIterator(this, Table::IterateRows());
1724   }
1725 
IterateRows()1726   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
1727 
FilterToIterator(const Query & q)1728   ConstIterator FilterToIterator(const Query& q) const {
1729     return ConstIterator(this, QueryToIterator(q));
1730   }
1731 
FilterToIterator(const Query & q)1732   Iterator FilterToIterator(const Query& q) {
1733     return Iterator(this, QueryToIterator(q));
1734   }
1735 
ShrinkToFit()1736   void ShrinkToFit() {
1737     type_.ShrinkToFit();
1738     ts_.ShrinkToFit();
1739     callsite_id_.ShrinkToFit();
1740     utid_.ShrinkToFit();
1741     process_priority_.ShrinkToFit();
1742   }
1743 
1744   ConstRowReference operator[](uint32_t r) const {
1745     return ConstRowReference(this, r);
1746   }
1747   RowReference operator[](uint32_t r) { return RowReference(this, r); }
1748   ConstRowReference operator[](RowNumber r) const {
1749     return ConstRowReference(this, r.row_number());
1750   }
1751   RowReference operator[](RowNumber r) {
1752     return RowReference(this, r.row_number());
1753   }
1754 
FindById(Id find_id)1755   std::optional<ConstRowReference> FindById(Id find_id) const {
1756     std::optional<uint32_t> row = id().IndexOf(find_id);
1757     return row ? std::make_optional(ConstRowReference(this, *row))
1758                : std::nullopt;
1759   }
1760 
FindById(Id find_id)1761   std::optional<RowReference> FindById(Id find_id) {
1762     std::optional<uint32_t> row = id().IndexOf(find_id);
1763     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
1764   }
1765 
Insert(const Row & row)1766   IdAndRow Insert(const Row& row) {
1767     uint32_t row_number = row_count();
1768     Id id = Id{row_number};
1769     type_.Append(string_pool()->InternString(row.type()));
1770     mutable_ts()->Append(row.ts);
1771     mutable_callsite_id()->Append(row.callsite_id);
1772     mutable_utid()->Append(row.utid);
1773     mutable_process_priority()->Append(row.process_priority);
1774     UpdateSelfOverlayAfterInsert();
1775     return IdAndRow{id, row_number, RowReference(this, row_number),
1776                      RowNumber(row_number)};
1777   }
1778 
1779 
1780 
id()1781   const IdColumn<CpuProfileStackSampleTable::Id>& id() const {
1782     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
1783   }
type()1784   const TypedColumn<StringPool::Id>& type() const {
1785     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
1786   }
ts()1787   const TypedColumn<int64_t>& ts() const {
1788     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
1789   }
callsite_id()1790   const TypedColumn<StackProfileCallsiteTable::Id>& callsite_id() const {
1791     return static_cast<const ColumnType::callsite_id&>(columns()[ColumnIndex::callsite_id]);
1792   }
utid()1793   const TypedColumn<uint32_t>& utid() const {
1794     return static_cast<const ColumnType::utid&>(columns()[ColumnIndex::utid]);
1795   }
process_priority()1796   const TypedColumn<int32_t>& process_priority() const {
1797     return static_cast<const ColumnType::process_priority&>(columns()[ColumnIndex::process_priority]);
1798   }
1799 
mutable_ts()1800   TypedColumn<int64_t>* mutable_ts() {
1801     return static_cast<ColumnType::ts*>(
1802         GetColumn(ColumnIndex::ts));
1803   }
mutable_callsite_id()1804   TypedColumn<StackProfileCallsiteTable::Id>* mutable_callsite_id() {
1805     return static_cast<ColumnType::callsite_id*>(
1806         GetColumn(ColumnIndex::callsite_id));
1807   }
mutable_utid()1808   TypedColumn<uint32_t>* mutable_utid() {
1809     return static_cast<ColumnType::utid*>(
1810         GetColumn(ColumnIndex::utid));
1811   }
mutable_process_priority()1812   TypedColumn<int32_t>* mutable_process_priority() {
1813     return static_cast<ColumnType::process_priority*>(
1814         GetColumn(ColumnIndex::process_priority));
1815   }
1816 
1817  private:
1818 
1819 
1820   ColumnStorage<ColumnType::ts::stored_type> ts_;
1821   ColumnStorage<ColumnType::callsite_id::stored_type> callsite_id_;
1822   ColumnStorage<ColumnType::utid::stored_type> utid_;
1823   ColumnStorage<ColumnType::process_priority::stored_type> process_priority_;
1824 
1825   RefPtr<column::StorageLayer> id_storage_layer_;
1826   RefPtr<column::StorageLayer> type_storage_layer_;
1827   RefPtr<column::StorageLayer> ts_storage_layer_;
1828   RefPtr<column::StorageLayer> callsite_id_storage_layer_;
1829   RefPtr<column::StorageLayer> utid_storage_layer_;
1830   RefPtr<column::StorageLayer> process_priority_storage_layer_;
1831 
1832 
1833 };
1834 
1835 
1836 class ExperimentalFlamegraphTable : public macros_internal::MacroTable {
1837  public:
1838   static constexpr uint32_t kColumnCount = 23;
1839 
1840   struct Id : public BaseId {
1841     Id() = default;
IdId1842     explicit constexpr Id(uint32_t v) : BaseId(v) {}
1843   };
1844   static_assert(std::is_trivially_destructible_v<Id>,
1845                 "Inheritance used without trivial destruction");
1846 
1847   struct ColumnIndex {
1848     static constexpr uint32_t id = 0;
1849     static constexpr uint32_t type = 1;
1850     static constexpr uint32_t profile_type = 2;
1851     static constexpr uint32_t ts_in = 3;
1852     static constexpr uint32_t ts_constraint = 4;
1853     static constexpr uint32_t upid = 5;
1854     static constexpr uint32_t upid_group = 6;
1855     static constexpr uint32_t focus_str = 7;
1856     static constexpr uint32_t ts = 8;
1857     static constexpr uint32_t depth = 9;
1858     static constexpr uint32_t name = 10;
1859     static constexpr uint32_t map_name = 11;
1860     static constexpr uint32_t count = 12;
1861     static constexpr uint32_t cumulative_count = 13;
1862     static constexpr uint32_t size = 14;
1863     static constexpr uint32_t cumulative_size = 15;
1864     static constexpr uint32_t alloc_count = 16;
1865     static constexpr uint32_t cumulative_alloc_count = 17;
1866     static constexpr uint32_t alloc_size = 18;
1867     static constexpr uint32_t cumulative_alloc_size = 19;
1868     static constexpr uint32_t parent_id = 20;
1869     static constexpr uint32_t source_file = 21;
1870     static constexpr uint32_t line_number = 22;
1871   };
1872   struct ColumnType {
1873     using id = IdColumn<ExperimentalFlamegraphTable::Id>;
1874     using type = TypedColumn<StringPool::Id>;
1875     using profile_type = TypedColumn<StringPool::Id>;
1876     using ts_in = TypedColumn<std::optional<int64_t>>;
1877     using ts_constraint = TypedColumn<std::optional<StringPool::Id>>;
1878     using upid = TypedColumn<std::optional<uint32_t>>;
1879     using upid_group = TypedColumn<std::optional<StringPool::Id>>;
1880     using focus_str = TypedColumn<std::optional<StringPool::Id>>;
1881     using ts = TypedColumn<int64_t>;
1882     using depth = TypedColumn<uint32_t>;
1883     using name = TypedColumn<StringPool::Id>;
1884     using map_name = TypedColumn<StringPool::Id>;
1885     using count = TypedColumn<int64_t>;
1886     using cumulative_count = TypedColumn<int64_t>;
1887     using size = TypedColumn<int64_t>;
1888     using cumulative_size = TypedColumn<int64_t>;
1889     using alloc_count = TypedColumn<int64_t>;
1890     using cumulative_alloc_count = TypedColumn<int64_t>;
1891     using alloc_size = TypedColumn<int64_t>;
1892     using cumulative_alloc_size = TypedColumn<int64_t>;
1893     using parent_id = TypedColumn<std::optional<ExperimentalFlamegraphTable::Id>>;
1894     using source_file = TypedColumn<std::optional<StringPool::Id>>;
1895     using line_number = TypedColumn<std::optional<uint32_t>>;
1896   };
1897   struct Row : public macros_internal::RootParentTable::Row {
1898     Row(StringPool::Id in_profile_type = {},
1899         std::optional<int64_t> in_ts_in = {},
1900         std::optional<StringPool::Id> in_ts_constraint = {},
1901         std::optional<uint32_t> in_upid = {},
1902         std::optional<StringPool::Id> in_upid_group = {},
1903         std::optional<StringPool::Id> in_focus_str = {},
1904         int64_t in_ts = {},
1905         uint32_t in_depth = {},
1906         StringPool::Id in_name = {},
1907         StringPool::Id in_map_name = {},
1908         int64_t in_count = {},
1909         int64_t in_cumulative_count = {},
1910         int64_t in_size = {},
1911         int64_t in_cumulative_size = {},
1912         int64_t in_alloc_count = {},
1913         int64_t in_cumulative_alloc_count = {},
1914         int64_t in_alloc_size = {},
1915         int64_t in_cumulative_alloc_size = {},
1916         std::optional<ExperimentalFlamegraphTable::Id> in_parent_id = {},
1917         std::optional<StringPool::Id> in_source_file = {},
1918         std::optional<uint32_t> in_line_number = {},
1919         std::nullptr_t = nullptr)
RowRow1920         : macros_internal::RootParentTable::Row(),
1921           profile_type(in_profile_type),
1922           ts_in(in_ts_in),
1923           ts_constraint(in_ts_constraint),
1924           upid(in_upid),
1925           upid_group(in_upid_group),
1926           focus_str(in_focus_str),
1927           ts(in_ts),
1928           depth(in_depth),
1929           name(in_name),
1930           map_name(in_map_name),
1931           count(in_count),
1932           cumulative_count(in_cumulative_count),
1933           size(in_size),
1934           cumulative_size(in_cumulative_size),
1935           alloc_count(in_alloc_count),
1936           cumulative_alloc_count(in_cumulative_alloc_count),
1937           alloc_size(in_alloc_size),
1938           cumulative_alloc_size(in_cumulative_alloc_size),
1939           parent_id(in_parent_id),
1940           source_file(in_source_file),
1941           line_number(in_line_number) {
1942       type_ = "experimental_flamegraph";
1943     }
1944     StringPool::Id profile_type;
1945     std::optional<int64_t> ts_in;
1946     std::optional<StringPool::Id> ts_constraint;
1947     std::optional<uint32_t> upid;
1948     std::optional<StringPool::Id> upid_group;
1949     std::optional<StringPool::Id> focus_str;
1950     int64_t ts;
1951     uint32_t depth;
1952     StringPool::Id name;
1953     StringPool::Id map_name;
1954     int64_t count;
1955     int64_t cumulative_count;
1956     int64_t size;
1957     int64_t cumulative_size;
1958     int64_t alloc_count;
1959     int64_t cumulative_alloc_count;
1960     int64_t alloc_size;
1961     int64_t cumulative_alloc_size;
1962     std::optional<ExperimentalFlamegraphTable::Id> parent_id;
1963     std::optional<StringPool::Id> source_file;
1964     std::optional<uint32_t> line_number;
1965 
1966     bool operator==(const ExperimentalFlamegraphTable::Row& other) const {
1967       return type() == other.type() && ColumnType::profile_type::Equals(profile_type, other.profile_type) &&
1968        ColumnType::ts_in::Equals(ts_in, other.ts_in) &&
1969        ColumnType::ts_constraint::Equals(ts_constraint, other.ts_constraint) &&
1970        ColumnType::upid::Equals(upid, other.upid) &&
1971        ColumnType::upid_group::Equals(upid_group, other.upid_group) &&
1972        ColumnType::focus_str::Equals(focus_str, other.focus_str) &&
1973        ColumnType::ts::Equals(ts, other.ts) &&
1974        ColumnType::depth::Equals(depth, other.depth) &&
1975        ColumnType::name::Equals(name, other.name) &&
1976        ColumnType::map_name::Equals(map_name, other.map_name) &&
1977        ColumnType::count::Equals(count, other.count) &&
1978        ColumnType::cumulative_count::Equals(cumulative_count, other.cumulative_count) &&
1979        ColumnType::size::Equals(size, other.size) &&
1980        ColumnType::cumulative_size::Equals(cumulative_size, other.cumulative_size) &&
1981        ColumnType::alloc_count::Equals(alloc_count, other.alloc_count) &&
1982        ColumnType::cumulative_alloc_count::Equals(cumulative_alloc_count, other.cumulative_alloc_count) &&
1983        ColumnType::alloc_size::Equals(alloc_size, other.alloc_size) &&
1984        ColumnType::cumulative_alloc_size::Equals(cumulative_alloc_size, other.cumulative_alloc_size) &&
1985        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
1986        ColumnType::source_file::Equals(source_file, other.source_file) &&
1987        ColumnType::line_number::Equals(line_number, other.line_number);
1988     }
1989   };
1990   struct ColumnFlag {
1991     static constexpr uint32_t profile_type = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::profile_type::default_flags();
1992     static constexpr uint32_t ts_in = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted | ColumnLegacy::Flag::kHidden) | ColumnType::ts_in::default_flags();
1993     static constexpr uint32_t ts_constraint = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::ts_constraint::default_flags();
1994     static constexpr uint32_t upid = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::upid::default_flags();
1995     static constexpr uint32_t upid_group = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::upid_group::default_flags();
1996     static constexpr uint32_t focus_str = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::focus_str::default_flags();
1997     static constexpr uint32_t ts = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted) | ColumnType::ts::default_flags();
1998     static constexpr uint32_t depth = ColumnType::depth::default_flags();
1999     static constexpr uint32_t name = ColumnType::name::default_flags();
2000     static constexpr uint32_t map_name = ColumnType::map_name::default_flags();
2001     static constexpr uint32_t count = ColumnType::count::default_flags();
2002     static constexpr uint32_t cumulative_count = ColumnType::cumulative_count::default_flags();
2003     static constexpr uint32_t size = ColumnType::size::default_flags();
2004     static constexpr uint32_t cumulative_size = ColumnType::cumulative_size::default_flags();
2005     static constexpr uint32_t alloc_count = ColumnType::alloc_count::default_flags();
2006     static constexpr uint32_t cumulative_alloc_count = ColumnType::cumulative_alloc_count::default_flags();
2007     static constexpr uint32_t alloc_size = ColumnType::alloc_size::default_flags();
2008     static constexpr uint32_t cumulative_alloc_size = ColumnType::cumulative_alloc_size::default_flags();
2009     static constexpr uint32_t parent_id = ColumnType::parent_id::default_flags();
2010     static constexpr uint32_t source_file = ColumnType::source_file::default_flags();
2011     static constexpr uint32_t line_number = ColumnType::line_number::default_flags();
2012   };
2013 
2014   class RowNumber;
2015   class ConstRowReference;
2016   class RowReference;
2017 
2018   class RowNumber : public macros_internal::AbstractRowNumber<
2019       ExperimentalFlamegraphTable, ConstRowReference, RowReference> {
2020    public:
RowNumber(uint32_t row_number)2021     explicit RowNumber(uint32_t row_number)
2022         : AbstractRowNumber(row_number) {}
2023   };
2024   static_assert(std::is_trivially_destructible_v<RowNumber>,
2025                 "Inheritance used without trivial destruction");
2026 
2027   class ConstRowReference : public macros_internal::AbstractConstRowReference<
2028     ExperimentalFlamegraphTable, RowNumber> {
2029    public:
ConstRowReference(const ExperimentalFlamegraphTable * table,uint32_t row_number)2030     ConstRowReference(const ExperimentalFlamegraphTable* table, uint32_t row_number)
2031         : AbstractConstRowReference(table, row_number) {}
2032 
id()2033     ColumnType::id::type id() const {
2034       return table()->id()[row_number_];
2035     }
type()2036     ColumnType::type::type type() const {
2037       return table()->type()[row_number_];
2038     }
profile_type()2039     ColumnType::profile_type::type profile_type() const {
2040       return table()->profile_type()[row_number_];
2041     }
ts_in()2042     ColumnType::ts_in::type ts_in() const {
2043       return table()->ts_in()[row_number_];
2044     }
ts_constraint()2045     ColumnType::ts_constraint::type ts_constraint() const {
2046       return table()->ts_constraint()[row_number_];
2047     }
upid()2048     ColumnType::upid::type upid() const {
2049       return table()->upid()[row_number_];
2050     }
upid_group()2051     ColumnType::upid_group::type upid_group() const {
2052       return table()->upid_group()[row_number_];
2053     }
focus_str()2054     ColumnType::focus_str::type focus_str() const {
2055       return table()->focus_str()[row_number_];
2056     }
ts()2057     ColumnType::ts::type ts() const {
2058       return table()->ts()[row_number_];
2059     }
depth()2060     ColumnType::depth::type depth() const {
2061       return table()->depth()[row_number_];
2062     }
name()2063     ColumnType::name::type name() const {
2064       return table()->name()[row_number_];
2065     }
map_name()2066     ColumnType::map_name::type map_name() const {
2067       return table()->map_name()[row_number_];
2068     }
count()2069     ColumnType::count::type count() const {
2070       return table()->count()[row_number_];
2071     }
cumulative_count()2072     ColumnType::cumulative_count::type cumulative_count() const {
2073       return table()->cumulative_count()[row_number_];
2074     }
size()2075     ColumnType::size::type size() const {
2076       return table()->size()[row_number_];
2077     }
cumulative_size()2078     ColumnType::cumulative_size::type cumulative_size() const {
2079       return table()->cumulative_size()[row_number_];
2080     }
alloc_count()2081     ColumnType::alloc_count::type alloc_count() const {
2082       return table()->alloc_count()[row_number_];
2083     }
cumulative_alloc_count()2084     ColumnType::cumulative_alloc_count::type cumulative_alloc_count() const {
2085       return table()->cumulative_alloc_count()[row_number_];
2086     }
alloc_size()2087     ColumnType::alloc_size::type alloc_size() const {
2088       return table()->alloc_size()[row_number_];
2089     }
cumulative_alloc_size()2090     ColumnType::cumulative_alloc_size::type cumulative_alloc_size() const {
2091       return table()->cumulative_alloc_size()[row_number_];
2092     }
parent_id()2093     ColumnType::parent_id::type parent_id() const {
2094       return table()->parent_id()[row_number_];
2095     }
source_file()2096     ColumnType::source_file::type source_file() const {
2097       return table()->source_file()[row_number_];
2098     }
line_number()2099     ColumnType::line_number::type line_number() const {
2100       return table()->line_number()[row_number_];
2101     }
2102   };
2103   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
2104                 "Inheritance used without trivial destruction");
2105   class RowReference : public ConstRowReference {
2106    public:
RowReference(const ExperimentalFlamegraphTable * table,uint32_t row_number)2107     RowReference(const ExperimentalFlamegraphTable* table, uint32_t row_number)
2108         : ConstRowReference(table, row_number) {}
2109 
set_profile_type(ColumnType::profile_type::non_optional_type v)2110     void set_profile_type(
2111         ColumnType::profile_type::non_optional_type v) {
2112       return mutable_table()->mutable_profile_type()->Set(row_number_, v);
2113     }
set_ts_in(ColumnType::ts_in::non_optional_type v)2114     void set_ts_in(
2115         ColumnType::ts_in::non_optional_type v) {
2116       return mutable_table()->mutable_ts_in()->Set(row_number_, v);
2117     }
set_ts_constraint(ColumnType::ts_constraint::non_optional_type v)2118     void set_ts_constraint(
2119         ColumnType::ts_constraint::non_optional_type v) {
2120       return mutable_table()->mutable_ts_constraint()->Set(row_number_, v);
2121     }
set_upid(ColumnType::upid::non_optional_type v)2122     void set_upid(
2123         ColumnType::upid::non_optional_type v) {
2124       return mutable_table()->mutable_upid()->Set(row_number_, v);
2125     }
set_upid_group(ColumnType::upid_group::non_optional_type v)2126     void set_upid_group(
2127         ColumnType::upid_group::non_optional_type v) {
2128       return mutable_table()->mutable_upid_group()->Set(row_number_, v);
2129     }
set_focus_str(ColumnType::focus_str::non_optional_type v)2130     void set_focus_str(
2131         ColumnType::focus_str::non_optional_type v) {
2132       return mutable_table()->mutable_focus_str()->Set(row_number_, v);
2133     }
set_ts(ColumnType::ts::non_optional_type v)2134     void set_ts(
2135         ColumnType::ts::non_optional_type v) {
2136       return mutable_table()->mutable_ts()->Set(row_number_, v);
2137     }
set_depth(ColumnType::depth::non_optional_type v)2138     void set_depth(
2139         ColumnType::depth::non_optional_type v) {
2140       return mutable_table()->mutable_depth()->Set(row_number_, v);
2141     }
set_name(ColumnType::name::non_optional_type v)2142     void set_name(
2143         ColumnType::name::non_optional_type v) {
2144       return mutable_table()->mutable_name()->Set(row_number_, v);
2145     }
set_map_name(ColumnType::map_name::non_optional_type v)2146     void set_map_name(
2147         ColumnType::map_name::non_optional_type v) {
2148       return mutable_table()->mutable_map_name()->Set(row_number_, v);
2149     }
set_count(ColumnType::count::non_optional_type v)2150     void set_count(
2151         ColumnType::count::non_optional_type v) {
2152       return mutable_table()->mutable_count()->Set(row_number_, v);
2153     }
set_cumulative_count(ColumnType::cumulative_count::non_optional_type v)2154     void set_cumulative_count(
2155         ColumnType::cumulative_count::non_optional_type v) {
2156       return mutable_table()->mutable_cumulative_count()->Set(row_number_, v);
2157     }
set_size(ColumnType::size::non_optional_type v)2158     void set_size(
2159         ColumnType::size::non_optional_type v) {
2160       return mutable_table()->mutable_size()->Set(row_number_, v);
2161     }
set_cumulative_size(ColumnType::cumulative_size::non_optional_type v)2162     void set_cumulative_size(
2163         ColumnType::cumulative_size::non_optional_type v) {
2164       return mutable_table()->mutable_cumulative_size()->Set(row_number_, v);
2165     }
set_alloc_count(ColumnType::alloc_count::non_optional_type v)2166     void set_alloc_count(
2167         ColumnType::alloc_count::non_optional_type v) {
2168       return mutable_table()->mutable_alloc_count()->Set(row_number_, v);
2169     }
set_cumulative_alloc_count(ColumnType::cumulative_alloc_count::non_optional_type v)2170     void set_cumulative_alloc_count(
2171         ColumnType::cumulative_alloc_count::non_optional_type v) {
2172       return mutable_table()->mutable_cumulative_alloc_count()->Set(row_number_, v);
2173     }
set_alloc_size(ColumnType::alloc_size::non_optional_type v)2174     void set_alloc_size(
2175         ColumnType::alloc_size::non_optional_type v) {
2176       return mutable_table()->mutable_alloc_size()->Set(row_number_, v);
2177     }
set_cumulative_alloc_size(ColumnType::cumulative_alloc_size::non_optional_type v)2178     void set_cumulative_alloc_size(
2179         ColumnType::cumulative_alloc_size::non_optional_type v) {
2180       return mutable_table()->mutable_cumulative_alloc_size()->Set(row_number_, v);
2181     }
set_parent_id(ColumnType::parent_id::non_optional_type v)2182     void set_parent_id(
2183         ColumnType::parent_id::non_optional_type v) {
2184       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
2185     }
set_source_file(ColumnType::source_file::non_optional_type v)2186     void set_source_file(
2187         ColumnType::source_file::non_optional_type v) {
2188       return mutable_table()->mutable_source_file()->Set(row_number_, v);
2189     }
set_line_number(ColumnType::line_number::non_optional_type v)2190     void set_line_number(
2191         ColumnType::line_number::non_optional_type v) {
2192       return mutable_table()->mutable_line_number()->Set(row_number_, v);
2193     }
2194 
2195    private:
mutable_table()2196     ExperimentalFlamegraphTable* mutable_table() const {
2197       return const_cast<ExperimentalFlamegraphTable*>(table());
2198     }
2199   };
2200   static_assert(std::is_trivially_destructible_v<RowReference>,
2201                 "Inheritance used without trivial destruction");
2202 
2203   class ConstIterator;
2204   class ConstIterator : public macros_internal::AbstractConstIterator<
2205     ConstIterator, ExperimentalFlamegraphTable, RowNumber, ConstRowReference> {
2206    public:
id()2207     ColumnType::id::type id() const {
2208       const auto& col = table()->id();
2209       return col.GetAtIdx(
2210         iterator_.StorageIndexForColumn(col.index_in_table()));
2211     }
type()2212     ColumnType::type::type type() const {
2213       const auto& col = table()->type();
2214       return col.GetAtIdx(
2215         iterator_.StorageIndexForColumn(col.index_in_table()));
2216     }
profile_type()2217     ColumnType::profile_type::type profile_type() const {
2218       const auto& col = table()->profile_type();
2219       return col.GetAtIdx(
2220         iterator_.StorageIndexForColumn(col.index_in_table()));
2221     }
ts_in()2222     ColumnType::ts_in::type ts_in() const {
2223       const auto& col = table()->ts_in();
2224       return col.GetAtIdx(
2225         iterator_.StorageIndexForColumn(col.index_in_table()));
2226     }
ts_constraint()2227     ColumnType::ts_constraint::type ts_constraint() const {
2228       const auto& col = table()->ts_constraint();
2229       return col.GetAtIdx(
2230         iterator_.StorageIndexForColumn(col.index_in_table()));
2231     }
upid()2232     ColumnType::upid::type upid() const {
2233       const auto& col = table()->upid();
2234       return col.GetAtIdx(
2235         iterator_.StorageIndexForColumn(col.index_in_table()));
2236     }
upid_group()2237     ColumnType::upid_group::type upid_group() const {
2238       const auto& col = table()->upid_group();
2239       return col.GetAtIdx(
2240         iterator_.StorageIndexForColumn(col.index_in_table()));
2241     }
focus_str()2242     ColumnType::focus_str::type focus_str() const {
2243       const auto& col = table()->focus_str();
2244       return col.GetAtIdx(
2245         iterator_.StorageIndexForColumn(col.index_in_table()));
2246     }
ts()2247     ColumnType::ts::type ts() const {
2248       const auto& col = table()->ts();
2249       return col.GetAtIdx(
2250         iterator_.StorageIndexForColumn(col.index_in_table()));
2251     }
depth()2252     ColumnType::depth::type depth() const {
2253       const auto& col = table()->depth();
2254       return col.GetAtIdx(
2255         iterator_.StorageIndexForColumn(col.index_in_table()));
2256     }
name()2257     ColumnType::name::type name() const {
2258       const auto& col = table()->name();
2259       return col.GetAtIdx(
2260         iterator_.StorageIndexForColumn(col.index_in_table()));
2261     }
map_name()2262     ColumnType::map_name::type map_name() const {
2263       const auto& col = table()->map_name();
2264       return col.GetAtIdx(
2265         iterator_.StorageIndexForColumn(col.index_in_table()));
2266     }
count()2267     ColumnType::count::type count() const {
2268       const auto& col = table()->count();
2269       return col.GetAtIdx(
2270         iterator_.StorageIndexForColumn(col.index_in_table()));
2271     }
cumulative_count()2272     ColumnType::cumulative_count::type cumulative_count() const {
2273       const auto& col = table()->cumulative_count();
2274       return col.GetAtIdx(
2275         iterator_.StorageIndexForColumn(col.index_in_table()));
2276     }
size()2277     ColumnType::size::type size() const {
2278       const auto& col = table()->size();
2279       return col.GetAtIdx(
2280         iterator_.StorageIndexForColumn(col.index_in_table()));
2281     }
cumulative_size()2282     ColumnType::cumulative_size::type cumulative_size() const {
2283       const auto& col = table()->cumulative_size();
2284       return col.GetAtIdx(
2285         iterator_.StorageIndexForColumn(col.index_in_table()));
2286     }
alloc_count()2287     ColumnType::alloc_count::type alloc_count() const {
2288       const auto& col = table()->alloc_count();
2289       return col.GetAtIdx(
2290         iterator_.StorageIndexForColumn(col.index_in_table()));
2291     }
cumulative_alloc_count()2292     ColumnType::cumulative_alloc_count::type cumulative_alloc_count() const {
2293       const auto& col = table()->cumulative_alloc_count();
2294       return col.GetAtIdx(
2295         iterator_.StorageIndexForColumn(col.index_in_table()));
2296     }
alloc_size()2297     ColumnType::alloc_size::type alloc_size() const {
2298       const auto& col = table()->alloc_size();
2299       return col.GetAtIdx(
2300         iterator_.StorageIndexForColumn(col.index_in_table()));
2301     }
cumulative_alloc_size()2302     ColumnType::cumulative_alloc_size::type cumulative_alloc_size() const {
2303       const auto& col = table()->cumulative_alloc_size();
2304       return col.GetAtIdx(
2305         iterator_.StorageIndexForColumn(col.index_in_table()));
2306     }
parent_id()2307     ColumnType::parent_id::type parent_id() const {
2308       const auto& col = table()->parent_id();
2309       return col.GetAtIdx(
2310         iterator_.StorageIndexForColumn(col.index_in_table()));
2311     }
source_file()2312     ColumnType::source_file::type source_file() const {
2313       const auto& col = table()->source_file();
2314       return col.GetAtIdx(
2315         iterator_.StorageIndexForColumn(col.index_in_table()));
2316     }
line_number()2317     ColumnType::line_number::type line_number() const {
2318       const auto& col = table()->line_number();
2319       return col.GetAtIdx(
2320         iterator_.StorageIndexForColumn(col.index_in_table()));
2321     }
2322 
2323    protected:
ConstIterator(const ExperimentalFlamegraphTable * table,Table::Iterator iterator)2324     explicit ConstIterator(const ExperimentalFlamegraphTable* table,
2325                            Table::Iterator iterator)
2326         : AbstractConstIterator(table, std::move(iterator)) {}
2327 
CurrentRowNumber()2328     uint32_t CurrentRowNumber() const {
2329       return iterator_.StorageIndexForLastOverlay();
2330     }
2331 
2332    private:
2333     friend class ExperimentalFlamegraphTable;
2334     friend class macros_internal::AbstractConstIterator<
2335       ConstIterator, ExperimentalFlamegraphTable, RowNumber, ConstRowReference>;
2336   };
2337   class Iterator : public ConstIterator {
2338     public:
row_reference()2339      RowReference row_reference() const {
2340        return {const_cast<ExperimentalFlamegraphTable*>(table()), CurrentRowNumber()};
2341      }
2342 
2343     private:
2344      friend class ExperimentalFlamegraphTable;
2345 
Iterator(ExperimentalFlamegraphTable * table,Table::Iterator iterator)2346      explicit Iterator(ExperimentalFlamegraphTable* table, Table::Iterator iterator)
2347         : ConstIterator(table, std::move(iterator)) {}
2348   };
2349 
2350   struct IdAndRow {
2351     Id id;
2352     uint32_t row;
2353     RowReference row_reference;
2354     RowNumber row_number;
2355   };
2356 
GetColumns(ExperimentalFlamegraphTable * self,const macros_internal::MacroTable * parent)2357   static std::vector<ColumnLegacy> GetColumns(
2358       ExperimentalFlamegraphTable* self,
2359       const macros_internal::MacroTable* parent) {
2360     std::vector<ColumnLegacy> columns =
2361         CopyColumnsFromParentOrAddRootColumns(self, parent);
2362     uint32_t olay_idx = OverlayCount(parent);
2363     AddColumnToVector(columns, "profile_type", &self->profile_type_, ColumnFlag::profile_type,
2364                       static_cast<uint32_t>(columns.size()), olay_idx);
2365     AddColumnToVector(columns, "ts_in", &self->ts_in_, ColumnFlag::ts_in,
2366                       static_cast<uint32_t>(columns.size()), olay_idx);
2367     AddColumnToVector(columns, "ts_constraint", &self->ts_constraint_, ColumnFlag::ts_constraint,
2368                       static_cast<uint32_t>(columns.size()), olay_idx);
2369     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
2370                       static_cast<uint32_t>(columns.size()), olay_idx);
2371     AddColumnToVector(columns, "upid_group", &self->upid_group_, ColumnFlag::upid_group,
2372                       static_cast<uint32_t>(columns.size()), olay_idx);
2373     AddColumnToVector(columns, "focus_str", &self->focus_str_, ColumnFlag::focus_str,
2374                       static_cast<uint32_t>(columns.size()), olay_idx);
2375     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
2376                       static_cast<uint32_t>(columns.size()), olay_idx);
2377     AddColumnToVector(columns, "depth", &self->depth_, ColumnFlag::depth,
2378                       static_cast<uint32_t>(columns.size()), olay_idx);
2379     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
2380                       static_cast<uint32_t>(columns.size()), olay_idx);
2381     AddColumnToVector(columns, "map_name", &self->map_name_, ColumnFlag::map_name,
2382                       static_cast<uint32_t>(columns.size()), olay_idx);
2383     AddColumnToVector(columns, "count", &self->count_, ColumnFlag::count,
2384                       static_cast<uint32_t>(columns.size()), olay_idx);
2385     AddColumnToVector(columns, "cumulative_count", &self->cumulative_count_, ColumnFlag::cumulative_count,
2386                       static_cast<uint32_t>(columns.size()), olay_idx);
2387     AddColumnToVector(columns, "size", &self->size_, ColumnFlag::size,
2388                       static_cast<uint32_t>(columns.size()), olay_idx);
2389     AddColumnToVector(columns, "cumulative_size", &self->cumulative_size_, ColumnFlag::cumulative_size,
2390                       static_cast<uint32_t>(columns.size()), olay_idx);
2391     AddColumnToVector(columns, "alloc_count", &self->alloc_count_, ColumnFlag::alloc_count,
2392                       static_cast<uint32_t>(columns.size()), olay_idx);
2393     AddColumnToVector(columns, "cumulative_alloc_count", &self->cumulative_alloc_count_, ColumnFlag::cumulative_alloc_count,
2394                       static_cast<uint32_t>(columns.size()), olay_idx);
2395     AddColumnToVector(columns, "alloc_size", &self->alloc_size_, ColumnFlag::alloc_size,
2396                       static_cast<uint32_t>(columns.size()), olay_idx);
2397     AddColumnToVector(columns, "cumulative_alloc_size", &self->cumulative_alloc_size_, ColumnFlag::cumulative_alloc_size,
2398                       static_cast<uint32_t>(columns.size()), olay_idx);
2399     AddColumnToVector(columns, "parent_id", &self->parent_id_, ColumnFlag::parent_id,
2400                       static_cast<uint32_t>(columns.size()), olay_idx);
2401     AddColumnToVector(columns, "source_file", &self->source_file_, ColumnFlag::source_file,
2402                       static_cast<uint32_t>(columns.size()), olay_idx);
2403     AddColumnToVector(columns, "line_number", &self->line_number_, ColumnFlag::line_number,
2404                       static_cast<uint32_t>(columns.size()), olay_idx);
2405     return columns;
2406   }
2407 
ExperimentalFlamegraphTable(StringPool * pool)2408   PERFETTO_NO_INLINE explicit ExperimentalFlamegraphTable(StringPool* pool)
2409       : macros_internal::MacroTable(
2410           pool,
2411           GetColumns(this, nullptr),
2412           nullptr),
2413         profile_type_(ColumnStorage<ColumnType::profile_type::stored_type>::Create<false>()),
2414         ts_in_(ColumnStorage<ColumnType::ts_in::stored_type>::Create<false>()),
2415         ts_constraint_(ColumnStorage<ColumnType::ts_constraint::stored_type>::Create<false>()),
2416         upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>()),
2417         upid_group_(ColumnStorage<ColumnType::upid_group::stored_type>::Create<false>()),
2418         focus_str_(ColumnStorage<ColumnType::focus_str::stored_type>::Create<false>()),
2419         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
2420         depth_(ColumnStorage<ColumnType::depth::stored_type>::Create<false>()),
2421         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>()),
2422         map_name_(ColumnStorage<ColumnType::map_name::stored_type>::Create<false>()),
2423         count_(ColumnStorage<ColumnType::count::stored_type>::Create<false>()),
2424         cumulative_count_(ColumnStorage<ColumnType::cumulative_count::stored_type>::Create<false>()),
2425         size_(ColumnStorage<ColumnType::size::stored_type>::Create<false>()),
2426         cumulative_size_(ColumnStorage<ColumnType::cumulative_size::stored_type>::Create<false>()),
2427         alloc_count_(ColumnStorage<ColumnType::alloc_count::stored_type>::Create<false>()),
2428         cumulative_alloc_count_(ColumnStorage<ColumnType::cumulative_alloc_count::stored_type>::Create<false>()),
2429         alloc_size_(ColumnStorage<ColumnType::alloc_size::stored_type>::Create<false>()),
2430         cumulative_alloc_size_(ColumnStorage<ColumnType::cumulative_alloc_size::stored_type>::Create<false>()),
2431         parent_id_(ColumnStorage<ColumnType::parent_id::stored_type>::Create<false>()),
2432         source_file_(ColumnStorage<ColumnType::source_file::stored_type>::Create<false>()),
2433         line_number_(ColumnStorage<ColumnType::line_number::stored_type>::Create<false>())
2434 ,
2435         id_storage_layer_(new column::IdStorage()),
2436         type_storage_layer_(
2437           new column::StringStorage(string_pool(), &type_.vector())),
2438         profile_type_storage_layer_(
2439           new column::StringStorage(string_pool(), &profile_type_.vector())),
2440         ts_in_storage_layer_(
2441           new column::NumericStorage<ColumnType::ts_in::non_optional_stored_type>(
2442             &ts_in_.non_null_vector(),
2443             ColumnTypeHelper<ColumnType::ts_in::stored_type>::ToColumnType(),
2444             true)),
2445         ts_constraint_storage_layer_(
2446           new column::StringStorage(string_pool(), &ts_constraint_.vector())),
2447         upid_storage_layer_(
2448           new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
2449             &upid_.non_null_vector(),
2450             ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
2451             false)),
2452         upid_group_storage_layer_(
2453           new column::StringStorage(string_pool(), &upid_group_.vector())),
2454         focus_str_storage_layer_(
2455           new column::StringStorage(string_pool(), &focus_str_.vector())),
2456         ts_storage_layer_(
2457         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
2458           &ts_.vector(),
2459           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
2460           true)),
2461         depth_storage_layer_(
2462         new column::NumericStorage<ColumnType::depth::non_optional_stored_type>(
2463           &depth_.vector(),
2464           ColumnTypeHelper<ColumnType::depth::stored_type>::ToColumnType(),
2465           false)),
2466         name_storage_layer_(
2467           new column::StringStorage(string_pool(), &name_.vector())),
2468         map_name_storage_layer_(
2469           new column::StringStorage(string_pool(), &map_name_.vector())),
2470         count_storage_layer_(
2471         new column::NumericStorage<ColumnType::count::non_optional_stored_type>(
2472           &count_.vector(),
2473           ColumnTypeHelper<ColumnType::count::stored_type>::ToColumnType(),
2474           false)),
2475         cumulative_count_storage_layer_(
2476         new column::NumericStorage<ColumnType::cumulative_count::non_optional_stored_type>(
2477           &cumulative_count_.vector(),
2478           ColumnTypeHelper<ColumnType::cumulative_count::stored_type>::ToColumnType(),
2479           false)),
2480         size_storage_layer_(
2481         new column::NumericStorage<ColumnType::size::non_optional_stored_type>(
2482           &size_.vector(),
2483           ColumnTypeHelper<ColumnType::size::stored_type>::ToColumnType(),
2484           false)),
2485         cumulative_size_storage_layer_(
2486         new column::NumericStorage<ColumnType::cumulative_size::non_optional_stored_type>(
2487           &cumulative_size_.vector(),
2488           ColumnTypeHelper<ColumnType::cumulative_size::stored_type>::ToColumnType(),
2489           false)),
2490         alloc_count_storage_layer_(
2491         new column::NumericStorage<ColumnType::alloc_count::non_optional_stored_type>(
2492           &alloc_count_.vector(),
2493           ColumnTypeHelper<ColumnType::alloc_count::stored_type>::ToColumnType(),
2494           false)),
2495         cumulative_alloc_count_storage_layer_(
2496         new column::NumericStorage<ColumnType::cumulative_alloc_count::non_optional_stored_type>(
2497           &cumulative_alloc_count_.vector(),
2498           ColumnTypeHelper<ColumnType::cumulative_alloc_count::stored_type>::ToColumnType(),
2499           false)),
2500         alloc_size_storage_layer_(
2501         new column::NumericStorage<ColumnType::alloc_size::non_optional_stored_type>(
2502           &alloc_size_.vector(),
2503           ColumnTypeHelper<ColumnType::alloc_size::stored_type>::ToColumnType(),
2504           false)),
2505         cumulative_alloc_size_storage_layer_(
2506         new column::NumericStorage<ColumnType::cumulative_alloc_size::non_optional_stored_type>(
2507           &cumulative_alloc_size_.vector(),
2508           ColumnTypeHelper<ColumnType::cumulative_alloc_size::stored_type>::ToColumnType(),
2509           false)),
2510         parent_id_storage_layer_(
2511           new column::NumericStorage<ColumnType::parent_id::non_optional_stored_type>(
2512             &parent_id_.non_null_vector(),
2513             ColumnTypeHelper<ColumnType::parent_id::stored_type>::ToColumnType(),
2514             false)),
2515         source_file_storage_layer_(
2516           new column::StringStorage(string_pool(), &source_file_.vector())),
2517         line_number_storage_layer_(
2518           new column::NumericStorage<ColumnType::line_number::non_optional_stored_type>(
2519             &line_number_.non_null_vector(),
2520             ColumnTypeHelper<ColumnType::line_number::stored_type>::ToColumnType(),
2521             false))
2522 ,
2523         ts_in_null_layer_(new column::NullOverlay(ts_in_.bv())),
2524         upid_null_layer_(new column::NullOverlay(upid_.bv())),
2525         parent_id_null_layer_(new column::NullOverlay(parent_id_.bv())),
2526         line_number_null_layer_(new column::NullOverlay(line_number_.bv())) {
2527     static_assert(
2528         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::profile_type::stored_type>(
2529           ColumnFlag::profile_type),
2530         "Column type and flag combination is not valid");
2531       static_assert(
2532         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts_in::stored_type>(
2533           ColumnFlag::ts_in),
2534         "Column type and flag combination is not valid");
2535       static_assert(
2536         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts_constraint::stored_type>(
2537           ColumnFlag::ts_constraint),
2538         "Column type and flag combination is not valid");
2539       static_assert(
2540         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
2541           ColumnFlag::upid),
2542         "Column type and flag combination is not valid");
2543       static_assert(
2544         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid_group::stored_type>(
2545           ColumnFlag::upid_group),
2546         "Column type and flag combination is not valid");
2547       static_assert(
2548         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::focus_str::stored_type>(
2549           ColumnFlag::focus_str),
2550         "Column type and flag combination is not valid");
2551       static_assert(
2552         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
2553           ColumnFlag::ts),
2554         "Column type and flag combination is not valid");
2555       static_assert(
2556         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::depth::stored_type>(
2557           ColumnFlag::depth),
2558         "Column type and flag combination is not valid");
2559       static_assert(
2560         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
2561           ColumnFlag::name),
2562         "Column type and flag combination is not valid");
2563       static_assert(
2564         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::map_name::stored_type>(
2565           ColumnFlag::map_name),
2566         "Column type and flag combination is not valid");
2567       static_assert(
2568         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::count::stored_type>(
2569           ColumnFlag::count),
2570         "Column type and flag combination is not valid");
2571       static_assert(
2572         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cumulative_count::stored_type>(
2573           ColumnFlag::cumulative_count),
2574         "Column type and flag combination is not valid");
2575       static_assert(
2576         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::size::stored_type>(
2577           ColumnFlag::size),
2578         "Column type and flag combination is not valid");
2579       static_assert(
2580         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cumulative_size::stored_type>(
2581           ColumnFlag::cumulative_size),
2582         "Column type and flag combination is not valid");
2583       static_assert(
2584         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::alloc_count::stored_type>(
2585           ColumnFlag::alloc_count),
2586         "Column type and flag combination is not valid");
2587       static_assert(
2588         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cumulative_alloc_count::stored_type>(
2589           ColumnFlag::cumulative_alloc_count),
2590         "Column type and flag combination is not valid");
2591       static_assert(
2592         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::alloc_size::stored_type>(
2593           ColumnFlag::alloc_size),
2594         "Column type and flag combination is not valid");
2595       static_assert(
2596         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cumulative_alloc_size::stored_type>(
2597           ColumnFlag::cumulative_alloc_size),
2598         "Column type and flag combination is not valid");
2599       static_assert(
2600         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::parent_id::stored_type>(
2601           ColumnFlag::parent_id),
2602         "Column type and flag combination is not valid");
2603       static_assert(
2604         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::source_file::stored_type>(
2605           ColumnFlag::source_file),
2606         "Column type and flag combination is not valid");
2607       static_assert(
2608         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::line_number::stored_type>(
2609           ColumnFlag::line_number),
2610         "Column type and flag combination is not valid");
2611     OnConstructionCompletedRegularConstructor(
2612       {id_storage_layer_,type_storage_layer_,profile_type_storage_layer_,ts_in_storage_layer_,ts_constraint_storage_layer_,upid_storage_layer_,upid_group_storage_layer_,focus_str_storage_layer_,ts_storage_layer_,depth_storage_layer_,name_storage_layer_,map_name_storage_layer_,count_storage_layer_,cumulative_count_storage_layer_,size_storage_layer_,cumulative_size_storage_layer_,alloc_count_storage_layer_,cumulative_alloc_count_storage_layer_,alloc_size_storage_layer_,cumulative_alloc_size_storage_layer_,parent_id_storage_layer_,source_file_storage_layer_,line_number_storage_layer_},
2613       {{},{},{},ts_in_null_layer_,{},upid_null_layer_,{},{},{},{},{},{},{},{},{},{},{},{},{},{},parent_id_null_layer_,{},line_number_null_layer_});
2614   }
2615   ~ExperimentalFlamegraphTable() override;
2616 
Name()2617   static const char* Name() { return "experimental_flamegraph"; }
2618 
ComputeStaticSchema()2619   static Table::Schema ComputeStaticSchema() {
2620     Table::Schema schema;
2621     schema.columns.emplace_back(Table::Schema::Column{
2622         "id", SqlValue::Type::kLong, true, true, false, false});
2623     schema.columns.emplace_back(Table::Schema::Column{
2624         "type", SqlValue::Type::kString, false, false, false, false});
2625     schema.columns.emplace_back(Table::Schema::Column{
2626         "profile_type", ColumnType::profile_type::SqlValueType(), false,
2627         false,
2628         true,
2629         false});
2630     schema.columns.emplace_back(Table::Schema::Column{
2631         "ts_in", ColumnType::ts_in::SqlValueType(), false,
2632         true,
2633         true,
2634         false});
2635     schema.columns.emplace_back(Table::Schema::Column{
2636         "ts_constraint", ColumnType::ts_constraint::SqlValueType(), false,
2637         false,
2638         true,
2639         false});
2640     schema.columns.emplace_back(Table::Schema::Column{
2641         "upid", ColumnType::upid::SqlValueType(), false,
2642         false,
2643         true,
2644         false});
2645     schema.columns.emplace_back(Table::Schema::Column{
2646         "upid_group", ColumnType::upid_group::SqlValueType(), false,
2647         false,
2648         true,
2649         false});
2650     schema.columns.emplace_back(Table::Schema::Column{
2651         "focus_str", ColumnType::focus_str::SqlValueType(), false,
2652         false,
2653         true,
2654         false});
2655     schema.columns.emplace_back(Table::Schema::Column{
2656         "ts", ColumnType::ts::SqlValueType(), false,
2657         true,
2658         false,
2659         false});
2660     schema.columns.emplace_back(Table::Schema::Column{
2661         "depth", ColumnType::depth::SqlValueType(), false,
2662         false,
2663         false,
2664         false});
2665     schema.columns.emplace_back(Table::Schema::Column{
2666         "name", ColumnType::name::SqlValueType(), false,
2667         false,
2668         false,
2669         false});
2670     schema.columns.emplace_back(Table::Schema::Column{
2671         "map_name", ColumnType::map_name::SqlValueType(), false,
2672         false,
2673         false,
2674         false});
2675     schema.columns.emplace_back(Table::Schema::Column{
2676         "count", ColumnType::count::SqlValueType(), false,
2677         false,
2678         false,
2679         false});
2680     schema.columns.emplace_back(Table::Schema::Column{
2681         "cumulative_count", ColumnType::cumulative_count::SqlValueType(), false,
2682         false,
2683         false,
2684         false});
2685     schema.columns.emplace_back(Table::Schema::Column{
2686         "size", ColumnType::size::SqlValueType(), false,
2687         false,
2688         false,
2689         false});
2690     schema.columns.emplace_back(Table::Schema::Column{
2691         "cumulative_size", ColumnType::cumulative_size::SqlValueType(), false,
2692         false,
2693         false,
2694         false});
2695     schema.columns.emplace_back(Table::Schema::Column{
2696         "alloc_count", ColumnType::alloc_count::SqlValueType(), false,
2697         false,
2698         false,
2699         false});
2700     schema.columns.emplace_back(Table::Schema::Column{
2701         "cumulative_alloc_count", ColumnType::cumulative_alloc_count::SqlValueType(), false,
2702         false,
2703         false,
2704         false});
2705     schema.columns.emplace_back(Table::Schema::Column{
2706         "alloc_size", ColumnType::alloc_size::SqlValueType(), false,
2707         false,
2708         false,
2709         false});
2710     schema.columns.emplace_back(Table::Schema::Column{
2711         "cumulative_alloc_size", ColumnType::cumulative_alloc_size::SqlValueType(), false,
2712         false,
2713         false,
2714         false});
2715     schema.columns.emplace_back(Table::Schema::Column{
2716         "parent_id", ColumnType::parent_id::SqlValueType(), false,
2717         false,
2718         false,
2719         false});
2720     schema.columns.emplace_back(Table::Schema::Column{
2721         "source_file", ColumnType::source_file::SqlValueType(), false,
2722         false,
2723         false,
2724         false});
2725     schema.columns.emplace_back(Table::Schema::Column{
2726         "line_number", ColumnType::line_number::SqlValueType(), false,
2727         false,
2728         false,
2729         false});
2730     return schema;
2731   }
2732 
IterateRows()2733   ConstIterator IterateRows() const {
2734     return ConstIterator(this, Table::IterateRows());
2735   }
2736 
IterateRows()2737   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
2738 
FilterToIterator(const Query & q)2739   ConstIterator FilterToIterator(const Query& q) const {
2740     return ConstIterator(this, QueryToIterator(q));
2741   }
2742 
FilterToIterator(const Query & q)2743   Iterator FilterToIterator(const Query& q) {
2744     return Iterator(this, QueryToIterator(q));
2745   }
2746 
ShrinkToFit()2747   void ShrinkToFit() {
2748     type_.ShrinkToFit();
2749     profile_type_.ShrinkToFit();
2750     ts_in_.ShrinkToFit();
2751     ts_constraint_.ShrinkToFit();
2752     upid_.ShrinkToFit();
2753     upid_group_.ShrinkToFit();
2754     focus_str_.ShrinkToFit();
2755     ts_.ShrinkToFit();
2756     depth_.ShrinkToFit();
2757     name_.ShrinkToFit();
2758     map_name_.ShrinkToFit();
2759     count_.ShrinkToFit();
2760     cumulative_count_.ShrinkToFit();
2761     size_.ShrinkToFit();
2762     cumulative_size_.ShrinkToFit();
2763     alloc_count_.ShrinkToFit();
2764     cumulative_alloc_count_.ShrinkToFit();
2765     alloc_size_.ShrinkToFit();
2766     cumulative_alloc_size_.ShrinkToFit();
2767     parent_id_.ShrinkToFit();
2768     source_file_.ShrinkToFit();
2769     line_number_.ShrinkToFit();
2770   }
2771 
2772   ConstRowReference operator[](uint32_t r) const {
2773     return ConstRowReference(this, r);
2774   }
2775   RowReference operator[](uint32_t r) { return RowReference(this, r); }
2776   ConstRowReference operator[](RowNumber r) const {
2777     return ConstRowReference(this, r.row_number());
2778   }
2779   RowReference operator[](RowNumber r) {
2780     return RowReference(this, r.row_number());
2781   }
2782 
FindById(Id find_id)2783   std::optional<ConstRowReference> FindById(Id find_id) const {
2784     std::optional<uint32_t> row = id().IndexOf(find_id);
2785     return row ? std::make_optional(ConstRowReference(this, *row))
2786                : std::nullopt;
2787   }
2788 
FindById(Id find_id)2789   std::optional<RowReference> FindById(Id find_id) {
2790     std::optional<uint32_t> row = id().IndexOf(find_id);
2791     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
2792   }
2793 
Insert(const Row & row)2794   IdAndRow Insert(const Row& row) {
2795     uint32_t row_number = row_count();
2796     Id id = Id{row_number};
2797     type_.Append(string_pool()->InternString(row.type()));
2798     mutable_profile_type()->Append(row.profile_type);
2799     mutable_ts_in()->Append(row.ts_in);
2800     mutable_ts_constraint()->Append(row.ts_constraint);
2801     mutable_upid()->Append(row.upid);
2802     mutable_upid_group()->Append(row.upid_group);
2803     mutable_focus_str()->Append(row.focus_str);
2804     mutable_ts()->Append(row.ts);
2805     mutable_depth()->Append(row.depth);
2806     mutable_name()->Append(row.name);
2807     mutable_map_name()->Append(row.map_name);
2808     mutable_count()->Append(row.count);
2809     mutable_cumulative_count()->Append(row.cumulative_count);
2810     mutable_size()->Append(row.size);
2811     mutable_cumulative_size()->Append(row.cumulative_size);
2812     mutable_alloc_count()->Append(row.alloc_count);
2813     mutable_cumulative_alloc_count()->Append(row.cumulative_alloc_count);
2814     mutable_alloc_size()->Append(row.alloc_size);
2815     mutable_cumulative_alloc_size()->Append(row.cumulative_alloc_size);
2816     mutable_parent_id()->Append(row.parent_id);
2817     mutable_source_file()->Append(row.source_file);
2818     mutable_line_number()->Append(row.line_number);
2819     UpdateSelfOverlayAfterInsert();
2820     return IdAndRow{id, row_number, RowReference(this, row_number),
2821                      RowNumber(row_number)};
2822   }
2823 
2824 
2825 
id()2826   const IdColumn<ExperimentalFlamegraphTable::Id>& id() const {
2827     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
2828   }
type()2829   const TypedColumn<StringPool::Id>& type() const {
2830     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
2831   }
profile_type()2832   const TypedColumn<StringPool::Id>& profile_type() const {
2833     return static_cast<const ColumnType::profile_type&>(columns()[ColumnIndex::profile_type]);
2834   }
ts_in()2835   const TypedColumn<std::optional<int64_t>>& ts_in() const {
2836     return static_cast<const ColumnType::ts_in&>(columns()[ColumnIndex::ts_in]);
2837   }
ts_constraint()2838   const TypedColumn<std::optional<StringPool::Id>>& ts_constraint() const {
2839     return static_cast<const ColumnType::ts_constraint&>(columns()[ColumnIndex::ts_constraint]);
2840   }
upid()2841   const TypedColumn<std::optional<uint32_t>>& upid() const {
2842     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
2843   }
upid_group()2844   const TypedColumn<std::optional<StringPool::Id>>& upid_group() const {
2845     return static_cast<const ColumnType::upid_group&>(columns()[ColumnIndex::upid_group]);
2846   }
focus_str()2847   const TypedColumn<std::optional<StringPool::Id>>& focus_str() const {
2848     return static_cast<const ColumnType::focus_str&>(columns()[ColumnIndex::focus_str]);
2849   }
ts()2850   const TypedColumn<int64_t>& ts() const {
2851     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
2852   }
depth()2853   const TypedColumn<uint32_t>& depth() const {
2854     return static_cast<const ColumnType::depth&>(columns()[ColumnIndex::depth]);
2855   }
name()2856   const TypedColumn<StringPool::Id>& name() const {
2857     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
2858   }
map_name()2859   const TypedColumn<StringPool::Id>& map_name() const {
2860     return static_cast<const ColumnType::map_name&>(columns()[ColumnIndex::map_name]);
2861   }
count()2862   const TypedColumn<int64_t>& count() const {
2863     return static_cast<const ColumnType::count&>(columns()[ColumnIndex::count]);
2864   }
cumulative_count()2865   const TypedColumn<int64_t>& cumulative_count() const {
2866     return static_cast<const ColumnType::cumulative_count&>(columns()[ColumnIndex::cumulative_count]);
2867   }
size()2868   const TypedColumn<int64_t>& size() const {
2869     return static_cast<const ColumnType::size&>(columns()[ColumnIndex::size]);
2870   }
cumulative_size()2871   const TypedColumn<int64_t>& cumulative_size() const {
2872     return static_cast<const ColumnType::cumulative_size&>(columns()[ColumnIndex::cumulative_size]);
2873   }
alloc_count()2874   const TypedColumn<int64_t>& alloc_count() const {
2875     return static_cast<const ColumnType::alloc_count&>(columns()[ColumnIndex::alloc_count]);
2876   }
cumulative_alloc_count()2877   const TypedColumn<int64_t>& cumulative_alloc_count() const {
2878     return static_cast<const ColumnType::cumulative_alloc_count&>(columns()[ColumnIndex::cumulative_alloc_count]);
2879   }
alloc_size()2880   const TypedColumn<int64_t>& alloc_size() const {
2881     return static_cast<const ColumnType::alloc_size&>(columns()[ColumnIndex::alloc_size]);
2882   }
cumulative_alloc_size()2883   const TypedColumn<int64_t>& cumulative_alloc_size() const {
2884     return static_cast<const ColumnType::cumulative_alloc_size&>(columns()[ColumnIndex::cumulative_alloc_size]);
2885   }
parent_id()2886   const TypedColumn<std::optional<ExperimentalFlamegraphTable::Id>>& parent_id() const {
2887     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
2888   }
source_file()2889   const TypedColumn<std::optional<StringPool::Id>>& source_file() const {
2890     return static_cast<const ColumnType::source_file&>(columns()[ColumnIndex::source_file]);
2891   }
line_number()2892   const TypedColumn<std::optional<uint32_t>>& line_number() const {
2893     return static_cast<const ColumnType::line_number&>(columns()[ColumnIndex::line_number]);
2894   }
2895 
mutable_profile_type()2896   TypedColumn<StringPool::Id>* mutable_profile_type() {
2897     return static_cast<ColumnType::profile_type*>(
2898         GetColumn(ColumnIndex::profile_type));
2899   }
mutable_ts_in()2900   TypedColumn<std::optional<int64_t>>* mutable_ts_in() {
2901     return static_cast<ColumnType::ts_in*>(
2902         GetColumn(ColumnIndex::ts_in));
2903   }
mutable_ts_constraint()2904   TypedColumn<std::optional<StringPool::Id>>* mutable_ts_constraint() {
2905     return static_cast<ColumnType::ts_constraint*>(
2906         GetColumn(ColumnIndex::ts_constraint));
2907   }
mutable_upid()2908   TypedColumn<std::optional<uint32_t>>* mutable_upid() {
2909     return static_cast<ColumnType::upid*>(
2910         GetColumn(ColumnIndex::upid));
2911   }
mutable_upid_group()2912   TypedColumn<std::optional<StringPool::Id>>* mutable_upid_group() {
2913     return static_cast<ColumnType::upid_group*>(
2914         GetColumn(ColumnIndex::upid_group));
2915   }
mutable_focus_str()2916   TypedColumn<std::optional<StringPool::Id>>* mutable_focus_str() {
2917     return static_cast<ColumnType::focus_str*>(
2918         GetColumn(ColumnIndex::focus_str));
2919   }
mutable_ts()2920   TypedColumn<int64_t>* mutable_ts() {
2921     return static_cast<ColumnType::ts*>(
2922         GetColumn(ColumnIndex::ts));
2923   }
mutable_depth()2924   TypedColumn<uint32_t>* mutable_depth() {
2925     return static_cast<ColumnType::depth*>(
2926         GetColumn(ColumnIndex::depth));
2927   }
mutable_name()2928   TypedColumn<StringPool::Id>* mutable_name() {
2929     return static_cast<ColumnType::name*>(
2930         GetColumn(ColumnIndex::name));
2931   }
mutable_map_name()2932   TypedColumn<StringPool::Id>* mutable_map_name() {
2933     return static_cast<ColumnType::map_name*>(
2934         GetColumn(ColumnIndex::map_name));
2935   }
mutable_count()2936   TypedColumn<int64_t>* mutable_count() {
2937     return static_cast<ColumnType::count*>(
2938         GetColumn(ColumnIndex::count));
2939   }
mutable_cumulative_count()2940   TypedColumn<int64_t>* mutable_cumulative_count() {
2941     return static_cast<ColumnType::cumulative_count*>(
2942         GetColumn(ColumnIndex::cumulative_count));
2943   }
mutable_size()2944   TypedColumn<int64_t>* mutable_size() {
2945     return static_cast<ColumnType::size*>(
2946         GetColumn(ColumnIndex::size));
2947   }
mutable_cumulative_size()2948   TypedColumn<int64_t>* mutable_cumulative_size() {
2949     return static_cast<ColumnType::cumulative_size*>(
2950         GetColumn(ColumnIndex::cumulative_size));
2951   }
mutable_alloc_count()2952   TypedColumn<int64_t>* mutable_alloc_count() {
2953     return static_cast<ColumnType::alloc_count*>(
2954         GetColumn(ColumnIndex::alloc_count));
2955   }
mutable_cumulative_alloc_count()2956   TypedColumn<int64_t>* mutable_cumulative_alloc_count() {
2957     return static_cast<ColumnType::cumulative_alloc_count*>(
2958         GetColumn(ColumnIndex::cumulative_alloc_count));
2959   }
mutable_alloc_size()2960   TypedColumn<int64_t>* mutable_alloc_size() {
2961     return static_cast<ColumnType::alloc_size*>(
2962         GetColumn(ColumnIndex::alloc_size));
2963   }
mutable_cumulative_alloc_size()2964   TypedColumn<int64_t>* mutable_cumulative_alloc_size() {
2965     return static_cast<ColumnType::cumulative_alloc_size*>(
2966         GetColumn(ColumnIndex::cumulative_alloc_size));
2967   }
mutable_parent_id()2968   TypedColumn<std::optional<ExperimentalFlamegraphTable::Id>>* mutable_parent_id() {
2969     return static_cast<ColumnType::parent_id*>(
2970         GetColumn(ColumnIndex::parent_id));
2971   }
mutable_source_file()2972   TypedColumn<std::optional<StringPool::Id>>* mutable_source_file() {
2973     return static_cast<ColumnType::source_file*>(
2974         GetColumn(ColumnIndex::source_file));
2975   }
mutable_line_number()2976   TypedColumn<std::optional<uint32_t>>* mutable_line_number() {
2977     return static_cast<ColumnType::line_number*>(
2978         GetColumn(ColumnIndex::line_number));
2979   }
2980 
2981  private:
2982 
2983 
2984   ColumnStorage<ColumnType::profile_type::stored_type> profile_type_;
2985   ColumnStorage<ColumnType::ts_in::stored_type> ts_in_;
2986   ColumnStorage<ColumnType::ts_constraint::stored_type> ts_constraint_;
2987   ColumnStorage<ColumnType::upid::stored_type> upid_;
2988   ColumnStorage<ColumnType::upid_group::stored_type> upid_group_;
2989   ColumnStorage<ColumnType::focus_str::stored_type> focus_str_;
2990   ColumnStorage<ColumnType::ts::stored_type> ts_;
2991   ColumnStorage<ColumnType::depth::stored_type> depth_;
2992   ColumnStorage<ColumnType::name::stored_type> name_;
2993   ColumnStorage<ColumnType::map_name::stored_type> map_name_;
2994   ColumnStorage<ColumnType::count::stored_type> count_;
2995   ColumnStorage<ColumnType::cumulative_count::stored_type> cumulative_count_;
2996   ColumnStorage<ColumnType::size::stored_type> size_;
2997   ColumnStorage<ColumnType::cumulative_size::stored_type> cumulative_size_;
2998   ColumnStorage<ColumnType::alloc_count::stored_type> alloc_count_;
2999   ColumnStorage<ColumnType::cumulative_alloc_count::stored_type> cumulative_alloc_count_;
3000   ColumnStorage<ColumnType::alloc_size::stored_type> alloc_size_;
3001   ColumnStorage<ColumnType::cumulative_alloc_size::stored_type> cumulative_alloc_size_;
3002   ColumnStorage<ColumnType::parent_id::stored_type> parent_id_;
3003   ColumnStorage<ColumnType::source_file::stored_type> source_file_;
3004   ColumnStorage<ColumnType::line_number::stored_type> line_number_;
3005 
3006   RefPtr<column::StorageLayer> id_storage_layer_;
3007   RefPtr<column::StorageLayer> type_storage_layer_;
3008   RefPtr<column::StorageLayer> profile_type_storage_layer_;
3009   RefPtr<column::StorageLayer> ts_in_storage_layer_;
3010   RefPtr<column::StorageLayer> ts_constraint_storage_layer_;
3011   RefPtr<column::StorageLayer> upid_storage_layer_;
3012   RefPtr<column::StorageLayer> upid_group_storage_layer_;
3013   RefPtr<column::StorageLayer> focus_str_storage_layer_;
3014   RefPtr<column::StorageLayer> ts_storage_layer_;
3015   RefPtr<column::StorageLayer> depth_storage_layer_;
3016   RefPtr<column::StorageLayer> name_storage_layer_;
3017   RefPtr<column::StorageLayer> map_name_storage_layer_;
3018   RefPtr<column::StorageLayer> count_storage_layer_;
3019   RefPtr<column::StorageLayer> cumulative_count_storage_layer_;
3020   RefPtr<column::StorageLayer> size_storage_layer_;
3021   RefPtr<column::StorageLayer> cumulative_size_storage_layer_;
3022   RefPtr<column::StorageLayer> alloc_count_storage_layer_;
3023   RefPtr<column::StorageLayer> cumulative_alloc_count_storage_layer_;
3024   RefPtr<column::StorageLayer> alloc_size_storage_layer_;
3025   RefPtr<column::StorageLayer> cumulative_alloc_size_storage_layer_;
3026   RefPtr<column::StorageLayer> parent_id_storage_layer_;
3027   RefPtr<column::StorageLayer> source_file_storage_layer_;
3028   RefPtr<column::StorageLayer> line_number_storage_layer_;
3029 
3030   RefPtr<column::OverlayLayer> ts_in_null_layer_;
3031   RefPtr<column::OverlayLayer> upid_null_layer_;
3032   RefPtr<column::OverlayLayer> parent_id_null_layer_;
3033   RefPtr<column::OverlayLayer> line_number_null_layer_;
3034 };
3035 
3036 
3037 class GpuCounterGroupTable : public macros_internal::MacroTable {
3038  public:
3039   static constexpr uint32_t kColumnCount = 4;
3040 
3041   struct Id : public BaseId {
3042     Id() = default;
IdId3043     explicit constexpr Id(uint32_t v) : BaseId(v) {}
3044   };
3045   static_assert(std::is_trivially_destructible_v<Id>,
3046                 "Inheritance used without trivial destruction");
3047 
3048   struct ColumnIndex {
3049     static constexpr uint32_t id = 0;
3050     static constexpr uint32_t type = 1;
3051     static constexpr uint32_t group_id = 2;
3052     static constexpr uint32_t track_id = 3;
3053   };
3054   struct ColumnType {
3055     using id = IdColumn<GpuCounterGroupTable::Id>;
3056     using type = TypedColumn<StringPool::Id>;
3057     using group_id = TypedColumn<int32_t>;
3058     using track_id = TypedColumn<TrackTable::Id>;
3059   };
3060   struct Row : public macros_internal::RootParentTable::Row {
3061     Row(int32_t in_group_id = {},
3062         TrackTable::Id in_track_id = {},
3063         std::nullptr_t = nullptr)
RowRow3064         : macros_internal::RootParentTable::Row(),
3065           group_id(in_group_id),
3066           track_id(in_track_id) {
3067       type_ = "gpu_counter_group";
3068     }
3069     int32_t group_id;
3070     TrackTable::Id track_id;
3071 
3072     bool operator==(const GpuCounterGroupTable::Row& other) const {
3073       return type() == other.type() && ColumnType::group_id::Equals(group_id, other.group_id) &&
3074        ColumnType::track_id::Equals(track_id, other.track_id);
3075     }
3076   };
3077   struct ColumnFlag {
3078     static constexpr uint32_t group_id = ColumnType::group_id::default_flags();
3079     static constexpr uint32_t track_id = ColumnType::track_id::default_flags();
3080   };
3081 
3082   class RowNumber;
3083   class ConstRowReference;
3084   class RowReference;
3085 
3086   class RowNumber : public macros_internal::AbstractRowNumber<
3087       GpuCounterGroupTable, ConstRowReference, RowReference> {
3088    public:
RowNumber(uint32_t row_number)3089     explicit RowNumber(uint32_t row_number)
3090         : AbstractRowNumber(row_number) {}
3091   };
3092   static_assert(std::is_trivially_destructible_v<RowNumber>,
3093                 "Inheritance used without trivial destruction");
3094 
3095   class ConstRowReference : public macros_internal::AbstractConstRowReference<
3096     GpuCounterGroupTable, RowNumber> {
3097    public:
ConstRowReference(const GpuCounterGroupTable * table,uint32_t row_number)3098     ConstRowReference(const GpuCounterGroupTable* table, uint32_t row_number)
3099         : AbstractConstRowReference(table, row_number) {}
3100 
id()3101     ColumnType::id::type id() const {
3102       return table()->id()[row_number_];
3103     }
type()3104     ColumnType::type::type type() const {
3105       return table()->type()[row_number_];
3106     }
group_id()3107     ColumnType::group_id::type group_id() const {
3108       return table()->group_id()[row_number_];
3109     }
track_id()3110     ColumnType::track_id::type track_id() const {
3111       return table()->track_id()[row_number_];
3112     }
3113   };
3114   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
3115                 "Inheritance used without trivial destruction");
3116   class RowReference : public ConstRowReference {
3117    public:
RowReference(const GpuCounterGroupTable * table,uint32_t row_number)3118     RowReference(const GpuCounterGroupTable* table, uint32_t row_number)
3119         : ConstRowReference(table, row_number) {}
3120 
set_group_id(ColumnType::group_id::non_optional_type v)3121     void set_group_id(
3122         ColumnType::group_id::non_optional_type v) {
3123       return mutable_table()->mutable_group_id()->Set(row_number_, v);
3124     }
set_track_id(ColumnType::track_id::non_optional_type v)3125     void set_track_id(
3126         ColumnType::track_id::non_optional_type v) {
3127       return mutable_table()->mutable_track_id()->Set(row_number_, v);
3128     }
3129 
3130    private:
mutable_table()3131     GpuCounterGroupTable* mutable_table() const {
3132       return const_cast<GpuCounterGroupTable*>(table());
3133     }
3134   };
3135   static_assert(std::is_trivially_destructible_v<RowReference>,
3136                 "Inheritance used without trivial destruction");
3137 
3138   class ConstIterator;
3139   class ConstIterator : public macros_internal::AbstractConstIterator<
3140     ConstIterator, GpuCounterGroupTable, RowNumber, ConstRowReference> {
3141    public:
id()3142     ColumnType::id::type id() const {
3143       const auto& col = table()->id();
3144       return col.GetAtIdx(
3145         iterator_.StorageIndexForColumn(col.index_in_table()));
3146     }
type()3147     ColumnType::type::type type() const {
3148       const auto& col = table()->type();
3149       return col.GetAtIdx(
3150         iterator_.StorageIndexForColumn(col.index_in_table()));
3151     }
group_id()3152     ColumnType::group_id::type group_id() const {
3153       const auto& col = table()->group_id();
3154       return col.GetAtIdx(
3155         iterator_.StorageIndexForColumn(col.index_in_table()));
3156     }
track_id()3157     ColumnType::track_id::type track_id() const {
3158       const auto& col = table()->track_id();
3159       return col.GetAtIdx(
3160         iterator_.StorageIndexForColumn(col.index_in_table()));
3161     }
3162 
3163    protected:
ConstIterator(const GpuCounterGroupTable * table,Table::Iterator iterator)3164     explicit ConstIterator(const GpuCounterGroupTable* table,
3165                            Table::Iterator iterator)
3166         : AbstractConstIterator(table, std::move(iterator)) {}
3167 
CurrentRowNumber()3168     uint32_t CurrentRowNumber() const {
3169       return iterator_.StorageIndexForLastOverlay();
3170     }
3171 
3172    private:
3173     friend class GpuCounterGroupTable;
3174     friend class macros_internal::AbstractConstIterator<
3175       ConstIterator, GpuCounterGroupTable, RowNumber, ConstRowReference>;
3176   };
3177   class Iterator : public ConstIterator {
3178     public:
row_reference()3179      RowReference row_reference() const {
3180        return {const_cast<GpuCounterGroupTable*>(table()), CurrentRowNumber()};
3181      }
3182 
3183     private:
3184      friend class GpuCounterGroupTable;
3185 
Iterator(GpuCounterGroupTable * table,Table::Iterator iterator)3186      explicit Iterator(GpuCounterGroupTable* table, Table::Iterator iterator)
3187         : ConstIterator(table, std::move(iterator)) {}
3188   };
3189 
3190   struct IdAndRow {
3191     Id id;
3192     uint32_t row;
3193     RowReference row_reference;
3194     RowNumber row_number;
3195   };
3196 
GetColumns(GpuCounterGroupTable * self,const macros_internal::MacroTable * parent)3197   static std::vector<ColumnLegacy> GetColumns(
3198       GpuCounterGroupTable* self,
3199       const macros_internal::MacroTable* parent) {
3200     std::vector<ColumnLegacy> columns =
3201         CopyColumnsFromParentOrAddRootColumns(self, parent);
3202     uint32_t olay_idx = OverlayCount(parent);
3203     AddColumnToVector(columns, "group_id", &self->group_id_, ColumnFlag::group_id,
3204                       static_cast<uint32_t>(columns.size()), olay_idx);
3205     AddColumnToVector(columns, "track_id", &self->track_id_, ColumnFlag::track_id,
3206                       static_cast<uint32_t>(columns.size()), olay_idx);
3207     return columns;
3208   }
3209 
GpuCounterGroupTable(StringPool * pool)3210   PERFETTO_NO_INLINE explicit GpuCounterGroupTable(StringPool* pool)
3211       : macros_internal::MacroTable(
3212           pool,
3213           GetColumns(this, nullptr),
3214           nullptr),
3215         group_id_(ColumnStorage<ColumnType::group_id::stored_type>::Create<false>()),
3216         track_id_(ColumnStorage<ColumnType::track_id::stored_type>::Create<false>())
3217 ,
3218         id_storage_layer_(new column::IdStorage()),
3219         type_storage_layer_(
3220           new column::StringStorage(string_pool(), &type_.vector())),
3221         group_id_storage_layer_(
3222         new column::NumericStorage<ColumnType::group_id::non_optional_stored_type>(
3223           &group_id_.vector(),
3224           ColumnTypeHelper<ColumnType::group_id::stored_type>::ToColumnType(),
3225           false)),
3226         track_id_storage_layer_(
3227         new column::NumericStorage<ColumnType::track_id::non_optional_stored_type>(
3228           &track_id_.vector(),
3229           ColumnTypeHelper<ColumnType::track_id::stored_type>::ToColumnType(),
3230           false))
3231          {
3232     static_assert(
3233         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::group_id::stored_type>(
3234           ColumnFlag::group_id),
3235         "Column type and flag combination is not valid");
3236       static_assert(
3237         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::track_id::stored_type>(
3238           ColumnFlag::track_id),
3239         "Column type and flag combination is not valid");
3240     OnConstructionCompletedRegularConstructor(
3241       {id_storage_layer_,type_storage_layer_,group_id_storage_layer_,track_id_storage_layer_},
3242       {{},{},{},{}});
3243   }
3244   ~GpuCounterGroupTable() override;
3245 
Name()3246   static const char* Name() { return "gpu_counter_group"; }
3247 
ComputeStaticSchema()3248   static Table::Schema ComputeStaticSchema() {
3249     Table::Schema schema;
3250     schema.columns.emplace_back(Table::Schema::Column{
3251         "id", SqlValue::Type::kLong, true, true, false, false});
3252     schema.columns.emplace_back(Table::Schema::Column{
3253         "type", SqlValue::Type::kString, false, false, false, false});
3254     schema.columns.emplace_back(Table::Schema::Column{
3255         "group_id", ColumnType::group_id::SqlValueType(), false,
3256         false,
3257         false,
3258         false});
3259     schema.columns.emplace_back(Table::Schema::Column{
3260         "track_id", ColumnType::track_id::SqlValueType(), false,
3261         false,
3262         false,
3263         false});
3264     return schema;
3265   }
3266 
IterateRows()3267   ConstIterator IterateRows() const {
3268     return ConstIterator(this, Table::IterateRows());
3269   }
3270 
IterateRows()3271   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
3272 
FilterToIterator(const Query & q)3273   ConstIterator FilterToIterator(const Query& q) const {
3274     return ConstIterator(this, QueryToIterator(q));
3275   }
3276 
FilterToIterator(const Query & q)3277   Iterator FilterToIterator(const Query& q) {
3278     return Iterator(this, QueryToIterator(q));
3279   }
3280 
ShrinkToFit()3281   void ShrinkToFit() {
3282     type_.ShrinkToFit();
3283     group_id_.ShrinkToFit();
3284     track_id_.ShrinkToFit();
3285   }
3286 
3287   ConstRowReference operator[](uint32_t r) const {
3288     return ConstRowReference(this, r);
3289   }
3290   RowReference operator[](uint32_t r) { return RowReference(this, r); }
3291   ConstRowReference operator[](RowNumber r) const {
3292     return ConstRowReference(this, r.row_number());
3293   }
3294   RowReference operator[](RowNumber r) {
3295     return RowReference(this, r.row_number());
3296   }
3297 
FindById(Id find_id)3298   std::optional<ConstRowReference> FindById(Id find_id) const {
3299     std::optional<uint32_t> row = id().IndexOf(find_id);
3300     return row ? std::make_optional(ConstRowReference(this, *row))
3301                : std::nullopt;
3302   }
3303 
FindById(Id find_id)3304   std::optional<RowReference> FindById(Id find_id) {
3305     std::optional<uint32_t> row = id().IndexOf(find_id);
3306     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
3307   }
3308 
Insert(const Row & row)3309   IdAndRow Insert(const Row& row) {
3310     uint32_t row_number = row_count();
3311     Id id = Id{row_number};
3312     type_.Append(string_pool()->InternString(row.type()));
3313     mutable_group_id()->Append(row.group_id);
3314     mutable_track_id()->Append(row.track_id);
3315     UpdateSelfOverlayAfterInsert();
3316     return IdAndRow{id, row_number, RowReference(this, row_number),
3317                      RowNumber(row_number)};
3318   }
3319 
3320 
3321 
id()3322   const IdColumn<GpuCounterGroupTable::Id>& id() const {
3323     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
3324   }
type()3325   const TypedColumn<StringPool::Id>& type() const {
3326     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
3327   }
group_id()3328   const TypedColumn<int32_t>& group_id() const {
3329     return static_cast<const ColumnType::group_id&>(columns()[ColumnIndex::group_id]);
3330   }
track_id()3331   const TypedColumn<TrackTable::Id>& track_id() const {
3332     return static_cast<const ColumnType::track_id&>(columns()[ColumnIndex::track_id]);
3333   }
3334 
mutable_group_id()3335   TypedColumn<int32_t>* mutable_group_id() {
3336     return static_cast<ColumnType::group_id*>(
3337         GetColumn(ColumnIndex::group_id));
3338   }
mutable_track_id()3339   TypedColumn<TrackTable::Id>* mutable_track_id() {
3340     return static_cast<ColumnType::track_id*>(
3341         GetColumn(ColumnIndex::track_id));
3342   }
3343 
3344  private:
3345 
3346 
3347   ColumnStorage<ColumnType::group_id::stored_type> group_id_;
3348   ColumnStorage<ColumnType::track_id::stored_type> track_id_;
3349 
3350   RefPtr<column::StorageLayer> id_storage_layer_;
3351   RefPtr<column::StorageLayer> type_storage_layer_;
3352   RefPtr<column::StorageLayer> group_id_storage_layer_;
3353   RefPtr<column::StorageLayer> track_id_storage_layer_;
3354 
3355 
3356 };
3357 
3358 
3359 class HeapGraphClassTable : public macros_internal::MacroTable {
3360  public:
3361   static constexpr uint32_t kColumnCount = 8;
3362 
3363   struct Id : public BaseId {
3364     Id() = default;
IdId3365     explicit constexpr Id(uint32_t v) : BaseId(v) {}
3366   };
3367   static_assert(std::is_trivially_destructible_v<Id>,
3368                 "Inheritance used without trivial destruction");
3369 
3370   struct ColumnIndex {
3371     static constexpr uint32_t id = 0;
3372     static constexpr uint32_t type = 1;
3373     static constexpr uint32_t name = 2;
3374     static constexpr uint32_t deobfuscated_name = 3;
3375     static constexpr uint32_t location = 4;
3376     static constexpr uint32_t superclass_id = 5;
3377     static constexpr uint32_t classloader_id = 6;
3378     static constexpr uint32_t kind = 7;
3379   };
3380   struct ColumnType {
3381     using id = IdColumn<HeapGraphClassTable::Id>;
3382     using type = TypedColumn<StringPool::Id>;
3383     using name = TypedColumn<StringPool::Id>;
3384     using deobfuscated_name = TypedColumn<std::optional<StringPool::Id>>;
3385     using location = TypedColumn<std::optional<StringPool::Id>>;
3386     using superclass_id = TypedColumn<std::optional<HeapGraphClassTable::Id>>;
3387     using classloader_id = TypedColumn<std::optional<uint32_t>>;
3388     using kind = TypedColumn<StringPool::Id>;
3389   };
3390   struct Row : public macros_internal::RootParentTable::Row {
3391     Row(StringPool::Id in_name = {},
3392         std::optional<StringPool::Id> in_deobfuscated_name = {},
3393         std::optional<StringPool::Id> in_location = {},
3394         std::optional<HeapGraphClassTable::Id> in_superclass_id = {},
3395         std::optional<uint32_t> in_classloader_id = {},
3396         StringPool::Id in_kind = {},
3397         std::nullptr_t = nullptr)
RowRow3398         : macros_internal::RootParentTable::Row(),
3399           name(in_name),
3400           deobfuscated_name(in_deobfuscated_name),
3401           location(in_location),
3402           superclass_id(in_superclass_id),
3403           classloader_id(in_classloader_id),
3404           kind(in_kind) {
3405       type_ = "heap_graph_class";
3406     }
3407     StringPool::Id name;
3408     std::optional<StringPool::Id> deobfuscated_name;
3409     std::optional<StringPool::Id> location;
3410     std::optional<HeapGraphClassTable::Id> superclass_id;
3411     std::optional<uint32_t> classloader_id;
3412     StringPool::Id kind;
3413 
3414     bool operator==(const HeapGraphClassTable::Row& other) const {
3415       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
3416        ColumnType::deobfuscated_name::Equals(deobfuscated_name, other.deobfuscated_name) &&
3417        ColumnType::location::Equals(location, other.location) &&
3418        ColumnType::superclass_id::Equals(superclass_id, other.superclass_id) &&
3419        ColumnType::classloader_id::Equals(classloader_id, other.classloader_id) &&
3420        ColumnType::kind::Equals(kind, other.kind);
3421     }
3422   };
3423   struct ColumnFlag {
3424     static constexpr uint32_t name = ColumnType::name::default_flags();
3425     static constexpr uint32_t deobfuscated_name = ColumnType::deobfuscated_name::default_flags();
3426     static constexpr uint32_t location = ColumnType::location::default_flags();
3427     static constexpr uint32_t superclass_id = ColumnType::superclass_id::default_flags();
3428     static constexpr uint32_t classloader_id = ColumnType::classloader_id::default_flags();
3429     static constexpr uint32_t kind = ColumnType::kind::default_flags();
3430   };
3431 
3432   class RowNumber;
3433   class ConstRowReference;
3434   class RowReference;
3435 
3436   class RowNumber : public macros_internal::AbstractRowNumber<
3437       HeapGraphClassTable, ConstRowReference, RowReference> {
3438    public:
RowNumber(uint32_t row_number)3439     explicit RowNumber(uint32_t row_number)
3440         : AbstractRowNumber(row_number) {}
3441   };
3442   static_assert(std::is_trivially_destructible_v<RowNumber>,
3443                 "Inheritance used without trivial destruction");
3444 
3445   class ConstRowReference : public macros_internal::AbstractConstRowReference<
3446     HeapGraphClassTable, RowNumber> {
3447    public:
ConstRowReference(const HeapGraphClassTable * table,uint32_t row_number)3448     ConstRowReference(const HeapGraphClassTable* table, uint32_t row_number)
3449         : AbstractConstRowReference(table, row_number) {}
3450 
id()3451     ColumnType::id::type id() const {
3452       return table()->id()[row_number_];
3453     }
type()3454     ColumnType::type::type type() const {
3455       return table()->type()[row_number_];
3456     }
name()3457     ColumnType::name::type name() const {
3458       return table()->name()[row_number_];
3459     }
deobfuscated_name()3460     ColumnType::deobfuscated_name::type deobfuscated_name() const {
3461       return table()->deobfuscated_name()[row_number_];
3462     }
location()3463     ColumnType::location::type location() const {
3464       return table()->location()[row_number_];
3465     }
superclass_id()3466     ColumnType::superclass_id::type superclass_id() const {
3467       return table()->superclass_id()[row_number_];
3468     }
classloader_id()3469     ColumnType::classloader_id::type classloader_id() const {
3470       return table()->classloader_id()[row_number_];
3471     }
kind()3472     ColumnType::kind::type kind() const {
3473       return table()->kind()[row_number_];
3474     }
3475   };
3476   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
3477                 "Inheritance used without trivial destruction");
3478   class RowReference : public ConstRowReference {
3479    public:
RowReference(const HeapGraphClassTable * table,uint32_t row_number)3480     RowReference(const HeapGraphClassTable* table, uint32_t row_number)
3481         : ConstRowReference(table, row_number) {}
3482 
set_name(ColumnType::name::non_optional_type v)3483     void set_name(
3484         ColumnType::name::non_optional_type v) {
3485       return mutable_table()->mutable_name()->Set(row_number_, v);
3486     }
set_deobfuscated_name(ColumnType::deobfuscated_name::non_optional_type v)3487     void set_deobfuscated_name(
3488         ColumnType::deobfuscated_name::non_optional_type v) {
3489       return mutable_table()->mutable_deobfuscated_name()->Set(row_number_, v);
3490     }
set_location(ColumnType::location::non_optional_type v)3491     void set_location(
3492         ColumnType::location::non_optional_type v) {
3493       return mutable_table()->mutable_location()->Set(row_number_, v);
3494     }
set_superclass_id(ColumnType::superclass_id::non_optional_type v)3495     void set_superclass_id(
3496         ColumnType::superclass_id::non_optional_type v) {
3497       return mutable_table()->mutable_superclass_id()->Set(row_number_, v);
3498     }
set_classloader_id(ColumnType::classloader_id::non_optional_type v)3499     void set_classloader_id(
3500         ColumnType::classloader_id::non_optional_type v) {
3501       return mutable_table()->mutable_classloader_id()->Set(row_number_, v);
3502     }
set_kind(ColumnType::kind::non_optional_type v)3503     void set_kind(
3504         ColumnType::kind::non_optional_type v) {
3505       return mutable_table()->mutable_kind()->Set(row_number_, v);
3506     }
3507 
3508    private:
mutable_table()3509     HeapGraphClassTable* mutable_table() const {
3510       return const_cast<HeapGraphClassTable*>(table());
3511     }
3512   };
3513   static_assert(std::is_trivially_destructible_v<RowReference>,
3514                 "Inheritance used without trivial destruction");
3515 
3516   class ConstIterator;
3517   class ConstIterator : public macros_internal::AbstractConstIterator<
3518     ConstIterator, HeapGraphClassTable, RowNumber, ConstRowReference> {
3519    public:
id()3520     ColumnType::id::type id() const {
3521       const auto& col = table()->id();
3522       return col.GetAtIdx(
3523         iterator_.StorageIndexForColumn(col.index_in_table()));
3524     }
type()3525     ColumnType::type::type type() const {
3526       const auto& col = table()->type();
3527       return col.GetAtIdx(
3528         iterator_.StorageIndexForColumn(col.index_in_table()));
3529     }
name()3530     ColumnType::name::type name() const {
3531       const auto& col = table()->name();
3532       return col.GetAtIdx(
3533         iterator_.StorageIndexForColumn(col.index_in_table()));
3534     }
deobfuscated_name()3535     ColumnType::deobfuscated_name::type deobfuscated_name() const {
3536       const auto& col = table()->deobfuscated_name();
3537       return col.GetAtIdx(
3538         iterator_.StorageIndexForColumn(col.index_in_table()));
3539     }
location()3540     ColumnType::location::type location() const {
3541       const auto& col = table()->location();
3542       return col.GetAtIdx(
3543         iterator_.StorageIndexForColumn(col.index_in_table()));
3544     }
superclass_id()3545     ColumnType::superclass_id::type superclass_id() const {
3546       const auto& col = table()->superclass_id();
3547       return col.GetAtIdx(
3548         iterator_.StorageIndexForColumn(col.index_in_table()));
3549     }
classloader_id()3550     ColumnType::classloader_id::type classloader_id() const {
3551       const auto& col = table()->classloader_id();
3552       return col.GetAtIdx(
3553         iterator_.StorageIndexForColumn(col.index_in_table()));
3554     }
kind()3555     ColumnType::kind::type kind() const {
3556       const auto& col = table()->kind();
3557       return col.GetAtIdx(
3558         iterator_.StorageIndexForColumn(col.index_in_table()));
3559     }
3560 
3561    protected:
ConstIterator(const HeapGraphClassTable * table,Table::Iterator iterator)3562     explicit ConstIterator(const HeapGraphClassTable* table,
3563                            Table::Iterator iterator)
3564         : AbstractConstIterator(table, std::move(iterator)) {}
3565 
CurrentRowNumber()3566     uint32_t CurrentRowNumber() const {
3567       return iterator_.StorageIndexForLastOverlay();
3568     }
3569 
3570    private:
3571     friend class HeapGraphClassTable;
3572     friend class macros_internal::AbstractConstIterator<
3573       ConstIterator, HeapGraphClassTable, RowNumber, ConstRowReference>;
3574   };
3575   class Iterator : public ConstIterator {
3576     public:
row_reference()3577      RowReference row_reference() const {
3578        return {const_cast<HeapGraphClassTable*>(table()), CurrentRowNumber()};
3579      }
3580 
3581     private:
3582      friend class HeapGraphClassTable;
3583 
Iterator(HeapGraphClassTable * table,Table::Iterator iterator)3584      explicit Iterator(HeapGraphClassTable* table, Table::Iterator iterator)
3585         : ConstIterator(table, std::move(iterator)) {}
3586   };
3587 
3588   struct IdAndRow {
3589     Id id;
3590     uint32_t row;
3591     RowReference row_reference;
3592     RowNumber row_number;
3593   };
3594 
GetColumns(HeapGraphClassTable * self,const macros_internal::MacroTable * parent)3595   static std::vector<ColumnLegacy> GetColumns(
3596       HeapGraphClassTable* self,
3597       const macros_internal::MacroTable* parent) {
3598     std::vector<ColumnLegacy> columns =
3599         CopyColumnsFromParentOrAddRootColumns(self, parent);
3600     uint32_t olay_idx = OverlayCount(parent);
3601     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
3602                       static_cast<uint32_t>(columns.size()), olay_idx);
3603     AddColumnToVector(columns, "deobfuscated_name", &self->deobfuscated_name_, ColumnFlag::deobfuscated_name,
3604                       static_cast<uint32_t>(columns.size()), olay_idx);
3605     AddColumnToVector(columns, "location", &self->location_, ColumnFlag::location,
3606                       static_cast<uint32_t>(columns.size()), olay_idx);
3607     AddColumnToVector(columns, "superclass_id", &self->superclass_id_, ColumnFlag::superclass_id,
3608                       static_cast<uint32_t>(columns.size()), olay_idx);
3609     AddColumnToVector(columns, "classloader_id", &self->classloader_id_, ColumnFlag::classloader_id,
3610                       static_cast<uint32_t>(columns.size()), olay_idx);
3611     AddColumnToVector(columns, "kind", &self->kind_, ColumnFlag::kind,
3612                       static_cast<uint32_t>(columns.size()), olay_idx);
3613     return columns;
3614   }
3615 
HeapGraphClassTable(StringPool * pool)3616   PERFETTO_NO_INLINE explicit HeapGraphClassTable(StringPool* pool)
3617       : macros_internal::MacroTable(
3618           pool,
3619           GetColumns(this, nullptr),
3620           nullptr),
3621         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>()),
3622         deobfuscated_name_(ColumnStorage<ColumnType::deobfuscated_name::stored_type>::Create<false>()),
3623         location_(ColumnStorage<ColumnType::location::stored_type>::Create<false>()),
3624         superclass_id_(ColumnStorage<ColumnType::superclass_id::stored_type>::Create<false>()),
3625         classloader_id_(ColumnStorage<ColumnType::classloader_id::stored_type>::Create<false>()),
3626         kind_(ColumnStorage<ColumnType::kind::stored_type>::Create<false>())
3627 ,
3628         id_storage_layer_(new column::IdStorage()),
3629         type_storage_layer_(
3630           new column::StringStorage(string_pool(), &type_.vector())),
3631         name_storage_layer_(
3632           new column::StringStorage(string_pool(), &name_.vector())),
3633         deobfuscated_name_storage_layer_(
3634           new column::StringStorage(string_pool(), &deobfuscated_name_.vector())),
3635         location_storage_layer_(
3636           new column::StringStorage(string_pool(), &location_.vector())),
3637         superclass_id_storage_layer_(
3638           new column::NumericStorage<ColumnType::superclass_id::non_optional_stored_type>(
3639             &superclass_id_.non_null_vector(),
3640             ColumnTypeHelper<ColumnType::superclass_id::stored_type>::ToColumnType(),
3641             false)),
3642         classloader_id_storage_layer_(
3643           new column::NumericStorage<ColumnType::classloader_id::non_optional_stored_type>(
3644             &classloader_id_.non_null_vector(),
3645             ColumnTypeHelper<ColumnType::classloader_id::stored_type>::ToColumnType(),
3646             false)),
3647         kind_storage_layer_(
3648           new column::StringStorage(string_pool(), &kind_.vector()))
3649 ,
3650         superclass_id_null_layer_(new column::NullOverlay(superclass_id_.bv())),
3651         classloader_id_null_layer_(new column::NullOverlay(classloader_id_.bv())) {
3652     static_assert(
3653         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
3654           ColumnFlag::name),
3655         "Column type and flag combination is not valid");
3656       static_assert(
3657         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::deobfuscated_name::stored_type>(
3658           ColumnFlag::deobfuscated_name),
3659         "Column type and flag combination is not valid");
3660       static_assert(
3661         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::location::stored_type>(
3662           ColumnFlag::location),
3663         "Column type and flag combination is not valid");
3664       static_assert(
3665         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::superclass_id::stored_type>(
3666           ColumnFlag::superclass_id),
3667         "Column type and flag combination is not valid");
3668       static_assert(
3669         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::classloader_id::stored_type>(
3670           ColumnFlag::classloader_id),
3671         "Column type and flag combination is not valid");
3672       static_assert(
3673         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::kind::stored_type>(
3674           ColumnFlag::kind),
3675         "Column type and flag combination is not valid");
3676     OnConstructionCompletedRegularConstructor(
3677       {id_storage_layer_,type_storage_layer_,name_storage_layer_,deobfuscated_name_storage_layer_,location_storage_layer_,superclass_id_storage_layer_,classloader_id_storage_layer_,kind_storage_layer_},
3678       {{},{},{},{},{},superclass_id_null_layer_,classloader_id_null_layer_,{}});
3679   }
3680   ~HeapGraphClassTable() override;
3681 
Name()3682   static const char* Name() { return "heap_graph_class"; }
3683 
ComputeStaticSchema()3684   static Table::Schema ComputeStaticSchema() {
3685     Table::Schema schema;
3686     schema.columns.emplace_back(Table::Schema::Column{
3687         "id", SqlValue::Type::kLong, true, true, false, false});
3688     schema.columns.emplace_back(Table::Schema::Column{
3689         "type", SqlValue::Type::kString, false, false, false, false});
3690     schema.columns.emplace_back(Table::Schema::Column{
3691         "name", ColumnType::name::SqlValueType(), false,
3692         false,
3693         false,
3694         false});
3695     schema.columns.emplace_back(Table::Schema::Column{
3696         "deobfuscated_name", ColumnType::deobfuscated_name::SqlValueType(), false,
3697         false,
3698         false,
3699         false});
3700     schema.columns.emplace_back(Table::Schema::Column{
3701         "location", ColumnType::location::SqlValueType(), false,
3702         false,
3703         false,
3704         false});
3705     schema.columns.emplace_back(Table::Schema::Column{
3706         "superclass_id", ColumnType::superclass_id::SqlValueType(), false,
3707         false,
3708         false,
3709         false});
3710     schema.columns.emplace_back(Table::Schema::Column{
3711         "classloader_id", ColumnType::classloader_id::SqlValueType(), false,
3712         false,
3713         false,
3714         false});
3715     schema.columns.emplace_back(Table::Schema::Column{
3716         "kind", ColumnType::kind::SqlValueType(), false,
3717         false,
3718         false,
3719         false});
3720     return schema;
3721   }
3722 
IterateRows()3723   ConstIterator IterateRows() const {
3724     return ConstIterator(this, Table::IterateRows());
3725   }
3726 
IterateRows()3727   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
3728 
FilterToIterator(const Query & q)3729   ConstIterator FilterToIterator(const Query& q) const {
3730     return ConstIterator(this, QueryToIterator(q));
3731   }
3732 
FilterToIterator(const Query & q)3733   Iterator FilterToIterator(const Query& q) {
3734     return Iterator(this, QueryToIterator(q));
3735   }
3736 
ShrinkToFit()3737   void ShrinkToFit() {
3738     type_.ShrinkToFit();
3739     name_.ShrinkToFit();
3740     deobfuscated_name_.ShrinkToFit();
3741     location_.ShrinkToFit();
3742     superclass_id_.ShrinkToFit();
3743     classloader_id_.ShrinkToFit();
3744     kind_.ShrinkToFit();
3745   }
3746 
3747   ConstRowReference operator[](uint32_t r) const {
3748     return ConstRowReference(this, r);
3749   }
3750   RowReference operator[](uint32_t r) { return RowReference(this, r); }
3751   ConstRowReference operator[](RowNumber r) const {
3752     return ConstRowReference(this, r.row_number());
3753   }
3754   RowReference operator[](RowNumber r) {
3755     return RowReference(this, r.row_number());
3756   }
3757 
FindById(Id find_id)3758   std::optional<ConstRowReference> FindById(Id find_id) const {
3759     std::optional<uint32_t> row = id().IndexOf(find_id);
3760     return row ? std::make_optional(ConstRowReference(this, *row))
3761                : std::nullopt;
3762   }
3763 
FindById(Id find_id)3764   std::optional<RowReference> FindById(Id find_id) {
3765     std::optional<uint32_t> row = id().IndexOf(find_id);
3766     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
3767   }
3768 
Insert(const Row & row)3769   IdAndRow Insert(const Row& row) {
3770     uint32_t row_number = row_count();
3771     Id id = Id{row_number};
3772     type_.Append(string_pool()->InternString(row.type()));
3773     mutable_name()->Append(row.name);
3774     mutable_deobfuscated_name()->Append(row.deobfuscated_name);
3775     mutable_location()->Append(row.location);
3776     mutable_superclass_id()->Append(row.superclass_id);
3777     mutable_classloader_id()->Append(row.classloader_id);
3778     mutable_kind()->Append(row.kind);
3779     UpdateSelfOverlayAfterInsert();
3780     return IdAndRow{id, row_number, RowReference(this, row_number),
3781                      RowNumber(row_number)};
3782   }
3783 
3784 
3785 
id()3786   const IdColumn<HeapGraphClassTable::Id>& id() const {
3787     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
3788   }
type()3789   const TypedColumn<StringPool::Id>& type() const {
3790     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
3791   }
name()3792   const TypedColumn<StringPool::Id>& name() const {
3793     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
3794   }
deobfuscated_name()3795   const TypedColumn<std::optional<StringPool::Id>>& deobfuscated_name() const {
3796     return static_cast<const ColumnType::deobfuscated_name&>(columns()[ColumnIndex::deobfuscated_name]);
3797   }
location()3798   const TypedColumn<std::optional<StringPool::Id>>& location() const {
3799     return static_cast<const ColumnType::location&>(columns()[ColumnIndex::location]);
3800   }
superclass_id()3801   const TypedColumn<std::optional<HeapGraphClassTable::Id>>& superclass_id() const {
3802     return static_cast<const ColumnType::superclass_id&>(columns()[ColumnIndex::superclass_id]);
3803   }
classloader_id()3804   const TypedColumn<std::optional<uint32_t>>& classloader_id() const {
3805     return static_cast<const ColumnType::classloader_id&>(columns()[ColumnIndex::classloader_id]);
3806   }
kind()3807   const TypedColumn<StringPool::Id>& kind() const {
3808     return static_cast<const ColumnType::kind&>(columns()[ColumnIndex::kind]);
3809   }
3810 
mutable_name()3811   TypedColumn<StringPool::Id>* mutable_name() {
3812     return static_cast<ColumnType::name*>(
3813         GetColumn(ColumnIndex::name));
3814   }
mutable_deobfuscated_name()3815   TypedColumn<std::optional<StringPool::Id>>* mutable_deobfuscated_name() {
3816     return static_cast<ColumnType::deobfuscated_name*>(
3817         GetColumn(ColumnIndex::deobfuscated_name));
3818   }
mutable_location()3819   TypedColumn<std::optional<StringPool::Id>>* mutable_location() {
3820     return static_cast<ColumnType::location*>(
3821         GetColumn(ColumnIndex::location));
3822   }
mutable_superclass_id()3823   TypedColumn<std::optional<HeapGraphClassTable::Id>>* mutable_superclass_id() {
3824     return static_cast<ColumnType::superclass_id*>(
3825         GetColumn(ColumnIndex::superclass_id));
3826   }
mutable_classloader_id()3827   TypedColumn<std::optional<uint32_t>>* mutable_classloader_id() {
3828     return static_cast<ColumnType::classloader_id*>(
3829         GetColumn(ColumnIndex::classloader_id));
3830   }
mutable_kind()3831   TypedColumn<StringPool::Id>* mutable_kind() {
3832     return static_cast<ColumnType::kind*>(
3833         GetColumn(ColumnIndex::kind));
3834   }
3835 
3836  private:
3837 
3838 
3839   ColumnStorage<ColumnType::name::stored_type> name_;
3840   ColumnStorage<ColumnType::deobfuscated_name::stored_type> deobfuscated_name_;
3841   ColumnStorage<ColumnType::location::stored_type> location_;
3842   ColumnStorage<ColumnType::superclass_id::stored_type> superclass_id_;
3843   ColumnStorage<ColumnType::classloader_id::stored_type> classloader_id_;
3844   ColumnStorage<ColumnType::kind::stored_type> kind_;
3845 
3846   RefPtr<column::StorageLayer> id_storage_layer_;
3847   RefPtr<column::StorageLayer> type_storage_layer_;
3848   RefPtr<column::StorageLayer> name_storage_layer_;
3849   RefPtr<column::StorageLayer> deobfuscated_name_storage_layer_;
3850   RefPtr<column::StorageLayer> location_storage_layer_;
3851   RefPtr<column::StorageLayer> superclass_id_storage_layer_;
3852   RefPtr<column::StorageLayer> classloader_id_storage_layer_;
3853   RefPtr<column::StorageLayer> kind_storage_layer_;
3854 
3855   RefPtr<column::OverlayLayer> superclass_id_null_layer_;
3856   RefPtr<column::OverlayLayer> classloader_id_null_layer_;
3857 };
3858 
3859 
3860 class HeapGraphObjectTable : public macros_internal::MacroTable {
3861  public:
3862   static constexpr uint32_t kColumnCount = 11;
3863 
3864   struct Id : public BaseId {
3865     Id() = default;
IdId3866     explicit constexpr Id(uint32_t v) : BaseId(v) {}
3867   };
3868   static_assert(std::is_trivially_destructible_v<Id>,
3869                 "Inheritance used without trivial destruction");
3870 
3871   struct ColumnIndex {
3872     static constexpr uint32_t id = 0;
3873     static constexpr uint32_t type = 1;
3874     static constexpr uint32_t upid = 2;
3875     static constexpr uint32_t graph_sample_ts = 3;
3876     static constexpr uint32_t self_size = 4;
3877     static constexpr uint32_t native_size = 5;
3878     static constexpr uint32_t reference_set_id = 6;
3879     static constexpr uint32_t reachable = 7;
3880     static constexpr uint32_t type_id = 8;
3881     static constexpr uint32_t root_type = 9;
3882     static constexpr uint32_t root_distance = 10;
3883   };
3884   struct ColumnType {
3885     using id = IdColumn<HeapGraphObjectTable::Id>;
3886     using type = TypedColumn<StringPool::Id>;
3887     using upid = TypedColumn<uint32_t>;
3888     using graph_sample_ts = TypedColumn<int64_t>;
3889     using self_size = TypedColumn<int64_t>;
3890     using native_size = TypedColumn<int64_t>;
3891     using reference_set_id = TypedColumn<std::optional<uint32_t>>;
3892     using reachable = TypedColumn<int32_t>;
3893     using type_id = TypedColumn<HeapGraphClassTable::Id>;
3894     using root_type = TypedColumn<std::optional<StringPool::Id>>;
3895     using root_distance = TypedColumn<int32_t>;
3896   };
3897   struct Row : public macros_internal::RootParentTable::Row {
3898     Row(uint32_t in_upid = {},
3899         int64_t in_graph_sample_ts = {},
3900         int64_t in_self_size = {},
3901         int64_t in_native_size = {},
3902         std::optional<uint32_t> in_reference_set_id = {},
3903         int32_t in_reachable = {},
3904         HeapGraphClassTable::Id in_type_id = {},
3905         std::optional<StringPool::Id> in_root_type = {},
3906         int32_t in_root_distance = {},
3907         std::nullptr_t = nullptr)
RowRow3908         : macros_internal::RootParentTable::Row(),
3909           upid(in_upid),
3910           graph_sample_ts(in_graph_sample_ts),
3911           self_size(in_self_size),
3912           native_size(in_native_size),
3913           reference_set_id(in_reference_set_id),
3914           reachable(in_reachable),
3915           type_id(in_type_id),
3916           root_type(in_root_type),
3917           root_distance(in_root_distance) {
3918       type_ = "heap_graph_object";
3919     }
3920     uint32_t upid;
3921     int64_t graph_sample_ts;
3922     int64_t self_size;
3923     int64_t native_size;
3924     std::optional<uint32_t> reference_set_id;
3925     int32_t reachable;
3926     HeapGraphClassTable::Id type_id;
3927     std::optional<StringPool::Id> root_type;
3928     int32_t root_distance;
3929 
3930     bool operator==(const HeapGraphObjectTable::Row& other) const {
3931       return type() == other.type() && ColumnType::upid::Equals(upid, other.upid) &&
3932        ColumnType::graph_sample_ts::Equals(graph_sample_ts, other.graph_sample_ts) &&
3933        ColumnType::self_size::Equals(self_size, other.self_size) &&
3934        ColumnType::native_size::Equals(native_size, other.native_size) &&
3935        ColumnType::reference_set_id::Equals(reference_set_id, other.reference_set_id) &&
3936        ColumnType::reachable::Equals(reachable, other.reachable) &&
3937        ColumnType::type_id::Equals(type_id, other.type_id) &&
3938        ColumnType::root_type::Equals(root_type, other.root_type) &&
3939        ColumnType::root_distance::Equals(root_distance, other.root_distance);
3940     }
3941   };
3942   struct ColumnFlag {
3943     static constexpr uint32_t upid = ColumnType::upid::default_flags();
3944     static constexpr uint32_t graph_sample_ts = ColumnType::graph_sample_ts::default_flags();
3945     static constexpr uint32_t self_size = ColumnType::self_size::default_flags();
3946     static constexpr uint32_t native_size = ColumnType::native_size::default_flags();
3947     static constexpr uint32_t reference_set_id = static_cast<uint32_t>(ColumnLegacy::Flag::kDense) | ColumnType::reference_set_id::default_flags();
3948     static constexpr uint32_t reachable = ColumnType::reachable::default_flags();
3949     static constexpr uint32_t type_id = ColumnType::type_id::default_flags();
3950     static constexpr uint32_t root_type = ColumnType::root_type::default_flags();
3951     static constexpr uint32_t root_distance = static_cast<uint32_t>(ColumnLegacy::Flag::kHidden) | ColumnType::root_distance::default_flags();
3952   };
3953 
3954   class RowNumber;
3955   class ConstRowReference;
3956   class RowReference;
3957 
3958   class RowNumber : public macros_internal::AbstractRowNumber<
3959       HeapGraphObjectTable, ConstRowReference, RowReference> {
3960    public:
RowNumber(uint32_t row_number)3961     explicit RowNumber(uint32_t row_number)
3962         : AbstractRowNumber(row_number) {}
3963   };
3964   static_assert(std::is_trivially_destructible_v<RowNumber>,
3965                 "Inheritance used without trivial destruction");
3966 
3967   class ConstRowReference : public macros_internal::AbstractConstRowReference<
3968     HeapGraphObjectTable, RowNumber> {
3969    public:
ConstRowReference(const HeapGraphObjectTable * table,uint32_t row_number)3970     ConstRowReference(const HeapGraphObjectTable* table, uint32_t row_number)
3971         : AbstractConstRowReference(table, row_number) {}
3972 
id()3973     ColumnType::id::type id() const {
3974       return table()->id()[row_number_];
3975     }
type()3976     ColumnType::type::type type() const {
3977       return table()->type()[row_number_];
3978     }
upid()3979     ColumnType::upid::type upid() const {
3980       return table()->upid()[row_number_];
3981     }
graph_sample_ts()3982     ColumnType::graph_sample_ts::type graph_sample_ts() const {
3983       return table()->graph_sample_ts()[row_number_];
3984     }
self_size()3985     ColumnType::self_size::type self_size() const {
3986       return table()->self_size()[row_number_];
3987     }
native_size()3988     ColumnType::native_size::type native_size() const {
3989       return table()->native_size()[row_number_];
3990     }
reference_set_id()3991     ColumnType::reference_set_id::type reference_set_id() const {
3992       return table()->reference_set_id()[row_number_];
3993     }
reachable()3994     ColumnType::reachable::type reachable() const {
3995       return table()->reachable()[row_number_];
3996     }
type_id()3997     ColumnType::type_id::type type_id() const {
3998       return table()->type_id()[row_number_];
3999     }
root_type()4000     ColumnType::root_type::type root_type() const {
4001       return table()->root_type()[row_number_];
4002     }
root_distance()4003     ColumnType::root_distance::type root_distance() const {
4004       return table()->root_distance()[row_number_];
4005     }
4006   };
4007   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
4008                 "Inheritance used without trivial destruction");
4009   class RowReference : public ConstRowReference {
4010    public:
RowReference(const HeapGraphObjectTable * table,uint32_t row_number)4011     RowReference(const HeapGraphObjectTable* table, uint32_t row_number)
4012         : ConstRowReference(table, row_number) {}
4013 
set_upid(ColumnType::upid::non_optional_type v)4014     void set_upid(
4015         ColumnType::upid::non_optional_type v) {
4016       return mutable_table()->mutable_upid()->Set(row_number_, v);
4017     }
set_graph_sample_ts(ColumnType::graph_sample_ts::non_optional_type v)4018     void set_graph_sample_ts(
4019         ColumnType::graph_sample_ts::non_optional_type v) {
4020       return mutable_table()->mutable_graph_sample_ts()->Set(row_number_, v);
4021     }
set_self_size(ColumnType::self_size::non_optional_type v)4022     void set_self_size(
4023         ColumnType::self_size::non_optional_type v) {
4024       return mutable_table()->mutable_self_size()->Set(row_number_, v);
4025     }
set_native_size(ColumnType::native_size::non_optional_type v)4026     void set_native_size(
4027         ColumnType::native_size::non_optional_type v) {
4028       return mutable_table()->mutable_native_size()->Set(row_number_, v);
4029     }
set_reference_set_id(ColumnType::reference_set_id::non_optional_type v)4030     void set_reference_set_id(
4031         ColumnType::reference_set_id::non_optional_type v) {
4032       return mutable_table()->mutable_reference_set_id()->Set(row_number_, v);
4033     }
set_reachable(ColumnType::reachable::non_optional_type v)4034     void set_reachable(
4035         ColumnType::reachable::non_optional_type v) {
4036       return mutable_table()->mutable_reachable()->Set(row_number_, v);
4037     }
set_type_id(ColumnType::type_id::non_optional_type v)4038     void set_type_id(
4039         ColumnType::type_id::non_optional_type v) {
4040       return mutable_table()->mutable_type_id()->Set(row_number_, v);
4041     }
set_root_type(ColumnType::root_type::non_optional_type v)4042     void set_root_type(
4043         ColumnType::root_type::non_optional_type v) {
4044       return mutable_table()->mutable_root_type()->Set(row_number_, v);
4045     }
set_root_distance(ColumnType::root_distance::non_optional_type v)4046     void set_root_distance(
4047         ColumnType::root_distance::non_optional_type v) {
4048       return mutable_table()->mutable_root_distance()->Set(row_number_, v);
4049     }
4050 
4051    private:
mutable_table()4052     HeapGraphObjectTable* mutable_table() const {
4053       return const_cast<HeapGraphObjectTable*>(table());
4054     }
4055   };
4056   static_assert(std::is_trivially_destructible_v<RowReference>,
4057                 "Inheritance used without trivial destruction");
4058 
4059   class ConstIterator;
4060   class ConstIterator : public macros_internal::AbstractConstIterator<
4061     ConstIterator, HeapGraphObjectTable, RowNumber, ConstRowReference> {
4062    public:
id()4063     ColumnType::id::type id() const {
4064       const auto& col = table()->id();
4065       return col.GetAtIdx(
4066         iterator_.StorageIndexForColumn(col.index_in_table()));
4067     }
type()4068     ColumnType::type::type type() const {
4069       const auto& col = table()->type();
4070       return col.GetAtIdx(
4071         iterator_.StorageIndexForColumn(col.index_in_table()));
4072     }
upid()4073     ColumnType::upid::type upid() const {
4074       const auto& col = table()->upid();
4075       return col.GetAtIdx(
4076         iterator_.StorageIndexForColumn(col.index_in_table()));
4077     }
graph_sample_ts()4078     ColumnType::graph_sample_ts::type graph_sample_ts() const {
4079       const auto& col = table()->graph_sample_ts();
4080       return col.GetAtIdx(
4081         iterator_.StorageIndexForColumn(col.index_in_table()));
4082     }
self_size()4083     ColumnType::self_size::type self_size() const {
4084       const auto& col = table()->self_size();
4085       return col.GetAtIdx(
4086         iterator_.StorageIndexForColumn(col.index_in_table()));
4087     }
native_size()4088     ColumnType::native_size::type native_size() const {
4089       const auto& col = table()->native_size();
4090       return col.GetAtIdx(
4091         iterator_.StorageIndexForColumn(col.index_in_table()));
4092     }
reference_set_id()4093     ColumnType::reference_set_id::type reference_set_id() const {
4094       const auto& col = table()->reference_set_id();
4095       return col.GetAtIdx(
4096         iterator_.StorageIndexForColumn(col.index_in_table()));
4097     }
reachable()4098     ColumnType::reachable::type reachable() const {
4099       const auto& col = table()->reachable();
4100       return col.GetAtIdx(
4101         iterator_.StorageIndexForColumn(col.index_in_table()));
4102     }
type_id()4103     ColumnType::type_id::type type_id() const {
4104       const auto& col = table()->type_id();
4105       return col.GetAtIdx(
4106         iterator_.StorageIndexForColumn(col.index_in_table()));
4107     }
root_type()4108     ColumnType::root_type::type root_type() const {
4109       const auto& col = table()->root_type();
4110       return col.GetAtIdx(
4111         iterator_.StorageIndexForColumn(col.index_in_table()));
4112     }
root_distance()4113     ColumnType::root_distance::type root_distance() const {
4114       const auto& col = table()->root_distance();
4115       return col.GetAtIdx(
4116         iterator_.StorageIndexForColumn(col.index_in_table()));
4117     }
4118 
4119    protected:
ConstIterator(const HeapGraphObjectTable * table,Table::Iterator iterator)4120     explicit ConstIterator(const HeapGraphObjectTable* table,
4121                            Table::Iterator iterator)
4122         : AbstractConstIterator(table, std::move(iterator)) {}
4123 
CurrentRowNumber()4124     uint32_t CurrentRowNumber() const {
4125       return iterator_.StorageIndexForLastOverlay();
4126     }
4127 
4128    private:
4129     friend class HeapGraphObjectTable;
4130     friend class macros_internal::AbstractConstIterator<
4131       ConstIterator, HeapGraphObjectTable, RowNumber, ConstRowReference>;
4132   };
4133   class Iterator : public ConstIterator {
4134     public:
row_reference()4135      RowReference row_reference() const {
4136        return {const_cast<HeapGraphObjectTable*>(table()), CurrentRowNumber()};
4137      }
4138 
4139     private:
4140      friend class HeapGraphObjectTable;
4141 
Iterator(HeapGraphObjectTable * table,Table::Iterator iterator)4142      explicit Iterator(HeapGraphObjectTable* table, Table::Iterator iterator)
4143         : ConstIterator(table, std::move(iterator)) {}
4144   };
4145 
4146   struct IdAndRow {
4147     Id id;
4148     uint32_t row;
4149     RowReference row_reference;
4150     RowNumber row_number;
4151   };
4152 
GetColumns(HeapGraphObjectTable * self,const macros_internal::MacroTable * parent)4153   static std::vector<ColumnLegacy> GetColumns(
4154       HeapGraphObjectTable* self,
4155       const macros_internal::MacroTable* parent) {
4156     std::vector<ColumnLegacy> columns =
4157         CopyColumnsFromParentOrAddRootColumns(self, parent);
4158     uint32_t olay_idx = OverlayCount(parent);
4159     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
4160                       static_cast<uint32_t>(columns.size()), olay_idx);
4161     AddColumnToVector(columns, "graph_sample_ts", &self->graph_sample_ts_, ColumnFlag::graph_sample_ts,
4162                       static_cast<uint32_t>(columns.size()), olay_idx);
4163     AddColumnToVector(columns, "self_size", &self->self_size_, ColumnFlag::self_size,
4164                       static_cast<uint32_t>(columns.size()), olay_idx);
4165     AddColumnToVector(columns, "native_size", &self->native_size_, ColumnFlag::native_size,
4166                       static_cast<uint32_t>(columns.size()), olay_idx);
4167     AddColumnToVector(columns, "reference_set_id", &self->reference_set_id_, ColumnFlag::reference_set_id,
4168                       static_cast<uint32_t>(columns.size()), olay_idx);
4169     AddColumnToVector(columns, "reachable", &self->reachable_, ColumnFlag::reachable,
4170                       static_cast<uint32_t>(columns.size()), olay_idx);
4171     AddColumnToVector(columns, "type_id", &self->type_id_, ColumnFlag::type_id,
4172                       static_cast<uint32_t>(columns.size()), olay_idx);
4173     AddColumnToVector(columns, "root_type", &self->root_type_, ColumnFlag::root_type,
4174                       static_cast<uint32_t>(columns.size()), olay_idx);
4175     AddColumnToVector(columns, "root_distance", &self->root_distance_, ColumnFlag::root_distance,
4176                       static_cast<uint32_t>(columns.size()), olay_idx);
4177     return columns;
4178   }
4179 
HeapGraphObjectTable(StringPool * pool)4180   PERFETTO_NO_INLINE explicit HeapGraphObjectTable(StringPool* pool)
4181       : macros_internal::MacroTable(
4182           pool,
4183           GetColumns(this, nullptr),
4184           nullptr),
4185         upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>()),
4186         graph_sample_ts_(ColumnStorage<ColumnType::graph_sample_ts::stored_type>::Create<false>()),
4187         self_size_(ColumnStorage<ColumnType::self_size::stored_type>::Create<false>()),
4188         native_size_(ColumnStorage<ColumnType::native_size::stored_type>::Create<false>()),
4189         reference_set_id_(ColumnStorage<ColumnType::reference_set_id::stored_type>::Create<true>()),
4190         reachable_(ColumnStorage<ColumnType::reachable::stored_type>::Create<false>()),
4191         type_id_(ColumnStorage<ColumnType::type_id::stored_type>::Create<false>()),
4192         root_type_(ColumnStorage<ColumnType::root_type::stored_type>::Create<false>()),
4193         root_distance_(ColumnStorage<ColumnType::root_distance::stored_type>::Create<false>())
4194 ,
4195         id_storage_layer_(new column::IdStorage()),
4196         type_storage_layer_(
4197           new column::StringStorage(string_pool(), &type_.vector())),
4198         upid_storage_layer_(
4199         new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
4200           &upid_.vector(),
4201           ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
4202           false)),
4203         graph_sample_ts_storage_layer_(
4204         new column::NumericStorage<ColumnType::graph_sample_ts::non_optional_stored_type>(
4205           &graph_sample_ts_.vector(),
4206           ColumnTypeHelper<ColumnType::graph_sample_ts::stored_type>::ToColumnType(),
4207           false)),
4208         self_size_storage_layer_(
4209         new column::NumericStorage<ColumnType::self_size::non_optional_stored_type>(
4210           &self_size_.vector(),
4211           ColumnTypeHelper<ColumnType::self_size::stored_type>::ToColumnType(),
4212           false)),
4213         native_size_storage_layer_(
4214         new column::NumericStorage<ColumnType::native_size::non_optional_stored_type>(
4215           &native_size_.vector(),
4216           ColumnTypeHelper<ColumnType::native_size::stored_type>::ToColumnType(),
4217           false)),
4218         reference_set_id_storage_layer_(
4219           new column::NumericStorage<ColumnType::reference_set_id::non_optional_stored_type>(
4220             &reference_set_id_.non_null_vector(),
4221             ColumnTypeHelper<ColumnType::reference_set_id::stored_type>::ToColumnType(),
4222             false)),
4223         reachable_storage_layer_(
4224         new column::NumericStorage<ColumnType::reachable::non_optional_stored_type>(
4225           &reachable_.vector(),
4226           ColumnTypeHelper<ColumnType::reachable::stored_type>::ToColumnType(),
4227           false)),
4228         type_id_storage_layer_(
4229         new column::NumericStorage<ColumnType::type_id::non_optional_stored_type>(
4230           &type_id_.vector(),
4231           ColumnTypeHelper<ColumnType::type_id::stored_type>::ToColumnType(),
4232           false)),
4233         root_type_storage_layer_(
4234           new column::StringStorage(string_pool(), &root_type_.vector())),
4235         root_distance_storage_layer_(
4236         new column::NumericStorage<ColumnType::root_distance::non_optional_stored_type>(
4237           &root_distance_.vector(),
4238           ColumnTypeHelper<ColumnType::root_distance::stored_type>::ToColumnType(),
4239           false))
4240 ,
4241         reference_set_id_null_layer_(new column::DenseNullOverlay(reference_set_id_.bv())) {
4242     static_assert(
4243         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
4244           ColumnFlag::upid),
4245         "Column type and flag combination is not valid");
4246       static_assert(
4247         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::graph_sample_ts::stored_type>(
4248           ColumnFlag::graph_sample_ts),
4249         "Column type and flag combination is not valid");
4250       static_assert(
4251         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::self_size::stored_type>(
4252           ColumnFlag::self_size),
4253         "Column type and flag combination is not valid");
4254       static_assert(
4255         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::native_size::stored_type>(
4256           ColumnFlag::native_size),
4257         "Column type and flag combination is not valid");
4258       static_assert(
4259         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::reference_set_id::stored_type>(
4260           ColumnFlag::reference_set_id),
4261         "Column type and flag combination is not valid");
4262       static_assert(
4263         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::reachable::stored_type>(
4264           ColumnFlag::reachable),
4265         "Column type and flag combination is not valid");
4266       static_assert(
4267         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::type_id::stored_type>(
4268           ColumnFlag::type_id),
4269         "Column type and flag combination is not valid");
4270       static_assert(
4271         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::root_type::stored_type>(
4272           ColumnFlag::root_type),
4273         "Column type and flag combination is not valid");
4274       static_assert(
4275         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::root_distance::stored_type>(
4276           ColumnFlag::root_distance),
4277         "Column type and flag combination is not valid");
4278     OnConstructionCompletedRegularConstructor(
4279       {id_storage_layer_,type_storage_layer_,upid_storage_layer_,graph_sample_ts_storage_layer_,self_size_storage_layer_,native_size_storage_layer_,reference_set_id_storage_layer_,reachable_storage_layer_,type_id_storage_layer_,root_type_storage_layer_,root_distance_storage_layer_},
4280       {{},{},{},{},{},{},reference_set_id_null_layer_,{},{},{},{}});
4281   }
4282   ~HeapGraphObjectTable() override;
4283 
Name()4284   static const char* Name() { return "heap_graph_object"; }
4285 
ComputeStaticSchema()4286   static Table::Schema ComputeStaticSchema() {
4287     Table::Schema schema;
4288     schema.columns.emplace_back(Table::Schema::Column{
4289         "id", SqlValue::Type::kLong, true, true, false, false});
4290     schema.columns.emplace_back(Table::Schema::Column{
4291         "type", SqlValue::Type::kString, false, false, false, false});
4292     schema.columns.emplace_back(Table::Schema::Column{
4293         "upid", ColumnType::upid::SqlValueType(), false,
4294         false,
4295         false,
4296         false});
4297     schema.columns.emplace_back(Table::Schema::Column{
4298         "graph_sample_ts", ColumnType::graph_sample_ts::SqlValueType(), false,
4299         false,
4300         false,
4301         false});
4302     schema.columns.emplace_back(Table::Schema::Column{
4303         "self_size", ColumnType::self_size::SqlValueType(), false,
4304         false,
4305         false,
4306         false});
4307     schema.columns.emplace_back(Table::Schema::Column{
4308         "native_size", ColumnType::native_size::SqlValueType(), false,
4309         false,
4310         false,
4311         false});
4312     schema.columns.emplace_back(Table::Schema::Column{
4313         "reference_set_id", ColumnType::reference_set_id::SqlValueType(), false,
4314         false,
4315         false,
4316         false});
4317     schema.columns.emplace_back(Table::Schema::Column{
4318         "reachable", ColumnType::reachable::SqlValueType(), false,
4319         false,
4320         false,
4321         false});
4322     schema.columns.emplace_back(Table::Schema::Column{
4323         "type_id", ColumnType::type_id::SqlValueType(), false,
4324         false,
4325         false,
4326         false});
4327     schema.columns.emplace_back(Table::Schema::Column{
4328         "root_type", ColumnType::root_type::SqlValueType(), false,
4329         false,
4330         false,
4331         false});
4332     schema.columns.emplace_back(Table::Schema::Column{
4333         "root_distance", ColumnType::root_distance::SqlValueType(), false,
4334         false,
4335         true,
4336         false});
4337     return schema;
4338   }
4339 
IterateRows()4340   ConstIterator IterateRows() const {
4341     return ConstIterator(this, Table::IterateRows());
4342   }
4343 
IterateRows()4344   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
4345 
FilterToIterator(const Query & q)4346   ConstIterator FilterToIterator(const Query& q) const {
4347     return ConstIterator(this, QueryToIterator(q));
4348   }
4349 
FilterToIterator(const Query & q)4350   Iterator FilterToIterator(const Query& q) {
4351     return Iterator(this, QueryToIterator(q));
4352   }
4353 
ShrinkToFit()4354   void ShrinkToFit() {
4355     type_.ShrinkToFit();
4356     upid_.ShrinkToFit();
4357     graph_sample_ts_.ShrinkToFit();
4358     self_size_.ShrinkToFit();
4359     native_size_.ShrinkToFit();
4360     reference_set_id_.ShrinkToFit();
4361     reachable_.ShrinkToFit();
4362     type_id_.ShrinkToFit();
4363     root_type_.ShrinkToFit();
4364     root_distance_.ShrinkToFit();
4365   }
4366 
4367   ConstRowReference operator[](uint32_t r) const {
4368     return ConstRowReference(this, r);
4369   }
4370   RowReference operator[](uint32_t r) { return RowReference(this, r); }
4371   ConstRowReference operator[](RowNumber r) const {
4372     return ConstRowReference(this, r.row_number());
4373   }
4374   RowReference operator[](RowNumber r) {
4375     return RowReference(this, r.row_number());
4376   }
4377 
FindById(Id find_id)4378   std::optional<ConstRowReference> FindById(Id find_id) const {
4379     std::optional<uint32_t> row = id().IndexOf(find_id);
4380     return row ? std::make_optional(ConstRowReference(this, *row))
4381                : std::nullopt;
4382   }
4383 
FindById(Id find_id)4384   std::optional<RowReference> FindById(Id find_id) {
4385     std::optional<uint32_t> row = id().IndexOf(find_id);
4386     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
4387   }
4388 
Insert(const Row & row)4389   IdAndRow Insert(const Row& row) {
4390     uint32_t row_number = row_count();
4391     Id id = Id{row_number};
4392     type_.Append(string_pool()->InternString(row.type()));
4393     mutable_upid()->Append(row.upid);
4394     mutable_graph_sample_ts()->Append(row.graph_sample_ts);
4395     mutable_self_size()->Append(row.self_size);
4396     mutable_native_size()->Append(row.native_size);
4397     mutable_reference_set_id()->Append(row.reference_set_id);
4398     mutable_reachable()->Append(row.reachable);
4399     mutable_type_id()->Append(row.type_id);
4400     mutable_root_type()->Append(row.root_type);
4401     mutable_root_distance()->Append(row.root_distance);
4402     UpdateSelfOverlayAfterInsert();
4403     return IdAndRow{id, row_number, RowReference(this, row_number),
4404                      RowNumber(row_number)};
4405   }
4406 
4407 
4408 
id()4409   const IdColumn<HeapGraphObjectTable::Id>& id() const {
4410     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
4411   }
type()4412   const TypedColumn<StringPool::Id>& type() const {
4413     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
4414   }
upid()4415   const TypedColumn<uint32_t>& upid() const {
4416     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
4417   }
graph_sample_ts()4418   const TypedColumn<int64_t>& graph_sample_ts() const {
4419     return static_cast<const ColumnType::graph_sample_ts&>(columns()[ColumnIndex::graph_sample_ts]);
4420   }
self_size()4421   const TypedColumn<int64_t>& self_size() const {
4422     return static_cast<const ColumnType::self_size&>(columns()[ColumnIndex::self_size]);
4423   }
native_size()4424   const TypedColumn<int64_t>& native_size() const {
4425     return static_cast<const ColumnType::native_size&>(columns()[ColumnIndex::native_size]);
4426   }
reference_set_id()4427   const TypedColumn<std::optional<uint32_t>>& reference_set_id() const {
4428     return static_cast<const ColumnType::reference_set_id&>(columns()[ColumnIndex::reference_set_id]);
4429   }
reachable()4430   const TypedColumn<int32_t>& reachable() const {
4431     return static_cast<const ColumnType::reachable&>(columns()[ColumnIndex::reachable]);
4432   }
type_id()4433   const TypedColumn<HeapGraphClassTable::Id>& type_id() const {
4434     return static_cast<const ColumnType::type_id&>(columns()[ColumnIndex::type_id]);
4435   }
root_type()4436   const TypedColumn<std::optional<StringPool::Id>>& root_type() const {
4437     return static_cast<const ColumnType::root_type&>(columns()[ColumnIndex::root_type]);
4438   }
root_distance()4439   const TypedColumn<int32_t>& root_distance() const {
4440     return static_cast<const ColumnType::root_distance&>(columns()[ColumnIndex::root_distance]);
4441   }
4442 
mutable_upid()4443   TypedColumn<uint32_t>* mutable_upid() {
4444     return static_cast<ColumnType::upid*>(
4445         GetColumn(ColumnIndex::upid));
4446   }
mutable_graph_sample_ts()4447   TypedColumn<int64_t>* mutable_graph_sample_ts() {
4448     return static_cast<ColumnType::graph_sample_ts*>(
4449         GetColumn(ColumnIndex::graph_sample_ts));
4450   }
mutable_self_size()4451   TypedColumn<int64_t>* mutable_self_size() {
4452     return static_cast<ColumnType::self_size*>(
4453         GetColumn(ColumnIndex::self_size));
4454   }
mutable_native_size()4455   TypedColumn<int64_t>* mutable_native_size() {
4456     return static_cast<ColumnType::native_size*>(
4457         GetColumn(ColumnIndex::native_size));
4458   }
mutable_reference_set_id()4459   TypedColumn<std::optional<uint32_t>>* mutable_reference_set_id() {
4460     return static_cast<ColumnType::reference_set_id*>(
4461         GetColumn(ColumnIndex::reference_set_id));
4462   }
mutable_reachable()4463   TypedColumn<int32_t>* mutable_reachable() {
4464     return static_cast<ColumnType::reachable*>(
4465         GetColumn(ColumnIndex::reachable));
4466   }
mutable_type_id()4467   TypedColumn<HeapGraphClassTable::Id>* mutable_type_id() {
4468     return static_cast<ColumnType::type_id*>(
4469         GetColumn(ColumnIndex::type_id));
4470   }
mutable_root_type()4471   TypedColumn<std::optional<StringPool::Id>>* mutable_root_type() {
4472     return static_cast<ColumnType::root_type*>(
4473         GetColumn(ColumnIndex::root_type));
4474   }
mutable_root_distance()4475   TypedColumn<int32_t>* mutable_root_distance() {
4476     return static_cast<ColumnType::root_distance*>(
4477         GetColumn(ColumnIndex::root_distance));
4478   }
4479 
4480  private:
4481 
4482 
4483   ColumnStorage<ColumnType::upid::stored_type> upid_;
4484   ColumnStorage<ColumnType::graph_sample_ts::stored_type> graph_sample_ts_;
4485   ColumnStorage<ColumnType::self_size::stored_type> self_size_;
4486   ColumnStorage<ColumnType::native_size::stored_type> native_size_;
4487   ColumnStorage<ColumnType::reference_set_id::stored_type> reference_set_id_;
4488   ColumnStorage<ColumnType::reachable::stored_type> reachable_;
4489   ColumnStorage<ColumnType::type_id::stored_type> type_id_;
4490   ColumnStorage<ColumnType::root_type::stored_type> root_type_;
4491   ColumnStorage<ColumnType::root_distance::stored_type> root_distance_;
4492 
4493   RefPtr<column::StorageLayer> id_storage_layer_;
4494   RefPtr<column::StorageLayer> type_storage_layer_;
4495   RefPtr<column::StorageLayer> upid_storage_layer_;
4496   RefPtr<column::StorageLayer> graph_sample_ts_storage_layer_;
4497   RefPtr<column::StorageLayer> self_size_storage_layer_;
4498   RefPtr<column::StorageLayer> native_size_storage_layer_;
4499   RefPtr<column::StorageLayer> reference_set_id_storage_layer_;
4500   RefPtr<column::StorageLayer> reachable_storage_layer_;
4501   RefPtr<column::StorageLayer> type_id_storage_layer_;
4502   RefPtr<column::StorageLayer> root_type_storage_layer_;
4503   RefPtr<column::StorageLayer> root_distance_storage_layer_;
4504 
4505   RefPtr<column::OverlayLayer> reference_set_id_null_layer_;
4506 };
4507 
4508 
4509 class HeapGraphReferenceTable : public macros_internal::MacroTable {
4510  public:
4511   static constexpr uint32_t kColumnCount = 8;
4512 
4513   struct Id : public BaseId {
4514     Id() = default;
IdId4515     explicit constexpr Id(uint32_t v) : BaseId(v) {}
4516   };
4517   static_assert(std::is_trivially_destructible_v<Id>,
4518                 "Inheritance used without trivial destruction");
4519 
4520   struct ColumnIndex {
4521     static constexpr uint32_t id = 0;
4522     static constexpr uint32_t type = 1;
4523     static constexpr uint32_t reference_set_id = 2;
4524     static constexpr uint32_t owner_id = 3;
4525     static constexpr uint32_t owned_id = 4;
4526     static constexpr uint32_t field_name = 5;
4527     static constexpr uint32_t field_type_name = 6;
4528     static constexpr uint32_t deobfuscated_field_name = 7;
4529   };
4530   struct ColumnType {
4531     using id = IdColumn<HeapGraphReferenceTable::Id>;
4532     using type = TypedColumn<StringPool::Id>;
4533     using reference_set_id = TypedColumn<uint32_t>;
4534     using owner_id = TypedColumn<HeapGraphObjectTable::Id>;
4535     using owned_id = TypedColumn<std::optional<HeapGraphObjectTable::Id>>;
4536     using field_name = TypedColumn<StringPool::Id>;
4537     using field_type_name = TypedColumn<StringPool::Id>;
4538     using deobfuscated_field_name = TypedColumn<std::optional<StringPool::Id>>;
4539   };
4540   struct Row : public macros_internal::RootParentTable::Row {
4541     Row(uint32_t in_reference_set_id = {},
4542         HeapGraphObjectTable::Id in_owner_id = {},
4543         std::optional<HeapGraphObjectTable::Id> in_owned_id = {},
4544         StringPool::Id in_field_name = {},
4545         StringPool::Id in_field_type_name = {},
4546         std::optional<StringPool::Id> in_deobfuscated_field_name = {},
4547         std::nullptr_t = nullptr)
RowRow4548         : macros_internal::RootParentTable::Row(),
4549           reference_set_id(in_reference_set_id),
4550           owner_id(in_owner_id),
4551           owned_id(in_owned_id),
4552           field_name(in_field_name),
4553           field_type_name(in_field_type_name),
4554           deobfuscated_field_name(in_deobfuscated_field_name) {
4555       type_ = "heap_graph_reference";
4556     }
4557     uint32_t reference_set_id;
4558     HeapGraphObjectTable::Id owner_id;
4559     std::optional<HeapGraphObjectTable::Id> owned_id;
4560     StringPool::Id field_name;
4561     StringPool::Id field_type_name;
4562     std::optional<StringPool::Id> deobfuscated_field_name;
4563 
4564     bool operator==(const HeapGraphReferenceTable::Row& other) const {
4565       return type() == other.type() && ColumnType::reference_set_id::Equals(reference_set_id, other.reference_set_id) &&
4566        ColumnType::owner_id::Equals(owner_id, other.owner_id) &&
4567        ColumnType::owned_id::Equals(owned_id, other.owned_id) &&
4568        ColumnType::field_name::Equals(field_name, other.field_name) &&
4569        ColumnType::field_type_name::Equals(field_type_name, other.field_type_name) &&
4570        ColumnType::deobfuscated_field_name::Equals(deobfuscated_field_name, other.deobfuscated_field_name);
4571     }
4572   };
4573   struct ColumnFlag {
4574     static constexpr uint32_t reference_set_id = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted | ColumnLegacy::Flag::kSetId) | ColumnType::reference_set_id::default_flags();
4575     static constexpr uint32_t owner_id = ColumnType::owner_id::default_flags();
4576     static constexpr uint32_t owned_id = ColumnType::owned_id::default_flags();
4577     static constexpr uint32_t field_name = ColumnType::field_name::default_flags();
4578     static constexpr uint32_t field_type_name = ColumnType::field_type_name::default_flags();
4579     static constexpr uint32_t deobfuscated_field_name = ColumnType::deobfuscated_field_name::default_flags();
4580   };
4581 
4582   class RowNumber;
4583   class ConstRowReference;
4584   class RowReference;
4585 
4586   class RowNumber : public macros_internal::AbstractRowNumber<
4587       HeapGraphReferenceTable, ConstRowReference, RowReference> {
4588    public:
RowNumber(uint32_t row_number)4589     explicit RowNumber(uint32_t row_number)
4590         : AbstractRowNumber(row_number) {}
4591   };
4592   static_assert(std::is_trivially_destructible_v<RowNumber>,
4593                 "Inheritance used without trivial destruction");
4594 
4595   class ConstRowReference : public macros_internal::AbstractConstRowReference<
4596     HeapGraphReferenceTable, RowNumber> {
4597    public:
ConstRowReference(const HeapGraphReferenceTable * table,uint32_t row_number)4598     ConstRowReference(const HeapGraphReferenceTable* table, uint32_t row_number)
4599         : AbstractConstRowReference(table, row_number) {}
4600 
id()4601     ColumnType::id::type id() const {
4602       return table()->id()[row_number_];
4603     }
type()4604     ColumnType::type::type type() const {
4605       return table()->type()[row_number_];
4606     }
reference_set_id()4607     ColumnType::reference_set_id::type reference_set_id() const {
4608       return table()->reference_set_id()[row_number_];
4609     }
owner_id()4610     ColumnType::owner_id::type owner_id() const {
4611       return table()->owner_id()[row_number_];
4612     }
owned_id()4613     ColumnType::owned_id::type owned_id() const {
4614       return table()->owned_id()[row_number_];
4615     }
field_name()4616     ColumnType::field_name::type field_name() const {
4617       return table()->field_name()[row_number_];
4618     }
field_type_name()4619     ColumnType::field_type_name::type field_type_name() const {
4620       return table()->field_type_name()[row_number_];
4621     }
deobfuscated_field_name()4622     ColumnType::deobfuscated_field_name::type deobfuscated_field_name() const {
4623       return table()->deobfuscated_field_name()[row_number_];
4624     }
4625   };
4626   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
4627                 "Inheritance used without trivial destruction");
4628   class RowReference : public ConstRowReference {
4629    public:
RowReference(const HeapGraphReferenceTable * table,uint32_t row_number)4630     RowReference(const HeapGraphReferenceTable* table, uint32_t row_number)
4631         : ConstRowReference(table, row_number) {}
4632 
set_reference_set_id(ColumnType::reference_set_id::non_optional_type v)4633     void set_reference_set_id(
4634         ColumnType::reference_set_id::non_optional_type v) {
4635       return mutable_table()->mutable_reference_set_id()->Set(row_number_, v);
4636     }
set_owner_id(ColumnType::owner_id::non_optional_type v)4637     void set_owner_id(
4638         ColumnType::owner_id::non_optional_type v) {
4639       return mutable_table()->mutable_owner_id()->Set(row_number_, v);
4640     }
set_owned_id(ColumnType::owned_id::non_optional_type v)4641     void set_owned_id(
4642         ColumnType::owned_id::non_optional_type v) {
4643       return mutable_table()->mutable_owned_id()->Set(row_number_, v);
4644     }
set_field_name(ColumnType::field_name::non_optional_type v)4645     void set_field_name(
4646         ColumnType::field_name::non_optional_type v) {
4647       return mutable_table()->mutable_field_name()->Set(row_number_, v);
4648     }
set_field_type_name(ColumnType::field_type_name::non_optional_type v)4649     void set_field_type_name(
4650         ColumnType::field_type_name::non_optional_type v) {
4651       return mutable_table()->mutable_field_type_name()->Set(row_number_, v);
4652     }
set_deobfuscated_field_name(ColumnType::deobfuscated_field_name::non_optional_type v)4653     void set_deobfuscated_field_name(
4654         ColumnType::deobfuscated_field_name::non_optional_type v) {
4655       return mutable_table()->mutable_deobfuscated_field_name()->Set(row_number_, v);
4656     }
4657 
4658    private:
mutable_table()4659     HeapGraphReferenceTable* mutable_table() const {
4660       return const_cast<HeapGraphReferenceTable*>(table());
4661     }
4662   };
4663   static_assert(std::is_trivially_destructible_v<RowReference>,
4664                 "Inheritance used without trivial destruction");
4665 
4666   class ConstIterator;
4667   class ConstIterator : public macros_internal::AbstractConstIterator<
4668     ConstIterator, HeapGraphReferenceTable, RowNumber, ConstRowReference> {
4669    public:
id()4670     ColumnType::id::type id() const {
4671       const auto& col = table()->id();
4672       return col.GetAtIdx(
4673         iterator_.StorageIndexForColumn(col.index_in_table()));
4674     }
type()4675     ColumnType::type::type type() const {
4676       const auto& col = table()->type();
4677       return col.GetAtIdx(
4678         iterator_.StorageIndexForColumn(col.index_in_table()));
4679     }
reference_set_id()4680     ColumnType::reference_set_id::type reference_set_id() const {
4681       const auto& col = table()->reference_set_id();
4682       return col.GetAtIdx(
4683         iterator_.StorageIndexForColumn(col.index_in_table()));
4684     }
owner_id()4685     ColumnType::owner_id::type owner_id() const {
4686       const auto& col = table()->owner_id();
4687       return col.GetAtIdx(
4688         iterator_.StorageIndexForColumn(col.index_in_table()));
4689     }
owned_id()4690     ColumnType::owned_id::type owned_id() const {
4691       const auto& col = table()->owned_id();
4692       return col.GetAtIdx(
4693         iterator_.StorageIndexForColumn(col.index_in_table()));
4694     }
field_name()4695     ColumnType::field_name::type field_name() const {
4696       const auto& col = table()->field_name();
4697       return col.GetAtIdx(
4698         iterator_.StorageIndexForColumn(col.index_in_table()));
4699     }
field_type_name()4700     ColumnType::field_type_name::type field_type_name() const {
4701       const auto& col = table()->field_type_name();
4702       return col.GetAtIdx(
4703         iterator_.StorageIndexForColumn(col.index_in_table()));
4704     }
deobfuscated_field_name()4705     ColumnType::deobfuscated_field_name::type deobfuscated_field_name() const {
4706       const auto& col = table()->deobfuscated_field_name();
4707       return col.GetAtIdx(
4708         iterator_.StorageIndexForColumn(col.index_in_table()));
4709     }
4710 
4711    protected:
ConstIterator(const HeapGraphReferenceTable * table,Table::Iterator iterator)4712     explicit ConstIterator(const HeapGraphReferenceTable* table,
4713                            Table::Iterator iterator)
4714         : AbstractConstIterator(table, std::move(iterator)) {}
4715 
CurrentRowNumber()4716     uint32_t CurrentRowNumber() const {
4717       return iterator_.StorageIndexForLastOverlay();
4718     }
4719 
4720    private:
4721     friend class HeapGraphReferenceTable;
4722     friend class macros_internal::AbstractConstIterator<
4723       ConstIterator, HeapGraphReferenceTable, RowNumber, ConstRowReference>;
4724   };
4725   class Iterator : public ConstIterator {
4726     public:
row_reference()4727      RowReference row_reference() const {
4728        return {const_cast<HeapGraphReferenceTable*>(table()), CurrentRowNumber()};
4729      }
4730 
4731     private:
4732      friend class HeapGraphReferenceTable;
4733 
Iterator(HeapGraphReferenceTable * table,Table::Iterator iterator)4734      explicit Iterator(HeapGraphReferenceTable* table, Table::Iterator iterator)
4735         : ConstIterator(table, std::move(iterator)) {}
4736   };
4737 
4738   struct IdAndRow {
4739     Id id;
4740     uint32_t row;
4741     RowReference row_reference;
4742     RowNumber row_number;
4743   };
4744 
GetColumns(HeapGraphReferenceTable * self,const macros_internal::MacroTable * parent)4745   static std::vector<ColumnLegacy> GetColumns(
4746       HeapGraphReferenceTable* self,
4747       const macros_internal::MacroTable* parent) {
4748     std::vector<ColumnLegacy> columns =
4749         CopyColumnsFromParentOrAddRootColumns(self, parent);
4750     uint32_t olay_idx = OverlayCount(parent);
4751     AddColumnToVector(columns, "reference_set_id", &self->reference_set_id_, ColumnFlag::reference_set_id,
4752                       static_cast<uint32_t>(columns.size()), olay_idx);
4753     AddColumnToVector(columns, "owner_id", &self->owner_id_, ColumnFlag::owner_id,
4754                       static_cast<uint32_t>(columns.size()), olay_idx);
4755     AddColumnToVector(columns, "owned_id", &self->owned_id_, ColumnFlag::owned_id,
4756                       static_cast<uint32_t>(columns.size()), olay_idx);
4757     AddColumnToVector(columns, "field_name", &self->field_name_, ColumnFlag::field_name,
4758                       static_cast<uint32_t>(columns.size()), olay_idx);
4759     AddColumnToVector(columns, "field_type_name", &self->field_type_name_, ColumnFlag::field_type_name,
4760                       static_cast<uint32_t>(columns.size()), olay_idx);
4761     AddColumnToVector(columns, "deobfuscated_field_name", &self->deobfuscated_field_name_, ColumnFlag::deobfuscated_field_name,
4762                       static_cast<uint32_t>(columns.size()), olay_idx);
4763     return columns;
4764   }
4765 
HeapGraphReferenceTable(StringPool * pool)4766   PERFETTO_NO_INLINE explicit HeapGraphReferenceTable(StringPool* pool)
4767       : macros_internal::MacroTable(
4768           pool,
4769           GetColumns(this, nullptr),
4770           nullptr),
4771         reference_set_id_(ColumnStorage<ColumnType::reference_set_id::stored_type>::Create<false>()),
4772         owner_id_(ColumnStorage<ColumnType::owner_id::stored_type>::Create<false>()),
4773         owned_id_(ColumnStorage<ColumnType::owned_id::stored_type>::Create<false>()),
4774         field_name_(ColumnStorage<ColumnType::field_name::stored_type>::Create<false>()),
4775         field_type_name_(ColumnStorage<ColumnType::field_type_name::stored_type>::Create<false>()),
4776         deobfuscated_field_name_(ColumnStorage<ColumnType::deobfuscated_field_name::stored_type>::Create<false>())
4777 ,
4778         id_storage_layer_(new column::IdStorage()),
4779         type_storage_layer_(
4780           new column::StringStorage(string_pool(), &type_.vector())),
4781         reference_set_id_storage_layer_(
4782           new column::SetIdStorage(&reference_set_id_.vector())),
4783         owner_id_storage_layer_(
4784         new column::NumericStorage<ColumnType::owner_id::non_optional_stored_type>(
4785           &owner_id_.vector(),
4786           ColumnTypeHelper<ColumnType::owner_id::stored_type>::ToColumnType(),
4787           false)),
4788         owned_id_storage_layer_(
4789           new column::NumericStorage<ColumnType::owned_id::non_optional_stored_type>(
4790             &owned_id_.non_null_vector(),
4791             ColumnTypeHelper<ColumnType::owned_id::stored_type>::ToColumnType(),
4792             false)),
4793         field_name_storage_layer_(
4794           new column::StringStorage(string_pool(), &field_name_.vector())),
4795         field_type_name_storage_layer_(
4796           new column::StringStorage(string_pool(), &field_type_name_.vector())),
4797         deobfuscated_field_name_storage_layer_(
4798           new column::StringStorage(string_pool(), &deobfuscated_field_name_.vector()))
4799 ,
4800         owned_id_null_layer_(new column::NullOverlay(owned_id_.bv())) {
4801     static_assert(
4802         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::reference_set_id::stored_type>(
4803           ColumnFlag::reference_set_id),
4804         "Column type and flag combination is not valid");
4805       static_assert(
4806         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::owner_id::stored_type>(
4807           ColumnFlag::owner_id),
4808         "Column type and flag combination is not valid");
4809       static_assert(
4810         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::owned_id::stored_type>(
4811           ColumnFlag::owned_id),
4812         "Column type and flag combination is not valid");
4813       static_assert(
4814         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::field_name::stored_type>(
4815           ColumnFlag::field_name),
4816         "Column type and flag combination is not valid");
4817       static_assert(
4818         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::field_type_name::stored_type>(
4819           ColumnFlag::field_type_name),
4820         "Column type and flag combination is not valid");
4821       static_assert(
4822         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::deobfuscated_field_name::stored_type>(
4823           ColumnFlag::deobfuscated_field_name),
4824         "Column type and flag combination is not valid");
4825     OnConstructionCompletedRegularConstructor(
4826       {id_storage_layer_,type_storage_layer_,reference_set_id_storage_layer_,owner_id_storage_layer_,owned_id_storage_layer_,field_name_storage_layer_,field_type_name_storage_layer_,deobfuscated_field_name_storage_layer_},
4827       {{},{},{},{},owned_id_null_layer_,{},{},{}});
4828   }
4829   ~HeapGraphReferenceTable() override;
4830 
Name()4831   static const char* Name() { return "heap_graph_reference"; }
4832 
ComputeStaticSchema()4833   static Table::Schema ComputeStaticSchema() {
4834     Table::Schema schema;
4835     schema.columns.emplace_back(Table::Schema::Column{
4836         "id", SqlValue::Type::kLong, true, true, false, false});
4837     schema.columns.emplace_back(Table::Schema::Column{
4838         "type", SqlValue::Type::kString, false, false, false, false});
4839     schema.columns.emplace_back(Table::Schema::Column{
4840         "reference_set_id", ColumnType::reference_set_id::SqlValueType(), false,
4841         true,
4842         false,
4843         true});
4844     schema.columns.emplace_back(Table::Schema::Column{
4845         "owner_id", ColumnType::owner_id::SqlValueType(), false,
4846         false,
4847         false,
4848         false});
4849     schema.columns.emplace_back(Table::Schema::Column{
4850         "owned_id", ColumnType::owned_id::SqlValueType(), false,
4851         false,
4852         false,
4853         false});
4854     schema.columns.emplace_back(Table::Schema::Column{
4855         "field_name", ColumnType::field_name::SqlValueType(), false,
4856         false,
4857         false,
4858         false});
4859     schema.columns.emplace_back(Table::Schema::Column{
4860         "field_type_name", ColumnType::field_type_name::SqlValueType(), false,
4861         false,
4862         false,
4863         false});
4864     schema.columns.emplace_back(Table::Schema::Column{
4865         "deobfuscated_field_name", ColumnType::deobfuscated_field_name::SqlValueType(), false,
4866         false,
4867         false,
4868         false});
4869     return schema;
4870   }
4871 
IterateRows()4872   ConstIterator IterateRows() const {
4873     return ConstIterator(this, Table::IterateRows());
4874   }
4875 
IterateRows()4876   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
4877 
FilterToIterator(const Query & q)4878   ConstIterator FilterToIterator(const Query& q) const {
4879     return ConstIterator(this, QueryToIterator(q));
4880   }
4881 
FilterToIterator(const Query & q)4882   Iterator FilterToIterator(const Query& q) {
4883     return Iterator(this, QueryToIterator(q));
4884   }
4885 
ShrinkToFit()4886   void ShrinkToFit() {
4887     type_.ShrinkToFit();
4888     reference_set_id_.ShrinkToFit();
4889     owner_id_.ShrinkToFit();
4890     owned_id_.ShrinkToFit();
4891     field_name_.ShrinkToFit();
4892     field_type_name_.ShrinkToFit();
4893     deobfuscated_field_name_.ShrinkToFit();
4894   }
4895 
4896   ConstRowReference operator[](uint32_t r) const {
4897     return ConstRowReference(this, r);
4898   }
4899   RowReference operator[](uint32_t r) { return RowReference(this, r); }
4900   ConstRowReference operator[](RowNumber r) const {
4901     return ConstRowReference(this, r.row_number());
4902   }
4903   RowReference operator[](RowNumber r) {
4904     return RowReference(this, r.row_number());
4905   }
4906 
FindById(Id find_id)4907   std::optional<ConstRowReference> FindById(Id find_id) const {
4908     std::optional<uint32_t> row = id().IndexOf(find_id);
4909     return row ? std::make_optional(ConstRowReference(this, *row))
4910                : std::nullopt;
4911   }
4912 
FindById(Id find_id)4913   std::optional<RowReference> FindById(Id find_id) {
4914     std::optional<uint32_t> row = id().IndexOf(find_id);
4915     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
4916   }
4917 
Insert(const Row & row)4918   IdAndRow Insert(const Row& row) {
4919     uint32_t row_number = row_count();
4920     Id id = Id{row_number};
4921     type_.Append(string_pool()->InternString(row.type()));
4922     mutable_reference_set_id()->Append(row.reference_set_id);
4923     mutable_owner_id()->Append(row.owner_id);
4924     mutable_owned_id()->Append(row.owned_id);
4925     mutable_field_name()->Append(row.field_name);
4926     mutable_field_type_name()->Append(row.field_type_name);
4927     mutable_deobfuscated_field_name()->Append(row.deobfuscated_field_name);
4928     UpdateSelfOverlayAfterInsert();
4929     return IdAndRow{id, row_number, RowReference(this, row_number),
4930                      RowNumber(row_number)};
4931   }
4932 
4933 
4934 
id()4935   const IdColumn<HeapGraphReferenceTable::Id>& id() const {
4936     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
4937   }
type()4938   const TypedColumn<StringPool::Id>& type() const {
4939     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
4940   }
reference_set_id()4941   const TypedColumn<uint32_t>& reference_set_id() const {
4942     return static_cast<const ColumnType::reference_set_id&>(columns()[ColumnIndex::reference_set_id]);
4943   }
owner_id()4944   const TypedColumn<HeapGraphObjectTable::Id>& owner_id() const {
4945     return static_cast<const ColumnType::owner_id&>(columns()[ColumnIndex::owner_id]);
4946   }
owned_id()4947   const TypedColumn<std::optional<HeapGraphObjectTable::Id>>& owned_id() const {
4948     return static_cast<const ColumnType::owned_id&>(columns()[ColumnIndex::owned_id]);
4949   }
field_name()4950   const TypedColumn<StringPool::Id>& field_name() const {
4951     return static_cast<const ColumnType::field_name&>(columns()[ColumnIndex::field_name]);
4952   }
field_type_name()4953   const TypedColumn<StringPool::Id>& field_type_name() const {
4954     return static_cast<const ColumnType::field_type_name&>(columns()[ColumnIndex::field_type_name]);
4955   }
deobfuscated_field_name()4956   const TypedColumn<std::optional<StringPool::Id>>& deobfuscated_field_name() const {
4957     return static_cast<const ColumnType::deobfuscated_field_name&>(columns()[ColumnIndex::deobfuscated_field_name]);
4958   }
4959 
mutable_reference_set_id()4960   TypedColumn<uint32_t>* mutable_reference_set_id() {
4961     return static_cast<ColumnType::reference_set_id*>(
4962         GetColumn(ColumnIndex::reference_set_id));
4963   }
mutable_owner_id()4964   TypedColumn<HeapGraphObjectTable::Id>* mutable_owner_id() {
4965     return static_cast<ColumnType::owner_id*>(
4966         GetColumn(ColumnIndex::owner_id));
4967   }
mutable_owned_id()4968   TypedColumn<std::optional<HeapGraphObjectTable::Id>>* mutable_owned_id() {
4969     return static_cast<ColumnType::owned_id*>(
4970         GetColumn(ColumnIndex::owned_id));
4971   }
mutable_field_name()4972   TypedColumn<StringPool::Id>* mutable_field_name() {
4973     return static_cast<ColumnType::field_name*>(
4974         GetColumn(ColumnIndex::field_name));
4975   }
mutable_field_type_name()4976   TypedColumn<StringPool::Id>* mutable_field_type_name() {
4977     return static_cast<ColumnType::field_type_name*>(
4978         GetColumn(ColumnIndex::field_type_name));
4979   }
mutable_deobfuscated_field_name()4980   TypedColumn<std::optional<StringPool::Id>>* mutable_deobfuscated_field_name() {
4981     return static_cast<ColumnType::deobfuscated_field_name*>(
4982         GetColumn(ColumnIndex::deobfuscated_field_name));
4983   }
4984 
4985  private:
4986 
4987 
4988   ColumnStorage<ColumnType::reference_set_id::stored_type> reference_set_id_;
4989   ColumnStorage<ColumnType::owner_id::stored_type> owner_id_;
4990   ColumnStorage<ColumnType::owned_id::stored_type> owned_id_;
4991   ColumnStorage<ColumnType::field_name::stored_type> field_name_;
4992   ColumnStorage<ColumnType::field_type_name::stored_type> field_type_name_;
4993   ColumnStorage<ColumnType::deobfuscated_field_name::stored_type> deobfuscated_field_name_;
4994 
4995   RefPtr<column::StorageLayer> id_storage_layer_;
4996   RefPtr<column::StorageLayer> type_storage_layer_;
4997   RefPtr<column::StorageLayer> reference_set_id_storage_layer_;
4998   RefPtr<column::StorageLayer> owner_id_storage_layer_;
4999   RefPtr<column::StorageLayer> owned_id_storage_layer_;
5000   RefPtr<column::StorageLayer> field_name_storage_layer_;
5001   RefPtr<column::StorageLayer> field_type_name_storage_layer_;
5002   RefPtr<column::StorageLayer> deobfuscated_field_name_storage_layer_;
5003 
5004   RefPtr<column::OverlayLayer> owned_id_null_layer_;
5005 };
5006 
5007 
5008 class InstrumentsSampleTable : public macros_internal::MacroTable {
5009  public:
5010   static constexpr uint32_t kColumnCount = 6;
5011 
5012   struct Id : public BaseId {
5013     Id() = default;
IdId5014     explicit constexpr Id(uint32_t v) : BaseId(v) {}
5015   };
5016   static_assert(std::is_trivially_destructible_v<Id>,
5017                 "Inheritance used without trivial destruction");
5018 
5019   struct ColumnIndex {
5020     static constexpr uint32_t id = 0;
5021     static constexpr uint32_t type = 1;
5022     static constexpr uint32_t ts = 2;
5023     static constexpr uint32_t utid = 3;
5024     static constexpr uint32_t cpu = 4;
5025     static constexpr uint32_t callsite_id = 5;
5026   };
5027   struct ColumnType {
5028     using id = IdColumn<InstrumentsSampleTable::Id>;
5029     using type = TypedColumn<StringPool::Id>;
5030     using ts = TypedColumn<int64_t>;
5031     using utid = TypedColumn<uint32_t>;
5032     using cpu = TypedColumn<std::optional<uint32_t>>;
5033     using callsite_id = TypedColumn<std::optional<StackProfileCallsiteTable::Id>>;
5034   };
5035   struct Row : public macros_internal::RootParentTable::Row {
5036     Row(int64_t in_ts = {},
5037         uint32_t in_utid = {},
5038         std::optional<uint32_t> in_cpu = {},
5039         std::optional<StackProfileCallsiteTable::Id> in_callsite_id = {},
5040         std::nullptr_t = nullptr)
RowRow5041         : macros_internal::RootParentTable::Row(),
5042           ts(in_ts),
5043           utid(in_utid),
5044           cpu(in_cpu),
5045           callsite_id(in_callsite_id) {
5046       type_ = "instruments_sample";
5047     }
5048     int64_t ts;
5049     uint32_t utid;
5050     std::optional<uint32_t> cpu;
5051     std::optional<StackProfileCallsiteTable::Id> callsite_id;
5052 
5053     bool operator==(const InstrumentsSampleTable::Row& other) const {
5054       return type() == other.type() && ColumnType::ts::Equals(ts, other.ts) &&
5055        ColumnType::utid::Equals(utid, other.utid) &&
5056        ColumnType::cpu::Equals(cpu, other.cpu) &&
5057        ColumnType::callsite_id::Equals(callsite_id, other.callsite_id);
5058     }
5059   };
5060   struct ColumnFlag {
5061     static constexpr uint32_t ts = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted) | ColumnType::ts::default_flags();
5062     static constexpr uint32_t utid = ColumnType::utid::default_flags();
5063     static constexpr uint32_t cpu = ColumnType::cpu::default_flags();
5064     static constexpr uint32_t callsite_id = ColumnType::callsite_id::default_flags();
5065   };
5066 
5067   class RowNumber;
5068   class ConstRowReference;
5069   class RowReference;
5070 
5071   class RowNumber : public macros_internal::AbstractRowNumber<
5072       InstrumentsSampleTable, ConstRowReference, RowReference> {
5073    public:
RowNumber(uint32_t row_number)5074     explicit RowNumber(uint32_t row_number)
5075         : AbstractRowNumber(row_number) {}
5076   };
5077   static_assert(std::is_trivially_destructible_v<RowNumber>,
5078                 "Inheritance used without trivial destruction");
5079 
5080   class ConstRowReference : public macros_internal::AbstractConstRowReference<
5081     InstrumentsSampleTable, RowNumber> {
5082    public:
ConstRowReference(const InstrumentsSampleTable * table,uint32_t row_number)5083     ConstRowReference(const InstrumentsSampleTable* table, uint32_t row_number)
5084         : AbstractConstRowReference(table, row_number) {}
5085 
id()5086     ColumnType::id::type id() const {
5087       return table()->id()[row_number_];
5088     }
type()5089     ColumnType::type::type type() const {
5090       return table()->type()[row_number_];
5091     }
ts()5092     ColumnType::ts::type ts() const {
5093       return table()->ts()[row_number_];
5094     }
utid()5095     ColumnType::utid::type utid() const {
5096       return table()->utid()[row_number_];
5097     }
cpu()5098     ColumnType::cpu::type cpu() const {
5099       return table()->cpu()[row_number_];
5100     }
callsite_id()5101     ColumnType::callsite_id::type callsite_id() const {
5102       return table()->callsite_id()[row_number_];
5103     }
5104   };
5105   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
5106                 "Inheritance used without trivial destruction");
5107   class RowReference : public ConstRowReference {
5108    public:
RowReference(const InstrumentsSampleTable * table,uint32_t row_number)5109     RowReference(const InstrumentsSampleTable* table, uint32_t row_number)
5110         : ConstRowReference(table, row_number) {}
5111 
set_ts(ColumnType::ts::non_optional_type v)5112     void set_ts(
5113         ColumnType::ts::non_optional_type v) {
5114       return mutable_table()->mutable_ts()->Set(row_number_, v);
5115     }
set_utid(ColumnType::utid::non_optional_type v)5116     void set_utid(
5117         ColumnType::utid::non_optional_type v) {
5118       return mutable_table()->mutable_utid()->Set(row_number_, v);
5119     }
set_cpu(ColumnType::cpu::non_optional_type v)5120     void set_cpu(
5121         ColumnType::cpu::non_optional_type v) {
5122       return mutable_table()->mutable_cpu()->Set(row_number_, v);
5123     }
set_callsite_id(ColumnType::callsite_id::non_optional_type v)5124     void set_callsite_id(
5125         ColumnType::callsite_id::non_optional_type v) {
5126       return mutable_table()->mutable_callsite_id()->Set(row_number_, v);
5127     }
5128 
5129    private:
mutable_table()5130     InstrumentsSampleTable* mutable_table() const {
5131       return const_cast<InstrumentsSampleTable*>(table());
5132     }
5133   };
5134   static_assert(std::is_trivially_destructible_v<RowReference>,
5135                 "Inheritance used without trivial destruction");
5136 
5137   class ConstIterator;
5138   class ConstIterator : public macros_internal::AbstractConstIterator<
5139     ConstIterator, InstrumentsSampleTable, RowNumber, ConstRowReference> {
5140    public:
id()5141     ColumnType::id::type id() const {
5142       const auto& col = table()->id();
5143       return col.GetAtIdx(
5144         iterator_.StorageIndexForColumn(col.index_in_table()));
5145     }
type()5146     ColumnType::type::type type() const {
5147       const auto& col = table()->type();
5148       return col.GetAtIdx(
5149         iterator_.StorageIndexForColumn(col.index_in_table()));
5150     }
ts()5151     ColumnType::ts::type ts() const {
5152       const auto& col = table()->ts();
5153       return col.GetAtIdx(
5154         iterator_.StorageIndexForColumn(col.index_in_table()));
5155     }
utid()5156     ColumnType::utid::type utid() const {
5157       const auto& col = table()->utid();
5158       return col.GetAtIdx(
5159         iterator_.StorageIndexForColumn(col.index_in_table()));
5160     }
cpu()5161     ColumnType::cpu::type cpu() const {
5162       const auto& col = table()->cpu();
5163       return col.GetAtIdx(
5164         iterator_.StorageIndexForColumn(col.index_in_table()));
5165     }
callsite_id()5166     ColumnType::callsite_id::type callsite_id() const {
5167       const auto& col = table()->callsite_id();
5168       return col.GetAtIdx(
5169         iterator_.StorageIndexForColumn(col.index_in_table()));
5170     }
5171 
5172    protected:
ConstIterator(const InstrumentsSampleTable * table,Table::Iterator iterator)5173     explicit ConstIterator(const InstrumentsSampleTable* table,
5174                            Table::Iterator iterator)
5175         : AbstractConstIterator(table, std::move(iterator)) {}
5176 
CurrentRowNumber()5177     uint32_t CurrentRowNumber() const {
5178       return iterator_.StorageIndexForLastOverlay();
5179     }
5180 
5181    private:
5182     friend class InstrumentsSampleTable;
5183     friend class macros_internal::AbstractConstIterator<
5184       ConstIterator, InstrumentsSampleTable, RowNumber, ConstRowReference>;
5185   };
5186   class Iterator : public ConstIterator {
5187     public:
row_reference()5188      RowReference row_reference() const {
5189        return {const_cast<InstrumentsSampleTable*>(table()), CurrentRowNumber()};
5190      }
5191 
5192     private:
5193      friend class InstrumentsSampleTable;
5194 
Iterator(InstrumentsSampleTable * table,Table::Iterator iterator)5195      explicit Iterator(InstrumentsSampleTable* table, Table::Iterator iterator)
5196         : ConstIterator(table, std::move(iterator)) {}
5197   };
5198 
5199   struct IdAndRow {
5200     Id id;
5201     uint32_t row;
5202     RowReference row_reference;
5203     RowNumber row_number;
5204   };
5205 
GetColumns(InstrumentsSampleTable * self,const macros_internal::MacroTable * parent)5206   static std::vector<ColumnLegacy> GetColumns(
5207       InstrumentsSampleTable* self,
5208       const macros_internal::MacroTable* parent) {
5209     std::vector<ColumnLegacy> columns =
5210         CopyColumnsFromParentOrAddRootColumns(self, parent);
5211     uint32_t olay_idx = OverlayCount(parent);
5212     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
5213                       static_cast<uint32_t>(columns.size()), olay_idx);
5214     AddColumnToVector(columns, "utid", &self->utid_, ColumnFlag::utid,
5215                       static_cast<uint32_t>(columns.size()), olay_idx);
5216     AddColumnToVector(columns, "cpu", &self->cpu_, ColumnFlag::cpu,
5217                       static_cast<uint32_t>(columns.size()), olay_idx);
5218     AddColumnToVector(columns, "callsite_id", &self->callsite_id_, ColumnFlag::callsite_id,
5219                       static_cast<uint32_t>(columns.size()), olay_idx);
5220     return columns;
5221   }
5222 
InstrumentsSampleTable(StringPool * pool)5223   PERFETTO_NO_INLINE explicit InstrumentsSampleTable(StringPool* pool)
5224       : macros_internal::MacroTable(
5225           pool,
5226           GetColumns(this, nullptr),
5227           nullptr),
5228         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
5229         utid_(ColumnStorage<ColumnType::utid::stored_type>::Create<false>()),
5230         cpu_(ColumnStorage<ColumnType::cpu::stored_type>::Create<false>()),
5231         callsite_id_(ColumnStorage<ColumnType::callsite_id::stored_type>::Create<false>())
5232 ,
5233         id_storage_layer_(new column::IdStorage()),
5234         type_storage_layer_(
5235           new column::StringStorage(string_pool(), &type_.vector())),
5236         ts_storage_layer_(
5237         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
5238           &ts_.vector(),
5239           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
5240           true)),
5241         utid_storage_layer_(
5242         new column::NumericStorage<ColumnType::utid::non_optional_stored_type>(
5243           &utid_.vector(),
5244           ColumnTypeHelper<ColumnType::utid::stored_type>::ToColumnType(),
5245           false)),
5246         cpu_storage_layer_(
5247           new column::NumericStorage<ColumnType::cpu::non_optional_stored_type>(
5248             &cpu_.non_null_vector(),
5249             ColumnTypeHelper<ColumnType::cpu::stored_type>::ToColumnType(),
5250             false)),
5251         callsite_id_storage_layer_(
5252           new column::NumericStorage<ColumnType::callsite_id::non_optional_stored_type>(
5253             &callsite_id_.non_null_vector(),
5254             ColumnTypeHelper<ColumnType::callsite_id::stored_type>::ToColumnType(),
5255             false))
5256 ,
5257         cpu_null_layer_(new column::NullOverlay(cpu_.bv())),
5258         callsite_id_null_layer_(new column::NullOverlay(callsite_id_.bv())) {
5259     static_assert(
5260         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
5261           ColumnFlag::ts),
5262         "Column type and flag combination is not valid");
5263       static_assert(
5264         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::utid::stored_type>(
5265           ColumnFlag::utid),
5266         "Column type and flag combination is not valid");
5267       static_assert(
5268         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cpu::stored_type>(
5269           ColumnFlag::cpu),
5270         "Column type and flag combination is not valid");
5271       static_assert(
5272         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::callsite_id::stored_type>(
5273           ColumnFlag::callsite_id),
5274         "Column type and flag combination is not valid");
5275     OnConstructionCompletedRegularConstructor(
5276       {id_storage_layer_,type_storage_layer_,ts_storage_layer_,utid_storage_layer_,cpu_storage_layer_,callsite_id_storage_layer_},
5277       {{},{},{},{},cpu_null_layer_,callsite_id_null_layer_});
5278   }
5279   ~InstrumentsSampleTable() override;
5280 
Name()5281   static const char* Name() { return "instruments_sample"; }
5282 
ComputeStaticSchema()5283   static Table::Schema ComputeStaticSchema() {
5284     Table::Schema schema;
5285     schema.columns.emplace_back(Table::Schema::Column{
5286         "id", SqlValue::Type::kLong, true, true, false, false});
5287     schema.columns.emplace_back(Table::Schema::Column{
5288         "type", SqlValue::Type::kString, false, false, false, false});
5289     schema.columns.emplace_back(Table::Schema::Column{
5290         "ts", ColumnType::ts::SqlValueType(), false,
5291         true,
5292         false,
5293         false});
5294     schema.columns.emplace_back(Table::Schema::Column{
5295         "utid", ColumnType::utid::SqlValueType(), false,
5296         false,
5297         false,
5298         false});
5299     schema.columns.emplace_back(Table::Schema::Column{
5300         "cpu", ColumnType::cpu::SqlValueType(), false,
5301         false,
5302         false,
5303         false});
5304     schema.columns.emplace_back(Table::Schema::Column{
5305         "callsite_id", ColumnType::callsite_id::SqlValueType(), false,
5306         false,
5307         false,
5308         false});
5309     return schema;
5310   }
5311 
IterateRows()5312   ConstIterator IterateRows() const {
5313     return ConstIterator(this, Table::IterateRows());
5314   }
5315 
IterateRows()5316   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
5317 
FilterToIterator(const Query & q)5318   ConstIterator FilterToIterator(const Query& q) const {
5319     return ConstIterator(this, QueryToIterator(q));
5320   }
5321 
FilterToIterator(const Query & q)5322   Iterator FilterToIterator(const Query& q) {
5323     return Iterator(this, QueryToIterator(q));
5324   }
5325 
ShrinkToFit()5326   void ShrinkToFit() {
5327     type_.ShrinkToFit();
5328     ts_.ShrinkToFit();
5329     utid_.ShrinkToFit();
5330     cpu_.ShrinkToFit();
5331     callsite_id_.ShrinkToFit();
5332   }
5333 
5334   ConstRowReference operator[](uint32_t r) const {
5335     return ConstRowReference(this, r);
5336   }
5337   RowReference operator[](uint32_t r) { return RowReference(this, r); }
5338   ConstRowReference operator[](RowNumber r) const {
5339     return ConstRowReference(this, r.row_number());
5340   }
5341   RowReference operator[](RowNumber r) {
5342     return RowReference(this, r.row_number());
5343   }
5344 
FindById(Id find_id)5345   std::optional<ConstRowReference> FindById(Id find_id) const {
5346     std::optional<uint32_t> row = id().IndexOf(find_id);
5347     return row ? std::make_optional(ConstRowReference(this, *row))
5348                : std::nullopt;
5349   }
5350 
FindById(Id find_id)5351   std::optional<RowReference> FindById(Id find_id) {
5352     std::optional<uint32_t> row = id().IndexOf(find_id);
5353     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
5354   }
5355 
Insert(const Row & row)5356   IdAndRow Insert(const Row& row) {
5357     uint32_t row_number = row_count();
5358     Id id = Id{row_number};
5359     type_.Append(string_pool()->InternString(row.type()));
5360     mutable_ts()->Append(row.ts);
5361     mutable_utid()->Append(row.utid);
5362     mutable_cpu()->Append(row.cpu);
5363     mutable_callsite_id()->Append(row.callsite_id);
5364     UpdateSelfOverlayAfterInsert();
5365     return IdAndRow{id, row_number, RowReference(this, row_number),
5366                      RowNumber(row_number)};
5367   }
5368 
5369 
5370 
id()5371   const IdColumn<InstrumentsSampleTable::Id>& id() const {
5372     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
5373   }
type()5374   const TypedColumn<StringPool::Id>& type() const {
5375     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
5376   }
ts()5377   const TypedColumn<int64_t>& ts() const {
5378     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
5379   }
utid()5380   const TypedColumn<uint32_t>& utid() const {
5381     return static_cast<const ColumnType::utid&>(columns()[ColumnIndex::utid]);
5382   }
cpu()5383   const TypedColumn<std::optional<uint32_t>>& cpu() const {
5384     return static_cast<const ColumnType::cpu&>(columns()[ColumnIndex::cpu]);
5385   }
callsite_id()5386   const TypedColumn<std::optional<StackProfileCallsiteTable::Id>>& callsite_id() const {
5387     return static_cast<const ColumnType::callsite_id&>(columns()[ColumnIndex::callsite_id]);
5388   }
5389 
mutable_ts()5390   TypedColumn<int64_t>* mutable_ts() {
5391     return static_cast<ColumnType::ts*>(
5392         GetColumn(ColumnIndex::ts));
5393   }
mutable_utid()5394   TypedColumn<uint32_t>* mutable_utid() {
5395     return static_cast<ColumnType::utid*>(
5396         GetColumn(ColumnIndex::utid));
5397   }
mutable_cpu()5398   TypedColumn<std::optional<uint32_t>>* mutable_cpu() {
5399     return static_cast<ColumnType::cpu*>(
5400         GetColumn(ColumnIndex::cpu));
5401   }
mutable_callsite_id()5402   TypedColumn<std::optional<StackProfileCallsiteTable::Id>>* mutable_callsite_id() {
5403     return static_cast<ColumnType::callsite_id*>(
5404         GetColumn(ColumnIndex::callsite_id));
5405   }
5406 
5407  private:
5408 
5409 
5410   ColumnStorage<ColumnType::ts::stored_type> ts_;
5411   ColumnStorage<ColumnType::utid::stored_type> utid_;
5412   ColumnStorage<ColumnType::cpu::stored_type> cpu_;
5413   ColumnStorage<ColumnType::callsite_id::stored_type> callsite_id_;
5414 
5415   RefPtr<column::StorageLayer> id_storage_layer_;
5416   RefPtr<column::StorageLayer> type_storage_layer_;
5417   RefPtr<column::StorageLayer> ts_storage_layer_;
5418   RefPtr<column::StorageLayer> utid_storage_layer_;
5419   RefPtr<column::StorageLayer> cpu_storage_layer_;
5420   RefPtr<column::StorageLayer> callsite_id_storage_layer_;
5421 
5422   RefPtr<column::OverlayLayer> cpu_null_layer_;
5423   RefPtr<column::OverlayLayer> callsite_id_null_layer_;
5424 };
5425 
5426 
5427 class HeapProfileAllocationTable : public macros_internal::MacroTable {
5428  public:
5429   static constexpr uint32_t kColumnCount = 8;
5430 
5431   struct Id : public BaseId {
5432     Id() = default;
IdId5433     explicit constexpr Id(uint32_t v) : BaseId(v) {}
5434   };
5435   static_assert(std::is_trivially_destructible_v<Id>,
5436                 "Inheritance used without trivial destruction");
5437 
5438   struct ColumnIndex {
5439     static constexpr uint32_t id = 0;
5440     static constexpr uint32_t type = 1;
5441     static constexpr uint32_t ts = 2;
5442     static constexpr uint32_t upid = 3;
5443     static constexpr uint32_t heap_name = 4;
5444     static constexpr uint32_t callsite_id = 5;
5445     static constexpr uint32_t count = 6;
5446     static constexpr uint32_t size = 7;
5447   };
5448   struct ColumnType {
5449     using id = IdColumn<HeapProfileAllocationTable::Id>;
5450     using type = TypedColumn<StringPool::Id>;
5451     using ts = TypedColumn<int64_t>;
5452     using upid = TypedColumn<uint32_t>;
5453     using heap_name = TypedColumn<StringPool::Id>;
5454     using callsite_id = TypedColumn<StackProfileCallsiteTable::Id>;
5455     using count = TypedColumn<int64_t>;
5456     using size = TypedColumn<int64_t>;
5457   };
5458   struct Row : public macros_internal::RootParentTable::Row {
5459     Row(int64_t in_ts = {},
5460         uint32_t in_upid = {},
5461         StringPool::Id in_heap_name = {},
5462         StackProfileCallsiteTable::Id in_callsite_id = {},
5463         int64_t in_count = {},
5464         int64_t in_size = {},
5465         std::nullptr_t = nullptr)
RowRow5466         : macros_internal::RootParentTable::Row(),
5467           ts(in_ts),
5468           upid(in_upid),
5469           heap_name(in_heap_name),
5470           callsite_id(in_callsite_id),
5471           count(in_count),
5472           size(in_size) {
5473       type_ = "heap_profile_allocation";
5474     }
5475     int64_t ts;
5476     uint32_t upid;
5477     StringPool::Id heap_name;
5478     StackProfileCallsiteTable::Id callsite_id;
5479     int64_t count;
5480     int64_t size;
5481 
5482     bool operator==(const HeapProfileAllocationTable::Row& other) const {
5483       return type() == other.type() && ColumnType::ts::Equals(ts, other.ts) &&
5484        ColumnType::upid::Equals(upid, other.upid) &&
5485        ColumnType::heap_name::Equals(heap_name, other.heap_name) &&
5486        ColumnType::callsite_id::Equals(callsite_id, other.callsite_id) &&
5487        ColumnType::count::Equals(count, other.count) &&
5488        ColumnType::size::Equals(size, other.size);
5489     }
5490   };
5491   struct ColumnFlag {
5492     static constexpr uint32_t ts = ColumnType::ts::default_flags();
5493     static constexpr uint32_t upid = ColumnType::upid::default_flags();
5494     static constexpr uint32_t heap_name = ColumnType::heap_name::default_flags();
5495     static constexpr uint32_t callsite_id = ColumnType::callsite_id::default_flags();
5496     static constexpr uint32_t count = ColumnType::count::default_flags();
5497     static constexpr uint32_t size = ColumnType::size::default_flags();
5498   };
5499 
5500   class RowNumber;
5501   class ConstRowReference;
5502   class RowReference;
5503 
5504   class RowNumber : public macros_internal::AbstractRowNumber<
5505       HeapProfileAllocationTable, ConstRowReference, RowReference> {
5506    public:
RowNumber(uint32_t row_number)5507     explicit RowNumber(uint32_t row_number)
5508         : AbstractRowNumber(row_number) {}
5509   };
5510   static_assert(std::is_trivially_destructible_v<RowNumber>,
5511                 "Inheritance used without trivial destruction");
5512 
5513   class ConstRowReference : public macros_internal::AbstractConstRowReference<
5514     HeapProfileAllocationTable, RowNumber> {
5515    public:
ConstRowReference(const HeapProfileAllocationTable * table,uint32_t row_number)5516     ConstRowReference(const HeapProfileAllocationTable* table, uint32_t row_number)
5517         : AbstractConstRowReference(table, row_number) {}
5518 
id()5519     ColumnType::id::type id() const {
5520       return table()->id()[row_number_];
5521     }
type()5522     ColumnType::type::type type() const {
5523       return table()->type()[row_number_];
5524     }
ts()5525     ColumnType::ts::type ts() const {
5526       return table()->ts()[row_number_];
5527     }
upid()5528     ColumnType::upid::type upid() const {
5529       return table()->upid()[row_number_];
5530     }
heap_name()5531     ColumnType::heap_name::type heap_name() const {
5532       return table()->heap_name()[row_number_];
5533     }
callsite_id()5534     ColumnType::callsite_id::type callsite_id() const {
5535       return table()->callsite_id()[row_number_];
5536     }
count()5537     ColumnType::count::type count() const {
5538       return table()->count()[row_number_];
5539     }
size()5540     ColumnType::size::type size() const {
5541       return table()->size()[row_number_];
5542     }
5543   };
5544   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
5545                 "Inheritance used without trivial destruction");
5546   class RowReference : public ConstRowReference {
5547    public:
RowReference(const HeapProfileAllocationTable * table,uint32_t row_number)5548     RowReference(const HeapProfileAllocationTable* table, uint32_t row_number)
5549         : ConstRowReference(table, row_number) {}
5550 
set_ts(ColumnType::ts::non_optional_type v)5551     void set_ts(
5552         ColumnType::ts::non_optional_type v) {
5553       return mutable_table()->mutable_ts()->Set(row_number_, v);
5554     }
set_upid(ColumnType::upid::non_optional_type v)5555     void set_upid(
5556         ColumnType::upid::non_optional_type v) {
5557       return mutable_table()->mutable_upid()->Set(row_number_, v);
5558     }
set_heap_name(ColumnType::heap_name::non_optional_type v)5559     void set_heap_name(
5560         ColumnType::heap_name::non_optional_type v) {
5561       return mutable_table()->mutable_heap_name()->Set(row_number_, v);
5562     }
set_callsite_id(ColumnType::callsite_id::non_optional_type v)5563     void set_callsite_id(
5564         ColumnType::callsite_id::non_optional_type v) {
5565       return mutable_table()->mutable_callsite_id()->Set(row_number_, v);
5566     }
set_count(ColumnType::count::non_optional_type v)5567     void set_count(
5568         ColumnType::count::non_optional_type v) {
5569       return mutable_table()->mutable_count()->Set(row_number_, v);
5570     }
set_size(ColumnType::size::non_optional_type v)5571     void set_size(
5572         ColumnType::size::non_optional_type v) {
5573       return mutable_table()->mutable_size()->Set(row_number_, v);
5574     }
5575 
5576    private:
mutable_table()5577     HeapProfileAllocationTable* mutable_table() const {
5578       return const_cast<HeapProfileAllocationTable*>(table());
5579     }
5580   };
5581   static_assert(std::is_trivially_destructible_v<RowReference>,
5582                 "Inheritance used without trivial destruction");
5583 
5584   class ConstIterator;
5585   class ConstIterator : public macros_internal::AbstractConstIterator<
5586     ConstIterator, HeapProfileAllocationTable, RowNumber, ConstRowReference> {
5587    public:
id()5588     ColumnType::id::type id() const {
5589       const auto& col = table()->id();
5590       return col.GetAtIdx(
5591         iterator_.StorageIndexForColumn(col.index_in_table()));
5592     }
type()5593     ColumnType::type::type type() const {
5594       const auto& col = table()->type();
5595       return col.GetAtIdx(
5596         iterator_.StorageIndexForColumn(col.index_in_table()));
5597     }
ts()5598     ColumnType::ts::type ts() const {
5599       const auto& col = table()->ts();
5600       return col.GetAtIdx(
5601         iterator_.StorageIndexForColumn(col.index_in_table()));
5602     }
upid()5603     ColumnType::upid::type upid() const {
5604       const auto& col = table()->upid();
5605       return col.GetAtIdx(
5606         iterator_.StorageIndexForColumn(col.index_in_table()));
5607     }
heap_name()5608     ColumnType::heap_name::type heap_name() const {
5609       const auto& col = table()->heap_name();
5610       return col.GetAtIdx(
5611         iterator_.StorageIndexForColumn(col.index_in_table()));
5612     }
callsite_id()5613     ColumnType::callsite_id::type callsite_id() const {
5614       const auto& col = table()->callsite_id();
5615       return col.GetAtIdx(
5616         iterator_.StorageIndexForColumn(col.index_in_table()));
5617     }
count()5618     ColumnType::count::type count() const {
5619       const auto& col = table()->count();
5620       return col.GetAtIdx(
5621         iterator_.StorageIndexForColumn(col.index_in_table()));
5622     }
size()5623     ColumnType::size::type size() const {
5624       const auto& col = table()->size();
5625       return col.GetAtIdx(
5626         iterator_.StorageIndexForColumn(col.index_in_table()));
5627     }
5628 
5629    protected:
ConstIterator(const HeapProfileAllocationTable * table,Table::Iterator iterator)5630     explicit ConstIterator(const HeapProfileAllocationTable* table,
5631                            Table::Iterator iterator)
5632         : AbstractConstIterator(table, std::move(iterator)) {}
5633 
CurrentRowNumber()5634     uint32_t CurrentRowNumber() const {
5635       return iterator_.StorageIndexForLastOverlay();
5636     }
5637 
5638    private:
5639     friend class HeapProfileAllocationTable;
5640     friend class macros_internal::AbstractConstIterator<
5641       ConstIterator, HeapProfileAllocationTable, RowNumber, ConstRowReference>;
5642   };
5643   class Iterator : public ConstIterator {
5644     public:
row_reference()5645      RowReference row_reference() const {
5646        return {const_cast<HeapProfileAllocationTable*>(table()), CurrentRowNumber()};
5647      }
5648 
5649     private:
5650      friend class HeapProfileAllocationTable;
5651 
Iterator(HeapProfileAllocationTable * table,Table::Iterator iterator)5652      explicit Iterator(HeapProfileAllocationTable* table, Table::Iterator iterator)
5653         : ConstIterator(table, std::move(iterator)) {}
5654   };
5655 
5656   struct IdAndRow {
5657     Id id;
5658     uint32_t row;
5659     RowReference row_reference;
5660     RowNumber row_number;
5661   };
5662 
GetColumns(HeapProfileAllocationTable * self,const macros_internal::MacroTable * parent)5663   static std::vector<ColumnLegacy> GetColumns(
5664       HeapProfileAllocationTable* self,
5665       const macros_internal::MacroTable* parent) {
5666     std::vector<ColumnLegacy> columns =
5667         CopyColumnsFromParentOrAddRootColumns(self, parent);
5668     uint32_t olay_idx = OverlayCount(parent);
5669     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
5670                       static_cast<uint32_t>(columns.size()), olay_idx);
5671     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
5672                       static_cast<uint32_t>(columns.size()), olay_idx);
5673     AddColumnToVector(columns, "heap_name", &self->heap_name_, ColumnFlag::heap_name,
5674                       static_cast<uint32_t>(columns.size()), olay_idx);
5675     AddColumnToVector(columns, "callsite_id", &self->callsite_id_, ColumnFlag::callsite_id,
5676                       static_cast<uint32_t>(columns.size()), olay_idx);
5677     AddColumnToVector(columns, "count", &self->count_, ColumnFlag::count,
5678                       static_cast<uint32_t>(columns.size()), olay_idx);
5679     AddColumnToVector(columns, "size", &self->size_, ColumnFlag::size,
5680                       static_cast<uint32_t>(columns.size()), olay_idx);
5681     return columns;
5682   }
5683 
HeapProfileAllocationTable(StringPool * pool)5684   PERFETTO_NO_INLINE explicit HeapProfileAllocationTable(StringPool* pool)
5685       : macros_internal::MacroTable(
5686           pool,
5687           GetColumns(this, nullptr),
5688           nullptr),
5689         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
5690         upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>()),
5691         heap_name_(ColumnStorage<ColumnType::heap_name::stored_type>::Create<false>()),
5692         callsite_id_(ColumnStorage<ColumnType::callsite_id::stored_type>::Create<false>()),
5693         count_(ColumnStorage<ColumnType::count::stored_type>::Create<false>()),
5694         size_(ColumnStorage<ColumnType::size::stored_type>::Create<false>())
5695 ,
5696         id_storage_layer_(new column::IdStorage()),
5697         type_storage_layer_(
5698           new column::StringStorage(string_pool(), &type_.vector())),
5699         ts_storage_layer_(
5700         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
5701           &ts_.vector(),
5702           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
5703           false)),
5704         upid_storage_layer_(
5705         new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
5706           &upid_.vector(),
5707           ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
5708           false)),
5709         heap_name_storage_layer_(
5710           new column::StringStorage(string_pool(), &heap_name_.vector())),
5711         callsite_id_storage_layer_(
5712         new column::NumericStorage<ColumnType::callsite_id::non_optional_stored_type>(
5713           &callsite_id_.vector(),
5714           ColumnTypeHelper<ColumnType::callsite_id::stored_type>::ToColumnType(),
5715           false)),
5716         count_storage_layer_(
5717         new column::NumericStorage<ColumnType::count::non_optional_stored_type>(
5718           &count_.vector(),
5719           ColumnTypeHelper<ColumnType::count::stored_type>::ToColumnType(),
5720           false)),
5721         size_storage_layer_(
5722         new column::NumericStorage<ColumnType::size::non_optional_stored_type>(
5723           &size_.vector(),
5724           ColumnTypeHelper<ColumnType::size::stored_type>::ToColumnType(),
5725           false))
5726          {
5727     static_assert(
5728         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
5729           ColumnFlag::ts),
5730         "Column type and flag combination is not valid");
5731       static_assert(
5732         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
5733           ColumnFlag::upid),
5734         "Column type and flag combination is not valid");
5735       static_assert(
5736         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::heap_name::stored_type>(
5737           ColumnFlag::heap_name),
5738         "Column type and flag combination is not valid");
5739       static_assert(
5740         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::callsite_id::stored_type>(
5741           ColumnFlag::callsite_id),
5742         "Column type and flag combination is not valid");
5743       static_assert(
5744         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::count::stored_type>(
5745           ColumnFlag::count),
5746         "Column type and flag combination is not valid");
5747       static_assert(
5748         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::size::stored_type>(
5749           ColumnFlag::size),
5750         "Column type and flag combination is not valid");
5751     OnConstructionCompletedRegularConstructor(
5752       {id_storage_layer_,type_storage_layer_,ts_storage_layer_,upid_storage_layer_,heap_name_storage_layer_,callsite_id_storage_layer_,count_storage_layer_,size_storage_layer_},
5753       {{},{},{},{},{},{},{},{}});
5754   }
5755   ~HeapProfileAllocationTable() override;
5756 
Name()5757   static const char* Name() { return "heap_profile_allocation"; }
5758 
ComputeStaticSchema()5759   static Table::Schema ComputeStaticSchema() {
5760     Table::Schema schema;
5761     schema.columns.emplace_back(Table::Schema::Column{
5762         "id", SqlValue::Type::kLong, true, true, false, false});
5763     schema.columns.emplace_back(Table::Schema::Column{
5764         "type", SqlValue::Type::kString, false, false, false, false});
5765     schema.columns.emplace_back(Table::Schema::Column{
5766         "ts", ColumnType::ts::SqlValueType(), false,
5767         false,
5768         false,
5769         false});
5770     schema.columns.emplace_back(Table::Schema::Column{
5771         "upid", ColumnType::upid::SqlValueType(), false,
5772         false,
5773         false,
5774         false});
5775     schema.columns.emplace_back(Table::Schema::Column{
5776         "heap_name", ColumnType::heap_name::SqlValueType(), false,
5777         false,
5778         false,
5779         false});
5780     schema.columns.emplace_back(Table::Schema::Column{
5781         "callsite_id", ColumnType::callsite_id::SqlValueType(), false,
5782         false,
5783         false,
5784         false});
5785     schema.columns.emplace_back(Table::Schema::Column{
5786         "count", ColumnType::count::SqlValueType(), false,
5787         false,
5788         false,
5789         false});
5790     schema.columns.emplace_back(Table::Schema::Column{
5791         "size", ColumnType::size::SqlValueType(), false,
5792         false,
5793         false,
5794         false});
5795     return schema;
5796   }
5797 
IterateRows()5798   ConstIterator IterateRows() const {
5799     return ConstIterator(this, Table::IterateRows());
5800   }
5801 
IterateRows()5802   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
5803 
FilterToIterator(const Query & q)5804   ConstIterator FilterToIterator(const Query& q) const {
5805     return ConstIterator(this, QueryToIterator(q));
5806   }
5807 
FilterToIterator(const Query & q)5808   Iterator FilterToIterator(const Query& q) {
5809     return Iterator(this, QueryToIterator(q));
5810   }
5811 
ShrinkToFit()5812   void ShrinkToFit() {
5813     type_.ShrinkToFit();
5814     ts_.ShrinkToFit();
5815     upid_.ShrinkToFit();
5816     heap_name_.ShrinkToFit();
5817     callsite_id_.ShrinkToFit();
5818     count_.ShrinkToFit();
5819     size_.ShrinkToFit();
5820   }
5821 
5822   ConstRowReference operator[](uint32_t r) const {
5823     return ConstRowReference(this, r);
5824   }
5825   RowReference operator[](uint32_t r) { return RowReference(this, r); }
5826   ConstRowReference operator[](RowNumber r) const {
5827     return ConstRowReference(this, r.row_number());
5828   }
5829   RowReference operator[](RowNumber r) {
5830     return RowReference(this, r.row_number());
5831   }
5832 
FindById(Id find_id)5833   std::optional<ConstRowReference> FindById(Id find_id) const {
5834     std::optional<uint32_t> row = id().IndexOf(find_id);
5835     return row ? std::make_optional(ConstRowReference(this, *row))
5836                : std::nullopt;
5837   }
5838 
FindById(Id find_id)5839   std::optional<RowReference> FindById(Id find_id) {
5840     std::optional<uint32_t> row = id().IndexOf(find_id);
5841     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
5842   }
5843 
Insert(const Row & row)5844   IdAndRow Insert(const Row& row) {
5845     uint32_t row_number = row_count();
5846     Id id = Id{row_number};
5847     type_.Append(string_pool()->InternString(row.type()));
5848     mutable_ts()->Append(row.ts);
5849     mutable_upid()->Append(row.upid);
5850     mutable_heap_name()->Append(row.heap_name);
5851     mutable_callsite_id()->Append(row.callsite_id);
5852     mutable_count()->Append(row.count);
5853     mutable_size()->Append(row.size);
5854     UpdateSelfOverlayAfterInsert();
5855     return IdAndRow{id, row_number, RowReference(this, row_number),
5856                      RowNumber(row_number)};
5857   }
5858 
5859 
5860 
id()5861   const IdColumn<HeapProfileAllocationTable::Id>& id() const {
5862     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
5863   }
type()5864   const TypedColumn<StringPool::Id>& type() const {
5865     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
5866   }
ts()5867   const TypedColumn<int64_t>& ts() const {
5868     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
5869   }
upid()5870   const TypedColumn<uint32_t>& upid() const {
5871     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
5872   }
heap_name()5873   const TypedColumn<StringPool::Id>& heap_name() const {
5874     return static_cast<const ColumnType::heap_name&>(columns()[ColumnIndex::heap_name]);
5875   }
callsite_id()5876   const TypedColumn<StackProfileCallsiteTable::Id>& callsite_id() const {
5877     return static_cast<const ColumnType::callsite_id&>(columns()[ColumnIndex::callsite_id]);
5878   }
count()5879   const TypedColumn<int64_t>& count() const {
5880     return static_cast<const ColumnType::count&>(columns()[ColumnIndex::count]);
5881   }
size()5882   const TypedColumn<int64_t>& size() const {
5883     return static_cast<const ColumnType::size&>(columns()[ColumnIndex::size]);
5884   }
5885 
mutable_ts()5886   TypedColumn<int64_t>* mutable_ts() {
5887     return static_cast<ColumnType::ts*>(
5888         GetColumn(ColumnIndex::ts));
5889   }
mutable_upid()5890   TypedColumn<uint32_t>* mutable_upid() {
5891     return static_cast<ColumnType::upid*>(
5892         GetColumn(ColumnIndex::upid));
5893   }
mutable_heap_name()5894   TypedColumn<StringPool::Id>* mutable_heap_name() {
5895     return static_cast<ColumnType::heap_name*>(
5896         GetColumn(ColumnIndex::heap_name));
5897   }
mutable_callsite_id()5898   TypedColumn<StackProfileCallsiteTable::Id>* mutable_callsite_id() {
5899     return static_cast<ColumnType::callsite_id*>(
5900         GetColumn(ColumnIndex::callsite_id));
5901   }
mutable_count()5902   TypedColumn<int64_t>* mutable_count() {
5903     return static_cast<ColumnType::count*>(
5904         GetColumn(ColumnIndex::count));
5905   }
mutable_size()5906   TypedColumn<int64_t>* mutable_size() {
5907     return static_cast<ColumnType::size*>(
5908         GetColumn(ColumnIndex::size));
5909   }
5910 
5911  private:
5912 
5913 
5914   ColumnStorage<ColumnType::ts::stored_type> ts_;
5915   ColumnStorage<ColumnType::upid::stored_type> upid_;
5916   ColumnStorage<ColumnType::heap_name::stored_type> heap_name_;
5917   ColumnStorage<ColumnType::callsite_id::stored_type> callsite_id_;
5918   ColumnStorage<ColumnType::count::stored_type> count_;
5919   ColumnStorage<ColumnType::size::stored_type> size_;
5920 
5921   RefPtr<column::StorageLayer> id_storage_layer_;
5922   RefPtr<column::StorageLayer> type_storage_layer_;
5923   RefPtr<column::StorageLayer> ts_storage_layer_;
5924   RefPtr<column::StorageLayer> upid_storage_layer_;
5925   RefPtr<column::StorageLayer> heap_name_storage_layer_;
5926   RefPtr<column::StorageLayer> callsite_id_storage_layer_;
5927   RefPtr<column::StorageLayer> count_storage_layer_;
5928   RefPtr<column::StorageLayer> size_storage_layer_;
5929 
5930 
5931 };
5932 
5933 
5934 class PackageListTable : public macros_internal::MacroTable {
5935  public:
5936   static constexpr uint32_t kColumnCount = 7;
5937 
5938   struct Id : public BaseId {
5939     Id() = default;
IdId5940     explicit constexpr Id(uint32_t v) : BaseId(v) {}
5941   };
5942   static_assert(std::is_trivially_destructible_v<Id>,
5943                 "Inheritance used without trivial destruction");
5944 
5945   struct ColumnIndex {
5946     static constexpr uint32_t id = 0;
5947     static constexpr uint32_t type = 1;
5948     static constexpr uint32_t package_name = 2;
5949     static constexpr uint32_t uid = 3;
5950     static constexpr uint32_t debuggable = 4;
5951     static constexpr uint32_t profileable_from_shell = 5;
5952     static constexpr uint32_t version_code = 6;
5953   };
5954   struct ColumnType {
5955     using id = IdColumn<PackageListTable::Id>;
5956     using type = TypedColumn<StringPool::Id>;
5957     using package_name = TypedColumn<StringPool::Id>;
5958     using uid = TypedColumn<int64_t>;
5959     using debuggable = TypedColumn<int32_t>;
5960     using profileable_from_shell = TypedColumn<int32_t>;
5961     using version_code = TypedColumn<int64_t>;
5962   };
5963   struct Row : public macros_internal::RootParentTable::Row {
5964     Row(StringPool::Id in_package_name = {},
5965         int64_t in_uid = {},
5966         int32_t in_debuggable = {},
5967         int32_t in_profileable_from_shell = {},
5968         int64_t in_version_code = {},
5969         std::nullptr_t = nullptr)
RowRow5970         : macros_internal::RootParentTable::Row(),
5971           package_name(in_package_name),
5972           uid(in_uid),
5973           debuggable(in_debuggable),
5974           profileable_from_shell(in_profileable_from_shell),
5975           version_code(in_version_code) {
5976       type_ = "package_list";
5977     }
5978     StringPool::Id package_name;
5979     int64_t uid;
5980     int32_t debuggable;
5981     int32_t profileable_from_shell;
5982     int64_t version_code;
5983 
5984     bool operator==(const PackageListTable::Row& other) const {
5985       return type() == other.type() && ColumnType::package_name::Equals(package_name, other.package_name) &&
5986        ColumnType::uid::Equals(uid, other.uid) &&
5987        ColumnType::debuggable::Equals(debuggable, other.debuggable) &&
5988        ColumnType::profileable_from_shell::Equals(profileable_from_shell, other.profileable_from_shell) &&
5989        ColumnType::version_code::Equals(version_code, other.version_code);
5990     }
5991   };
5992   struct ColumnFlag {
5993     static constexpr uint32_t package_name = ColumnType::package_name::default_flags();
5994     static constexpr uint32_t uid = ColumnType::uid::default_flags();
5995     static constexpr uint32_t debuggable = ColumnType::debuggable::default_flags();
5996     static constexpr uint32_t profileable_from_shell = ColumnType::profileable_from_shell::default_flags();
5997     static constexpr uint32_t version_code = ColumnType::version_code::default_flags();
5998   };
5999 
6000   class RowNumber;
6001   class ConstRowReference;
6002   class RowReference;
6003 
6004   class RowNumber : public macros_internal::AbstractRowNumber<
6005       PackageListTable, ConstRowReference, RowReference> {
6006    public:
RowNumber(uint32_t row_number)6007     explicit RowNumber(uint32_t row_number)
6008         : AbstractRowNumber(row_number) {}
6009   };
6010   static_assert(std::is_trivially_destructible_v<RowNumber>,
6011                 "Inheritance used without trivial destruction");
6012 
6013   class ConstRowReference : public macros_internal::AbstractConstRowReference<
6014     PackageListTable, RowNumber> {
6015    public:
ConstRowReference(const PackageListTable * table,uint32_t row_number)6016     ConstRowReference(const PackageListTable* table, uint32_t row_number)
6017         : AbstractConstRowReference(table, row_number) {}
6018 
id()6019     ColumnType::id::type id() const {
6020       return table()->id()[row_number_];
6021     }
type()6022     ColumnType::type::type type() const {
6023       return table()->type()[row_number_];
6024     }
package_name()6025     ColumnType::package_name::type package_name() const {
6026       return table()->package_name()[row_number_];
6027     }
uid()6028     ColumnType::uid::type uid() const {
6029       return table()->uid()[row_number_];
6030     }
debuggable()6031     ColumnType::debuggable::type debuggable() const {
6032       return table()->debuggable()[row_number_];
6033     }
profileable_from_shell()6034     ColumnType::profileable_from_shell::type profileable_from_shell() const {
6035       return table()->profileable_from_shell()[row_number_];
6036     }
version_code()6037     ColumnType::version_code::type version_code() const {
6038       return table()->version_code()[row_number_];
6039     }
6040   };
6041   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
6042                 "Inheritance used without trivial destruction");
6043   class RowReference : public ConstRowReference {
6044    public:
RowReference(const PackageListTable * table,uint32_t row_number)6045     RowReference(const PackageListTable* table, uint32_t row_number)
6046         : ConstRowReference(table, row_number) {}
6047 
set_package_name(ColumnType::package_name::non_optional_type v)6048     void set_package_name(
6049         ColumnType::package_name::non_optional_type v) {
6050       return mutable_table()->mutable_package_name()->Set(row_number_, v);
6051     }
set_uid(ColumnType::uid::non_optional_type v)6052     void set_uid(
6053         ColumnType::uid::non_optional_type v) {
6054       return mutable_table()->mutable_uid()->Set(row_number_, v);
6055     }
set_debuggable(ColumnType::debuggable::non_optional_type v)6056     void set_debuggable(
6057         ColumnType::debuggable::non_optional_type v) {
6058       return mutable_table()->mutable_debuggable()->Set(row_number_, v);
6059     }
set_profileable_from_shell(ColumnType::profileable_from_shell::non_optional_type v)6060     void set_profileable_from_shell(
6061         ColumnType::profileable_from_shell::non_optional_type v) {
6062       return mutable_table()->mutable_profileable_from_shell()->Set(row_number_, v);
6063     }
set_version_code(ColumnType::version_code::non_optional_type v)6064     void set_version_code(
6065         ColumnType::version_code::non_optional_type v) {
6066       return mutable_table()->mutable_version_code()->Set(row_number_, v);
6067     }
6068 
6069    private:
mutable_table()6070     PackageListTable* mutable_table() const {
6071       return const_cast<PackageListTable*>(table());
6072     }
6073   };
6074   static_assert(std::is_trivially_destructible_v<RowReference>,
6075                 "Inheritance used without trivial destruction");
6076 
6077   class ConstIterator;
6078   class ConstIterator : public macros_internal::AbstractConstIterator<
6079     ConstIterator, PackageListTable, RowNumber, ConstRowReference> {
6080    public:
id()6081     ColumnType::id::type id() const {
6082       const auto& col = table()->id();
6083       return col.GetAtIdx(
6084         iterator_.StorageIndexForColumn(col.index_in_table()));
6085     }
type()6086     ColumnType::type::type type() const {
6087       const auto& col = table()->type();
6088       return col.GetAtIdx(
6089         iterator_.StorageIndexForColumn(col.index_in_table()));
6090     }
package_name()6091     ColumnType::package_name::type package_name() const {
6092       const auto& col = table()->package_name();
6093       return col.GetAtIdx(
6094         iterator_.StorageIndexForColumn(col.index_in_table()));
6095     }
uid()6096     ColumnType::uid::type uid() const {
6097       const auto& col = table()->uid();
6098       return col.GetAtIdx(
6099         iterator_.StorageIndexForColumn(col.index_in_table()));
6100     }
debuggable()6101     ColumnType::debuggable::type debuggable() const {
6102       const auto& col = table()->debuggable();
6103       return col.GetAtIdx(
6104         iterator_.StorageIndexForColumn(col.index_in_table()));
6105     }
profileable_from_shell()6106     ColumnType::profileable_from_shell::type profileable_from_shell() const {
6107       const auto& col = table()->profileable_from_shell();
6108       return col.GetAtIdx(
6109         iterator_.StorageIndexForColumn(col.index_in_table()));
6110     }
version_code()6111     ColumnType::version_code::type version_code() const {
6112       const auto& col = table()->version_code();
6113       return col.GetAtIdx(
6114         iterator_.StorageIndexForColumn(col.index_in_table()));
6115     }
6116 
6117    protected:
ConstIterator(const PackageListTable * table,Table::Iterator iterator)6118     explicit ConstIterator(const PackageListTable* table,
6119                            Table::Iterator iterator)
6120         : AbstractConstIterator(table, std::move(iterator)) {}
6121 
CurrentRowNumber()6122     uint32_t CurrentRowNumber() const {
6123       return iterator_.StorageIndexForLastOverlay();
6124     }
6125 
6126    private:
6127     friend class PackageListTable;
6128     friend class macros_internal::AbstractConstIterator<
6129       ConstIterator, PackageListTable, RowNumber, ConstRowReference>;
6130   };
6131   class Iterator : public ConstIterator {
6132     public:
row_reference()6133      RowReference row_reference() const {
6134        return {const_cast<PackageListTable*>(table()), CurrentRowNumber()};
6135      }
6136 
6137     private:
6138      friend class PackageListTable;
6139 
Iterator(PackageListTable * table,Table::Iterator iterator)6140      explicit Iterator(PackageListTable* table, Table::Iterator iterator)
6141         : ConstIterator(table, std::move(iterator)) {}
6142   };
6143 
6144   struct IdAndRow {
6145     Id id;
6146     uint32_t row;
6147     RowReference row_reference;
6148     RowNumber row_number;
6149   };
6150 
GetColumns(PackageListTable * self,const macros_internal::MacroTable * parent)6151   static std::vector<ColumnLegacy> GetColumns(
6152       PackageListTable* self,
6153       const macros_internal::MacroTable* parent) {
6154     std::vector<ColumnLegacy> columns =
6155         CopyColumnsFromParentOrAddRootColumns(self, parent);
6156     uint32_t olay_idx = OverlayCount(parent);
6157     AddColumnToVector(columns, "package_name", &self->package_name_, ColumnFlag::package_name,
6158                       static_cast<uint32_t>(columns.size()), olay_idx);
6159     AddColumnToVector(columns, "uid", &self->uid_, ColumnFlag::uid,
6160                       static_cast<uint32_t>(columns.size()), olay_idx);
6161     AddColumnToVector(columns, "debuggable", &self->debuggable_, ColumnFlag::debuggable,
6162                       static_cast<uint32_t>(columns.size()), olay_idx);
6163     AddColumnToVector(columns, "profileable_from_shell", &self->profileable_from_shell_, ColumnFlag::profileable_from_shell,
6164                       static_cast<uint32_t>(columns.size()), olay_idx);
6165     AddColumnToVector(columns, "version_code", &self->version_code_, ColumnFlag::version_code,
6166                       static_cast<uint32_t>(columns.size()), olay_idx);
6167     return columns;
6168   }
6169 
PackageListTable(StringPool * pool)6170   PERFETTO_NO_INLINE explicit PackageListTable(StringPool* pool)
6171       : macros_internal::MacroTable(
6172           pool,
6173           GetColumns(this, nullptr),
6174           nullptr),
6175         package_name_(ColumnStorage<ColumnType::package_name::stored_type>::Create<false>()),
6176         uid_(ColumnStorage<ColumnType::uid::stored_type>::Create<false>()),
6177         debuggable_(ColumnStorage<ColumnType::debuggable::stored_type>::Create<false>()),
6178         profileable_from_shell_(ColumnStorage<ColumnType::profileable_from_shell::stored_type>::Create<false>()),
6179         version_code_(ColumnStorage<ColumnType::version_code::stored_type>::Create<false>())
6180 ,
6181         id_storage_layer_(new column::IdStorage()),
6182         type_storage_layer_(
6183           new column::StringStorage(string_pool(), &type_.vector())),
6184         package_name_storage_layer_(
6185           new column::StringStorage(string_pool(), &package_name_.vector())),
6186         uid_storage_layer_(
6187         new column::NumericStorage<ColumnType::uid::non_optional_stored_type>(
6188           &uid_.vector(),
6189           ColumnTypeHelper<ColumnType::uid::stored_type>::ToColumnType(),
6190           false)),
6191         debuggable_storage_layer_(
6192         new column::NumericStorage<ColumnType::debuggable::non_optional_stored_type>(
6193           &debuggable_.vector(),
6194           ColumnTypeHelper<ColumnType::debuggable::stored_type>::ToColumnType(),
6195           false)),
6196         profileable_from_shell_storage_layer_(
6197         new column::NumericStorage<ColumnType::profileable_from_shell::non_optional_stored_type>(
6198           &profileable_from_shell_.vector(),
6199           ColumnTypeHelper<ColumnType::profileable_from_shell::stored_type>::ToColumnType(),
6200           false)),
6201         version_code_storage_layer_(
6202         new column::NumericStorage<ColumnType::version_code::non_optional_stored_type>(
6203           &version_code_.vector(),
6204           ColumnTypeHelper<ColumnType::version_code::stored_type>::ToColumnType(),
6205           false))
6206          {
6207     static_assert(
6208         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::package_name::stored_type>(
6209           ColumnFlag::package_name),
6210         "Column type and flag combination is not valid");
6211       static_assert(
6212         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::uid::stored_type>(
6213           ColumnFlag::uid),
6214         "Column type and flag combination is not valid");
6215       static_assert(
6216         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::debuggable::stored_type>(
6217           ColumnFlag::debuggable),
6218         "Column type and flag combination is not valid");
6219       static_assert(
6220         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::profileable_from_shell::stored_type>(
6221           ColumnFlag::profileable_from_shell),
6222         "Column type and flag combination is not valid");
6223       static_assert(
6224         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::version_code::stored_type>(
6225           ColumnFlag::version_code),
6226         "Column type and flag combination is not valid");
6227     OnConstructionCompletedRegularConstructor(
6228       {id_storage_layer_,type_storage_layer_,package_name_storage_layer_,uid_storage_layer_,debuggable_storage_layer_,profileable_from_shell_storage_layer_,version_code_storage_layer_},
6229       {{},{},{},{},{},{},{}});
6230   }
6231   ~PackageListTable() override;
6232 
Name()6233   static const char* Name() { return "package_list"; }
6234 
ComputeStaticSchema()6235   static Table::Schema ComputeStaticSchema() {
6236     Table::Schema schema;
6237     schema.columns.emplace_back(Table::Schema::Column{
6238         "id", SqlValue::Type::kLong, true, true, false, false});
6239     schema.columns.emplace_back(Table::Schema::Column{
6240         "type", SqlValue::Type::kString, false, false, false, false});
6241     schema.columns.emplace_back(Table::Schema::Column{
6242         "package_name", ColumnType::package_name::SqlValueType(), false,
6243         false,
6244         false,
6245         false});
6246     schema.columns.emplace_back(Table::Schema::Column{
6247         "uid", ColumnType::uid::SqlValueType(), false,
6248         false,
6249         false,
6250         false});
6251     schema.columns.emplace_back(Table::Schema::Column{
6252         "debuggable", ColumnType::debuggable::SqlValueType(), false,
6253         false,
6254         false,
6255         false});
6256     schema.columns.emplace_back(Table::Schema::Column{
6257         "profileable_from_shell", ColumnType::profileable_from_shell::SqlValueType(), false,
6258         false,
6259         false,
6260         false});
6261     schema.columns.emplace_back(Table::Schema::Column{
6262         "version_code", ColumnType::version_code::SqlValueType(), false,
6263         false,
6264         false,
6265         false});
6266     return schema;
6267   }
6268 
IterateRows()6269   ConstIterator IterateRows() const {
6270     return ConstIterator(this, Table::IterateRows());
6271   }
6272 
IterateRows()6273   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
6274 
FilterToIterator(const Query & q)6275   ConstIterator FilterToIterator(const Query& q) const {
6276     return ConstIterator(this, QueryToIterator(q));
6277   }
6278 
FilterToIterator(const Query & q)6279   Iterator FilterToIterator(const Query& q) {
6280     return Iterator(this, QueryToIterator(q));
6281   }
6282 
ShrinkToFit()6283   void ShrinkToFit() {
6284     type_.ShrinkToFit();
6285     package_name_.ShrinkToFit();
6286     uid_.ShrinkToFit();
6287     debuggable_.ShrinkToFit();
6288     profileable_from_shell_.ShrinkToFit();
6289     version_code_.ShrinkToFit();
6290   }
6291 
6292   ConstRowReference operator[](uint32_t r) const {
6293     return ConstRowReference(this, r);
6294   }
6295   RowReference operator[](uint32_t r) { return RowReference(this, r); }
6296   ConstRowReference operator[](RowNumber r) const {
6297     return ConstRowReference(this, r.row_number());
6298   }
6299   RowReference operator[](RowNumber r) {
6300     return RowReference(this, r.row_number());
6301   }
6302 
FindById(Id find_id)6303   std::optional<ConstRowReference> FindById(Id find_id) const {
6304     std::optional<uint32_t> row = id().IndexOf(find_id);
6305     return row ? std::make_optional(ConstRowReference(this, *row))
6306                : std::nullopt;
6307   }
6308 
FindById(Id find_id)6309   std::optional<RowReference> FindById(Id find_id) {
6310     std::optional<uint32_t> row = id().IndexOf(find_id);
6311     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
6312   }
6313 
Insert(const Row & row)6314   IdAndRow Insert(const Row& row) {
6315     uint32_t row_number = row_count();
6316     Id id = Id{row_number};
6317     type_.Append(string_pool()->InternString(row.type()));
6318     mutable_package_name()->Append(row.package_name);
6319     mutable_uid()->Append(row.uid);
6320     mutable_debuggable()->Append(row.debuggable);
6321     mutable_profileable_from_shell()->Append(row.profileable_from_shell);
6322     mutable_version_code()->Append(row.version_code);
6323     UpdateSelfOverlayAfterInsert();
6324     return IdAndRow{id, row_number, RowReference(this, row_number),
6325                      RowNumber(row_number)};
6326   }
6327 
6328 
6329 
id()6330   const IdColumn<PackageListTable::Id>& id() const {
6331     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
6332   }
type()6333   const TypedColumn<StringPool::Id>& type() const {
6334     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
6335   }
package_name()6336   const TypedColumn<StringPool::Id>& package_name() const {
6337     return static_cast<const ColumnType::package_name&>(columns()[ColumnIndex::package_name]);
6338   }
uid()6339   const TypedColumn<int64_t>& uid() const {
6340     return static_cast<const ColumnType::uid&>(columns()[ColumnIndex::uid]);
6341   }
debuggable()6342   const TypedColumn<int32_t>& debuggable() const {
6343     return static_cast<const ColumnType::debuggable&>(columns()[ColumnIndex::debuggable]);
6344   }
profileable_from_shell()6345   const TypedColumn<int32_t>& profileable_from_shell() const {
6346     return static_cast<const ColumnType::profileable_from_shell&>(columns()[ColumnIndex::profileable_from_shell]);
6347   }
version_code()6348   const TypedColumn<int64_t>& version_code() const {
6349     return static_cast<const ColumnType::version_code&>(columns()[ColumnIndex::version_code]);
6350   }
6351 
mutable_package_name()6352   TypedColumn<StringPool::Id>* mutable_package_name() {
6353     return static_cast<ColumnType::package_name*>(
6354         GetColumn(ColumnIndex::package_name));
6355   }
mutable_uid()6356   TypedColumn<int64_t>* mutable_uid() {
6357     return static_cast<ColumnType::uid*>(
6358         GetColumn(ColumnIndex::uid));
6359   }
mutable_debuggable()6360   TypedColumn<int32_t>* mutable_debuggable() {
6361     return static_cast<ColumnType::debuggable*>(
6362         GetColumn(ColumnIndex::debuggable));
6363   }
mutable_profileable_from_shell()6364   TypedColumn<int32_t>* mutable_profileable_from_shell() {
6365     return static_cast<ColumnType::profileable_from_shell*>(
6366         GetColumn(ColumnIndex::profileable_from_shell));
6367   }
mutable_version_code()6368   TypedColumn<int64_t>* mutable_version_code() {
6369     return static_cast<ColumnType::version_code*>(
6370         GetColumn(ColumnIndex::version_code));
6371   }
6372 
6373  private:
6374 
6375 
6376   ColumnStorage<ColumnType::package_name::stored_type> package_name_;
6377   ColumnStorage<ColumnType::uid::stored_type> uid_;
6378   ColumnStorage<ColumnType::debuggable::stored_type> debuggable_;
6379   ColumnStorage<ColumnType::profileable_from_shell::stored_type> profileable_from_shell_;
6380   ColumnStorage<ColumnType::version_code::stored_type> version_code_;
6381 
6382   RefPtr<column::StorageLayer> id_storage_layer_;
6383   RefPtr<column::StorageLayer> type_storage_layer_;
6384   RefPtr<column::StorageLayer> package_name_storage_layer_;
6385   RefPtr<column::StorageLayer> uid_storage_layer_;
6386   RefPtr<column::StorageLayer> debuggable_storage_layer_;
6387   RefPtr<column::StorageLayer> profileable_from_shell_storage_layer_;
6388   RefPtr<column::StorageLayer> version_code_storage_layer_;
6389 
6390 
6391 };
6392 
6393 
6394 class PerfSessionTable : public macros_internal::MacroTable {
6395  public:
6396   static constexpr uint32_t kColumnCount = 3;
6397 
6398   struct Id : public BaseId {
6399     Id() = default;
IdId6400     explicit constexpr Id(uint32_t v) : BaseId(v) {}
6401   };
6402   static_assert(std::is_trivially_destructible_v<Id>,
6403                 "Inheritance used without trivial destruction");
6404 
6405   struct ColumnIndex {
6406     static constexpr uint32_t id = 0;
6407     static constexpr uint32_t type = 1;
6408     static constexpr uint32_t cmdline = 2;
6409   };
6410   struct ColumnType {
6411     using id = IdColumn<PerfSessionTable::Id>;
6412     using type = TypedColumn<StringPool::Id>;
6413     using cmdline = TypedColumn<std::optional<StringPool::Id>>;
6414   };
6415   struct Row : public macros_internal::RootParentTable::Row {
6416     Row(std::optional<StringPool::Id> in_cmdline = {},
6417         std::nullptr_t = nullptr)
RowRow6418         : macros_internal::RootParentTable::Row(),
6419           cmdline(in_cmdline) {
6420       type_ = "__intrinsic_perf_session";
6421     }
6422     std::optional<StringPool::Id> cmdline;
6423 
6424     bool operator==(const PerfSessionTable::Row& other) const {
6425       return type() == other.type() && ColumnType::cmdline::Equals(cmdline, other.cmdline);
6426     }
6427   };
6428   struct ColumnFlag {
6429     static constexpr uint32_t cmdline = ColumnType::cmdline::default_flags();
6430   };
6431 
6432   class RowNumber;
6433   class ConstRowReference;
6434   class RowReference;
6435 
6436   class RowNumber : public macros_internal::AbstractRowNumber<
6437       PerfSessionTable, ConstRowReference, RowReference> {
6438    public:
RowNumber(uint32_t row_number)6439     explicit RowNumber(uint32_t row_number)
6440         : AbstractRowNumber(row_number) {}
6441   };
6442   static_assert(std::is_trivially_destructible_v<RowNumber>,
6443                 "Inheritance used without trivial destruction");
6444 
6445   class ConstRowReference : public macros_internal::AbstractConstRowReference<
6446     PerfSessionTable, RowNumber> {
6447    public:
ConstRowReference(const PerfSessionTable * table,uint32_t row_number)6448     ConstRowReference(const PerfSessionTable* table, uint32_t row_number)
6449         : AbstractConstRowReference(table, row_number) {}
6450 
id()6451     ColumnType::id::type id() const {
6452       return table()->id()[row_number_];
6453     }
type()6454     ColumnType::type::type type() const {
6455       return table()->type()[row_number_];
6456     }
cmdline()6457     ColumnType::cmdline::type cmdline() const {
6458       return table()->cmdline()[row_number_];
6459     }
6460   };
6461   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
6462                 "Inheritance used without trivial destruction");
6463   class RowReference : public ConstRowReference {
6464    public:
RowReference(const PerfSessionTable * table,uint32_t row_number)6465     RowReference(const PerfSessionTable* table, uint32_t row_number)
6466         : ConstRowReference(table, row_number) {}
6467 
set_cmdline(ColumnType::cmdline::non_optional_type v)6468     void set_cmdline(
6469         ColumnType::cmdline::non_optional_type v) {
6470       return mutable_table()->mutable_cmdline()->Set(row_number_, v);
6471     }
6472 
6473    private:
mutable_table()6474     PerfSessionTable* mutable_table() const {
6475       return const_cast<PerfSessionTable*>(table());
6476     }
6477   };
6478   static_assert(std::is_trivially_destructible_v<RowReference>,
6479                 "Inheritance used without trivial destruction");
6480 
6481   class ConstIterator;
6482   class ConstIterator : public macros_internal::AbstractConstIterator<
6483     ConstIterator, PerfSessionTable, RowNumber, ConstRowReference> {
6484    public:
id()6485     ColumnType::id::type id() const {
6486       const auto& col = table()->id();
6487       return col.GetAtIdx(
6488         iterator_.StorageIndexForColumn(col.index_in_table()));
6489     }
type()6490     ColumnType::type::type type() const {
6491       const auto& col = table()->type();
6492       return col.GetAtIdx(
6493         iterator_.StorageIndexForColumn(col.index_in_table()));
6494     }
cmdline()6495     ColumnType::cmdline::type cmdline() const {
6496       const auto& col = table()->cmdline();
6497       return col.GetAtIdx(
6498         iterator_.StorageIndexForColumn(col.index_in_table()));
6499     }
6500 
6501    protected:
ConstIterator(const PerfSessionTable * table,Table::Iterator iterator)6502     explicit ConstIterator(const PerfSessionTable* table,
6503                            Table::Iterator iterator)
6504         : AbstractConstIterator(table, std::move(iterator)) {}
6505 
CurrentRowNumber()6506     uint32_t CurrentRowNumber() const {
6507       return iterator_.StorageIndexForLastOverlay();
6508     }
6509 
6510    private:
6511     friend class PerfSessionTable;
6512     friend class macros_internal::AbstractConstIterator<
6513       ConstIterator, PerfSessionTable, RowNumber, ConstRowReference>;
6514   };
6515   class Iterator : public ConstIterator {
6516     public:
row_reference()6517      RowReference row_reference() const {
6518        return {const_cast<PerfSessionTable*>(table()), CurrentRowNumber()};
6519      }
6520 
6521     private:
6522      friend class PerfSessionTable;
6523 
Iterator(PerfSessionTable * table,Table::Iterator iterator)6524      explicit Iterator(PerfSessionTable* table, Table::Iterator iterator)
6525         : ConstIterator(table, std::move(iterator)) {}
6526   };
6527 
6528   struct IdAndRow {
6529     Id id;
6530     uint32_t row;
6531     RowReference row_reference;
6532     RowNumber row_number;
6533   };
6534 
GetColumns(PerfSessionTable * self,const macros_internal::MacroTable * parent)6535   static std::vector<ColumnLegacy> GetColumns(
6536       PerfSessionTable* self,
6537       const macros_internal::MacroTable* parent) {
6538     std::vector<ColumnLegacy> columns =
6539         CopyColumnsFromParentOrAddRootColumns(self, parent);
6540     uint32_t olay_idx = OverlayCount(parent);
6541     AddColumnToVector(columns, "cmdline", &self->cmdline_, ColumnFlag::cmdline,
6542                       static_cast<uint32_t>(columns.size()), olay_idx);
6543     return columns;
6544   }
6545 
PerfSessionTable(StringPool * pool)6546   PERFETTO_NO_INLINE explicit PerfSessionTable(StringPool* pool)
6547       : macros_internal::MacroTable(
6548           pool,
6549           GetColumns(this, nullptr),
6550           nullptr),
6551         cmdline_(ColumnStorage<ColumnType::cmdline::stored_type>::Create<false>())
6552 ,
6553         id_storage_layer_(new column::IdStorage()),
6554         type_storage_layer_(
6555           new column::StringStorage(string_pool(), &type_.vector())),
6556         cmdline_storage_layer_(
6557           new column::StringStorage(string_pool(), &cmdline_.vector()))
6558          {
6559     static_assert(
6560         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cmdline::stored_type>(
6561           ColumnFlag::cmdline),
6562         "Column type and flag combination is not valid");
6563     OnConstructionCompletedRegularConstructor(
6564       {id_storage_layer_,type_storage_layer_,cmdline_storage_layer_},
6565       {{},{},{}});
6566   }
6567   ~PerfSessionTable() override;
6568 
Name()6569   static const char* Name() { return "__intrinsic_perf_session"; }
6570 
ComputeStaticSchema()6571   static Table::Schema ComputeStaticSchema() {
6572     Table::Schema schema;
6573     schema.columns.emplace_back(Table::Schema::Column{
6574         "id", SqlValue::Type::kLong, true, true, false, false});
6575     schema.columns.emplace_back(Table::Schema::Column{
6576         "type", SqlValue::Type::kString, false, false, false, false});
6577     schema.columns.emplace_back(Table::Schema::Column{
6578         "cmdline", ColumnType::cmdline::SqlValueType(), false,
6579         false,
6580         false,
6581         false});
6582     return schema;
6583   }
6584 
IterateRows()6585   ConstIterator IterateRows() const {
6586     return ConstIterator(this, Table::IterateRows());
6587   }
6588 
IterateRows()6589   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
6590 
FilterToIterator(const Query & q)6591   ConstIterator FilterToIterator(const Query& q) const {
6592     return ConstIterator(this, QueryToIterator(q));
6593   }
6594 
FilterToIterator(const Query & q)6595   Iterator FilterToIterator(const Query& q) {
6596     return Iterator(this, QueryToIterator(q));
6597   }
6598 
ShrinkToFit()6599   void ShrinkToFit() {
6600     type_.ShrinkToFit();
6601     cmdline_.ShrinkToFit();
6602   }
6603 
6604   ConstRowReference operator[](uint32_t r) const {
6605     return ConstRowReference(this, r);
6606   }
6607   RowReference operator[](uint32_t r) { return RowReference(this, r); }
6608   ConstRowReference operator[](RowNumber r) const {
6609     return ConstRowReference(this, r.row_number());
6610   }
6611   RowReference operator[](RowNumber r) {
6612     return RowReference(this, r.row_number());
6613   }
6614 
FindById(Id find_id)6615   std::optional<ConstRowReference> FindById(Id find_id) const {
6616     std::optional<uint32_t> row = id().IndexOf(find_id);
6617     return row ? std::make_optional(ConstRowReference(this, *row))
6618                : std::nullopt;
6619   }
6620 
FindById(Id find_id)6621   std::optional<RowReference> FindById(Id find_id) {
6622     std::optional<uint32_t> row = id().IndexOf(find_id);
6623     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
6624   }
6625 
Insert(const Row & row)6626   IdAndRow Insert(const Row& row) {
6627     uint32_t row_number = row_count();
6628     Id id = Id{row_number};
6629     type_.Append(string_pool()->InternString(row.type()));
6630     mutable_cmdline()->Append(row.cmdline);
6631     UpdateSelfOverlayAfterInsert();
6632     return IdAndRow{id, row_number, RowReference(this, row_number),
6633                      RowNumber(row_number)};
6634   }
6635 
6636 
6637 
id()6638   const IdColumn<PerfSessionTable::Id>& id() const {
6639     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
6640   }
type()6641   const TypedColumn<StringPool::Id>& type() const {
6642     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
6643   }
cmdline()6644   const TypedColumn<std::optional<StringPool::Id>>& cmdline() const {
6645     return static_cast<const ColumnType::cmdline&>(columns()[ColumnIndex::cmdline]);
6646   }
6647 
mutable_cmdline()6648   TypedColumn<std::optional<StringPool::Id>>* mutable_cmdline() {
6649     return static_cast<ColumnType::cmdline*>(
6650         GetColumn(ColumnIndex::cmdline));
6651   }
6652 
6653  private:
6654 
6655 
6656   ColumnStorage<ColumnType::cmdline::stored_type> cmdline_;
6657 
6658   RefPtr<column::StorageLayer> id_storage_layer_;
6659   RefPtr<column::StorageLayer> type_storage_layer_;
6660   RefPtr<column::StorageLayer> cmdline_storage_layer_;
6661 
6662 
6663 };
6664 
6665 
6666 class PerfSampleTable : public macros_internal::MacroTable {
6667  public:
6668   static constexpr uint32_t kColumnCount = 9;
6669 
6670   struct Id : public BaseId {
6671     Id() = default;
IdId6672     explicit constexpr Id(uint32_t v) : BaseId(v) {}
6673   };
6674   static_assert(std::is_trivially_destructible_v<Id>,
6675                 "Inheritance used without trivial destruction");
6676 
6677   struct ColumnIndex {
6678     static constexpr uint32_t id = 0;
6679     static constexpr uint32_t type = 1;
6680     static constexpr uint32_t ts = 2;
6681     static constexpr uint32_t utid = 3;
6682     static constexpr uint32_t cpu = 4;
6683     static constexpr uint32_t cpu_mode = 5;
6684     static constexpr uint32_t callsite_id = 6;
6685     static constexpr uint32_t unwind_error = 7;
6686     static constexpr uint32_t perf_session_id = 8;
6687   };
6688   struct ColumnType {
6689     using id = IdColumn<PerfSampleTable::Id>;
6690     using type = TypedColumn<StringPool::Id>;
6691     using ts = TypedColumn<int64_t>;
6692     using utid = TypedColumn<uint32_t>;
6693     using cpu = TypedColumn<std::optional<uint32_t>>;
6694     using cpu_mode = TypedColumn<StringPool::Id>;
6695     using callsite_id = TypedColumn<std::optional<StackProfileCallsiteTable::Id>>;
6696     using unwind_error = TypedColumn<std::optional<StringPool::Id>>;
6697     using perf_session_id = TypedColumn<PerfSessionTable::Id>;
6698   };
6699   struct Row : public macros_internal::RootParentTable::Row {
6700     Row(int64_t in_ts = {},
6701         uint32_t in_utid = {},
6702         std::optional<uint32_t> in_cpu = {},
6703         StringPool::Id in_cpu_mode = {},
6704         std::optional<StackProfileCallsiteTable::Id> in_callsite_id = {},
6705         std::optional<StringPool::Id> in_unwind_error = {},
6706         PerfSessionTable::Id in_perf_session_id = {},
6707         std::nullptr_t = nullptr)
RowRow6708         : macros_internal::RootParentTable::Row(),
6709           ts(in_ts),
6710           utid(in_utid),
6711           cpu(in_cpu),
6712           cpu_mode(in_cpu_mode),
6713           callsite_id(in_callsite_id),
6714           unwind_error(in_unwind_error),
6715           perf_session_id(in_perf_session_id) {
6716       type_ = "perf_sample";
6717     }
6718     int64_t ts;
6719     uint32_t utid;
6720     std::optional<uint32_t> cpu;
6721     StringPool::Id cpu_mode;
6722     std::optional<StackProfileCallsiteTable::Id> callsite_id;
6723     std::optional<StringPool::Id> unwind_error;
6724     PerfSessionTable::Id perf_session_id;
6725 
6726     bool operator==(const PerfSampleTable::Row& other) const {
6727       return type() == other.type() && ColumnType::ts::Equals(ts, other.ts) &&
6728        ColumnType::utid::Equals(utid, other.utid) &&
6729        ColumnType::cpu::Equals(cpu, other.cpu) &&
6730        ColumnType::cpu_mode::Equals(cpu_mode, other.cpu_mode) &&
6731        ColumnType::callsite_id::Equals(callsite_id, other.callsite_id) &&
6732        ColumnType::unwind_error::Equals(unwind_error, other.unwind_error) &&
6733        ColumnType::perf_session_id::Equals(perf_session_id, other.perf_session_id);
6734     }
6735   };
6736   struct ColumnFlag {
6737     static constexpr uint32_t ts = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted) | ColumnType::ts::default_flags();
6738     static constexpr uint32_t utid = ColumnType::utid::default_flags();
6739     static constexpr uint32_t cpu = ColumnType::cpu::default_flags();
6740     static constexpr uint32_t cpu_mode = ColumnType::cpu_mode::default_flags();
6741     static constexpr uint32_t callsite_id = ColumnType::callsite_id::default_flags();
6742     static constexpr uint32_t unwind_error = ColumnType::unwind_error::default_flags();
6743     static constexpr uint32_t perf_session_id = ColumnType::perf_session_id::default_flags();
6744   };
6745 
6746   class RowNumber;
6747   class ConstRowReference;
6748   class RowReference;
6749 
6750   class RowNumber : public macros_internal::AbstractRowNumber<
6751       PerfSampleTable, ConstRowReference, RowReference> {
6752    public:
RowNumber(uint32_t row_number)6753     explicit RowNumber(uint32_t row_number)
6754         : AbstractRowNumber(row_number) {}
6755   };
6756   static_assert(std::is_trivially_destructible_v<RowNumber>,
6757                 "Inheritance used without trivial destruction");
6758 
6759   class ConstRowReference : public macros_internal::AbstractConstRowReference<
6760     PerfSampleTable, RowNumber> {
6761    public:
ConstRowReference(const PerfSampleTable * table,uint32_t row_number)6762     ConstRowReference(const PerfSampleTable* table, uint32_t row_number)
6763         : AbstractConstRowReference(table, row_number) {}
6764 
id()6765     ColumnType::id::type id() const {
6766       return table()->id()[row_number_];
6767     }
type()6768     ColumnType::type::type type() const {
6769       return table()->type()[row_number_];
6770     }
ts()6771     ColumnType::ts::type ts() const {
6772       return table()->ts()[row_number_];
6773     }
utid()6774     ColumnType::utid::type utid() const {
6775       return table()->utid()[row_number_];
6776     }
cpu()6777     ColumnType::cpu::type cpu() const {
6778       return table()->cpu()[row_number_];
6779     }
cpu_mode()6780     ColumnType::cpu_mode::type cpu_mode() const {
6781       return table()->cpu_mode()[row_number_];
6782     }
callsite_id()6783     ColumnType::callsite_id::type callsite_id() const {
6784       return table()->callsite_id()[row_number_];
6785     }
unwind_error()6786     ColumnType::unwind_error::type unwind_error() const {
6787       return table()->unwind_error()[row_number_];
6788     }
perf_session_id()6789     ColumnType::perf_session_id::type perf_session_id() const {
6790       return table()->perf_session_id()[row_number_];
6791     }
6792   };
6793   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
6794                 "Inheritance used without trivial destruction");
6795   class RowReference : public ConstRowReference {
6796    public:
RowReference(const PerfSampleTable * table,uint32_t row_number)6797     RowReference(const PerfSampleTable* table, uint32_t row_number)
6798         : ConstRowReference(table, row_number) {}
6799 
set_ts(ColumnType::ts::non_optional_type v)6800     void set_ts(
6801         ColumnType::ts::non_optional_type v) {
6802       return mutable_table()->mutable_ts()->Set(row_number_, v);
6803     }
set_utid(ColumnType::utid::non_optional_type v)6804     void set_utid(
6805         ColumnType::utid::non_optional_type v) {
6806       return mutable_table()->mutable_utid()->Set(row_number_, v);
6807     }
set_cpu(ColumnType::cpu::non_optional_type v)6808     void set_cpu(
6809         ColumnType::cpu::non_optional_type v) {
6810       return mutable_table()->mutable_cpu()->Set(row_number_, v);
6811     }
set_cpu_mode(ColumnType::cpu_mode::non_optional_type v)6812     void set_cpu_mode(
6813         ColumnType::cpu_mode::non_optional_type v) {
6814       return mutable_table()->mutable_cpu_mode()->Set(row_number_, v);
6815     }
set_callsite_id(ColumnType::callsite_id::non_optional_type v)6816     void set_callsite_id(
6817         ColumnType::callsite_id::non_optional_type v) {
6818       return mutable_table()->mutable_callsite_id()->Set(row_number_, v);
6819     }
set_unwind_error(ColumnType::unwind_error::non_optional_type v)6820     void set_unwind_error(
6821         ColumnType::unwind_error::non_optional_type v) {
6822       return mutable_table()->mutable_unwind_error()->Set(row_number_, v);
6823     }
set_perf_session_id(ColumnType::perf_session_id::non_optional_type v)6824     void set_perf_session_id(
6825         ColumnType::perf_session_id::non_optional_type v) {
6826       return mutable_table()->mutable_perf_session_id()->Set(row_number_, v);
6827     }
6828 
6829    private:
mutable_table()6830     PerfSampleTable* mutable_table() const {
6831       return const_cast<PerfSampleTable*>(table());
6832     }
6833   };
6834   static_assert(std::is_trivially_destructible_v<RowReference>,
6835                 "Inheritance used without trivial destruction");
6836 
6837   class ConstIterator;
6838   class ConstIterator : public macros_internal::AbstractConstIterator<
6839     ConstIterator, PerfSampleTable, RowNumber, ConstRowReference> {
6840    public:
id()6841     ColumnType::id::type id() const {
6842       const auto& col = table()->id();
6843       return col.GetAtIdx(
6844         iterator_.StorageIndexForColumn(col.index_in_table()));
6845     }
type()6846     ColumnType::type::type type() const {
6847       const auto& col = table()->type();
6848       return col.GetAtIdx(
6849         iterator_.StorageIndexForColumn(col.index_in_table()));
6850     }
ts()6851     ColumnType::ts::type ts() const {
6852       const auto& col = table()->ts();
6853       return col.GetAtIdx(
6854         iterator_.StorageIndexForColumn(col.index_in_table()));
6855     }
utid()6856     ColumnType::utid::type utid() const {
6857       const auto& col = table()->utid();
6858       return col.GetAtIdx(
6859         iterator_.StorageIndexForColumn(col.index_in_table()));
6860     }
cpu()6861     ColumnType::cpu::type cpu() const {
6862       const auto& col = table()->cpu();
6863       return col.GetAtIdx(
6864         iterator_.StorageIndexForColumn(col.index_in_table()));
6865     }
cpu_mode()6866     ColumnType::cpu_mode::type cpu_mode() const {
6867       const auto& col = table()->cpu_mode();
6868       return col.GetAtIdx(
6869         iterator_.StorageIndexForColumn(col.index_in_table()));
6870     }
callsite_id()6871     ColumnType::callsite_id::type callsite_id() const {
6872       const auto& col = table()->callsite_id();
6873       return col.GetAtIdx(
6874         iterator_.StorageIndexForColumn(col.index_in_table()));
6875     }
unwind_error()6876     ColumnType::unwind_error::type unwind_error() const {
6877       const auto& col = table()->unwind_error();
6878       return col.GetAtIdx(
6879         iterator_.StorageIndexForColumn(col.index_in_table()));
6880     }
perf_session_id()6881     ColumnType::perf_session_id::type perf_session_id() const {
6882       const auto& col = table()->perf_session_id();
6883       return col.GetAtIdx(
6884         iterator_.StorageIndexForColumn(col.index_in_table()));
6885     }
6886 
6887    protected:
ConstIterator(const PerfSampleTable * table,Table::Iterator iterator)6888     explicit ConstIterator(const PerfSampleTable* table,
6889                            Table::Iterator iterator)
6890         : AbstractConstIterator(table, std::move(iterator)) {}
6891 
CurrentRowNumber()6892     uint32_t CurrentRowNumber() const {
6893       return iterator_.StorageIndexForLastOverlay();
6894     }
6895 
6896    private:
6897     friend class PerfSampleTable;
6898     friend class macros_internal::AbstractConstIterator<
6899       ConstIterator, PerfSampleTable, RowNumber, ConstRowReference>;
6900   };
6901   class Iterator : public ConstIterator {
6902     public:
row_reference()6903      RowReference row_reference() const {
6904        return {const_cast<PerfSampleTable*>(table()), CurrentRowNumber()};
6905      }
6906 
6907     private:
6908      friend class PerfSampleTable;
6909 
Iterator(PerfSampleTable * table,Table::Iterator iterator)6910      explicit Iterator(PerfSampleTable* table, Table::Iterator iterator)
6911         : ConstIterator(table, std::move(iterator)) {}
6912   };
6913 
6914   struct IdAndRow {
6915     Id id;
6916     uint32_t row;
6917     RowReference row_reference;
6918     RowNumber row_number;
6919   };
6920 
GetColumns(PerfSampleTable * self,const macros_internal::MacroTable * parent)6921   static std::vector<ColumnLegacy> GetColumns(
6922       PerfSampleTable* self,
6923       const macros_internal::MacroTable* parent) {
6924     std::vector<ColumnLegacy> columns =
6925         CopyColumnsFromParentOrAddRootColumns(self, parent);
6926     uint32_t olay_idx = OverlayCount(parent);
6927     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
6928                       static_cast<uint32_t>(columns.size()), olay_idx);
6929     AddColumnToVector(columns, "utid", &self->utid_, ColumnFlag::utid,
6930                       static_cast<uint32_t>(columns.size()), olay_idx);
6931     AddColumnToVector(columns, "cpu", &self->cpu_, ColumnFlag::cpu,
6932                       static_cast<uint32_t>(columns.size()), olay_idx);
6933     AddColumnToVector(columns, "cpu_mode", &self->cpu_mode_, ColumnFlag::cpu_mode,
6934                       static_cast<uint32_t>(columns.size()), olay_idx);
6935     AddColumnToVector(columns, "callsite_id", &self->callsite_id_, ColumnFlag::callsite_id,
6936                       static_cast<uint32_t>(columns.size()), olay_idx);
6937     AddColumnToVector(columns, "unwind_error", &self->unwind_error_, ColumnFlag::unwind_error,
6938                       static_cast<uint32_t>(columns.size()), olay_idx);
6939     AddColumnToVector(columns, "perf_session_id", &self->perf_session_id_, ColumnFlag::perf_session_id,
6940                       static_cast<uint32_t>(columns.size()), olay_idx);
6941     return columns;
6942   }
6943 
PerfSampleTable(StringPool * pool)6944   PERFETTO_NO_INLINE explicit PerfSampleTable(StringPool* pool)
6945       : macros_internal::MacroTable(
6946           pool,
6947           GetColumns(this, nullptr),
6948           nullptr),
6949         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
6950         utid_(ColumnStorage<ColumnType::utid::stored_type>::Create<false>()),
6951         cpu_(ColumnStorage<ColumnType::cpu::stored_type>::Create<false>()),
6952         cpu_mode_(ColumnStorage<ColumnType::cpu_mode::stored_type>::Create<false>()),
6953         callsite_id_(ColumnStorage<ColumnType::callsite_id::stored_type>::Create<false>()),
6954         unwind_error_(ColumnStorage<ColumnType::unwind_error::stored_type>::Create<false>()),
6955         perf_session_id_(ColumnStorage<ColumnType::perf_session_id::stored_type>::Create<false>())
6956 ,
6957         id_storage_layer_(new column::IdStorage()),
6958         type_storage_layer_(
6959           new column::StringStorage(string_pool(), &type_.vector())),
6960         ts_storage_layer_(
6961         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
6962           &ts_.vector(),
6963           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
6964           true)),
6965         utid_storage_layer_(
6966         new column::NumericStorage<ColumnType::utid::non_optional_stored_type>(
6967           &utid_.vector(),
6968           ColumnTypeHelper<ColumnType::utid::stored_type>::ToColumnType(),
6969           false)),
6970         cpu_storage_layer_(
6971           new column::NumericStorage<ColumnType::cpu::non_optional_stored_type>(
6972             &cpu_.non_null_vector(),
6973             ColumnTypeHelper<ColumnType::cpu::stored_type>::ToColumnType(),
6974             false)),
6975         cpu_mode_storage_layer_(
6976           new column::StringStorage(string_pool(), &cpu_mode_.vector())),
6977         callsite_id_storage_layer_(
6978           new column::NumericStorage<ColumnType::callsite_id::non_optional_stored_type>(
6979             &callsite_id_.non_null_vector(),
6980             ColumnTypeHelper<ColumnType::callsite_id::stored_type>::ToColumnType(),
6981             false)),
6982         unwind_error_storage_layer_(
6983           new column::StringStorage(string_pool(), &unwind_error_.vector())),
6984         perf_session_id_storage_layer_(
6985         new column::NumericStorage<ColumnType::perf_session_id::non_optional_stored_type>(
6986           &perf_session_id_.vector(),
6987           ColumnTypeHelper<ColumnType::perf_session_id::stored_type>::ToColumnType(),
6988           false))
6989 ,
6990         cpu_null_layer_(new column::NullOverlay(cpu_.bv())),
6991         callsite_id_null_layer_(new column::NullOverlay(callsite_id_.bv())) {
6992     static_assert(
6993         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
6994           ColumnFlag::ts),
6995         "Column type and flag combination is not valid");
6996       static_assert(
6997         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::utid::stored_type>(
6998           ColumnFlag::utid),
6999         "Column type and flag combination is not valid");
7000       static_assert(
7001         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cpu::stored_type>(
7002           ColumnFlag::cpu),
7003         "Column type and flag combination is not valid");
7004       static_assert(
7005         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cpu_mode::stored_type>(
7006           ColumnFlag::cpu_mode),
7007         "Column type and flag combination is not valid");
7008       static_assert(
7009         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::callsite_id::stored_type>(
7010           ColumnFlag::callsite_id),
7011         "Column type and flag combination is not valid");
7012       static_assert(
7013         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::unwind_error::stored_type>(
7014           ColumnFlag::unwind_error),
7015         "Column type and flag combination is not valid");
7016       static_assert(
7017         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::perf_session_id::stored_type>(
7018           ColumnFlag::perf_session_id),
7019         "Column type and flag combination is not valid");
7020     OnConstructionCompletedRegularConstructor(
7021       {id_storage_layer_,type_storage_layer_,ts_storage_layer_,utid_storage_layer_,cpu_storage_layer_,cpu_mode_storage_layer_,callsite_id_storage_layer_,unwind_error_storage_layer_,perf_session_id_storage_layer_},
7022       {{},{},{},{},cpu_null_layer_,{},callsite_id_null_layer_,{},{}});
7023   }
7024   ~PerfSampleTable() override;
7025 
Name()7026   static const char* Name() { return "perf_sample"; }
7027 
ComputeStaticSchema()7028   static Table::Schema ComputeStaticSchema() {
7029     Table::Schema schema;
7030     schema.columns.emplace_back(Table::Schema::Column{
7031         "id", SqlValue::Type::kLong, true, true, false, false});
7032     schema.columns.emplace_back(Table::Schema::Column{
7033         "type", SqlValue::Type::kString, false, false, false, false});
7034     schema.columns.emplace_back(Table::Schema::Column{
7035         "ts", ColumnType::ts::SqlValueType(), false,
7036         true,
7037         false,
7038         false});
7039     schema.columns.emplace_back(Table::Schema::Column{
7040         "utid", ColumnType::utid::SqlValueType(), false,
7041         false,
7042         false,
7043         false});
7044     schema.columns.emplace_back(Table::Schema::Column{
7045         "cpu", ColumnType::cpu::SqlValueType(), false,
7046         false,
7047         false,
7048         false});
7049     schema.columns.emplace_back(Table::Schema::Column{
7050         "cpu_mode", ColumnType::cpu_mode::SqlValueType(), false,
7051         false,
7052         false,
7053         false});
7054     schema.columns.emplace_back(Table::Schema::Column{
7055         "callsite_id", ColumnType::callsite_id::SqlValueType(), false,
7056         false,
7057         false,
7058         false});
7059     schema.columns.emplace_back(Table::Schema::Column{
7060         "unwind_error", ColumnType::unwind_error::SqlValueType(), false,
7061         false,
7062         false,
7063         false});
7064     schema.columns.emplace_back(Table::Schema::Column{
7065         "perf_session_id", ColumnType::perf_session_id::SqlValueType(), false,
7066         false,
7067         false,
7068         false});
7069     return schema;
7070   }
7071 
IterateRows()7072   ConstIterator IterateRows() const {
7073     return ConstIterator(this, Table::IterateRows());
7074   }
7075 
IterateRows()7076   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
7077 
FilterToIterator(const Query & q)7078   ConstIterator FilterToIterator(const Query& q) const {
7079     return ConstIterator(this, QueryToIterator(q));
7080   }
7081 
FilterToIterator(const Query & q)7082   Iterator FilterToIterator(const Query& q) {
7083     return Iterator(this, QueryToIterator(q));
7084   }
7085 
ShrinkToFit()7086   void ShrinkToFit() {
7087     type_.ShrinkToFit();
7088     ts_.ShrinkToFit();
7089     utid_.ShrinkToFit();
7090     cpu_.ShrinkToFit();
7091     cpu_mode_.ShrinkToFit();
7092     callsite_id_.ShrinkToFit();
7093     unwind_error_.ShrinkToFit();
7094     perf_session_id_.ShrinkToFit();
7095   }
7096 
7097   ConstRowReference operator[](uint32_t r) const {
7098     return ConstRowReference(this, r);
7099   }
7100   RowReference operator[](uint32_t r) { return RowReference(this, r); }
7101   ConstRowReference operator[](RowNumber r) const {
7102     return ConstRowReference(this, r.row_number());
7103   }
7104   RowReference operator[](RowNumber r) {
7105     return RowReference(this, r.row_number());
7106   }
7107 
FindById(Id find_id)7108   std::optional<ConstRowReference> FindById(Id find_id) const {
7109     std::optional<uint32_t> row = id().IndexOf(find_id);
7110     return row ? std::make_optional(ConstRowReference(this, *row))
7111                : std::nullopt;
7112   }
7113 
FindById(Id find_id)7114   std::optional<RowReference> FindById(Id find_id) {
7115     std::optional<uint32_t> row = id().IndexOf(find_id);
7116     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
7117   }
7118 
Insert(const Row & row)7119   IdAndRow Insert(const Row& row) {
7120     uint32_t row_number = row_count();
7121     Id id = Id{row_number};
7122     type_.Append(string_pool()->InternString(row.type()));
7123     mutable_ts()->Append(row.ts);
7124     mutable_utid()->Append(row.utid);
7125     mutable_cpu()->Append(row.cpu);
7126     mutable_cpu_mode()->Append(row.cpu_mode);
7127     mutable_callsite_id()->Append(row.callsite_id);
7128     mutable_unwind_error()->Append(row.unwind_error);
7129     mutable_perf_session_id()->Append(row.perf_session_id);
7130     UpdateSelfOverlayAfterInsert();
7131     return IdAndRow{id, row_number, RowReference(this, row_number),
7132                      RowNumber(row_number)};
7133   }
7134 
7135 
7136 
id()7137   const IdColumn<PerfSampleTable::Id>& id() const {
7138     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
7139   }
type()7140   const TypedColumn<StringPool::Id>& type() const {
7141     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
7142   }
ts()7143   const TypedColumn<int64_t>& ts() const {
7144     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
7145   }
utid()7146   const TypedColumn<uint32_t>& utid() const {
7147     return static_cast<const ColumnType::utid&>(columns()[ColumnIndex::utid]);
7148   }
cpu()7149   const TypedColumn<std::optional<uint32_t>>& cpu() const {
7150     return static_cast<const ColumnType::cpu&>(columns()[ColumnIndex::cpu]);
7151   }
cpu_mode()7152   const TypedColumn<StringPool::Id>& cpu_mode() const {
7153     return static_cast<const ColumnType::cpu_mode&>(columns()[ColumnIndex::cpu_mode]);
7154   }
callsite_id()7155   const TypedColumn<std::optional<StackProfileCallsiteTable::Id>>& callsite_id() const {
7156     return static_cast<const ColumnType::callsite_id&>(columns()[ColumnIndex::callsite_id]);
7157   }
unwind_error()7158   const TypedColumn<std::optional<StringPool::Id>>& unwind_error() const {
7159     return static_cast<const ColumnType::unwind_error&>(columns()[ColumnIndex::unwind_error]);
7160   }
perf_session_id()7161   const TypedColumn<PerfSessionTable::Id>& perf_session_id() const {
7162     return static_cast<const ColumnType::perf_session_id&>(columns()[ColumnIndex::perf_session_id]);
7163   }
7164 
mutable_ts()7165   TypedColumn<int64_t>* mutable_ts() {
7166     return static_cast<ColumnType::ts*>(
7167         GetColumn(ColumnIndex::ts));
7168   }
mutable_utid()7169   TypedColumn<uint32_t>* mutable_utid() {
7170     return static_cast<ColumnType::utid*>(
7171         GetColumn(ColumnIndex::utid));
7172   }
mutable_cpu()7173   TypedColumn<std::optional<uint32_t>>* mutable_cpu() {
7174     return static_cast<ColumnType::cpu*>(
7175         GetColumn(ColumnIndex::cpu));
7176   }
mutable_cpu_mode()7177   TypedColumn<StringPool::Id>* mutable_cpu_mode() {
7178     return static_cast<ColumnType::cpu_mode*>(
7179         GetColumn(ColumnIndex::cpu_mode));
7180   }
mutable_callsite_id()7181   TypedColumn<std::optional<StackProfileCallsiteTable::Id>>* mutable_callsite_id() {
7182     return static_cast<ColumnType::callsite_id*>(
7183         GetColumn(ColumnIndex::callsite_id));
7184   }
mutable_unwind_error()7185   TypedColumn<std::optional<StringPool::Id>>* mutable_unwind_error() {
7186     return static_cast<ColumnType::unwind_error*>(
7187         GetColumn(ColumnIndex::unwind_error));
7188   }
mutable_perf_session_id()7189   TypedColumn<PerfSessionTable::Id>* mutable_perf_session_id() {
7190     return static_cast<ColumnType::perf_session_id*>(
7191         GetColumn(ColumnIndex::perf_session_id));
7192   }
7193 
7194  private:
7195 
7196 
7197   ColumnStorage<ColumnType::ts::stored_type> ts_;
7198   ColumnStorage<ColumnType::utid::stored_type> utid_;
7199   ColumnStorage<ColumnType::cpu::stored_type> cpu_;
7200   ColumnStorage<ColumnType::cpu_mode::stored_type> cpu_mode_;
7201   ColumnStorage<ColumnType::callsite_id::stored_type> callsite_id_;
7202   ColumnStorage<ColumnType::unwind_error::stored_type> unwind_error_;
7203   ColumnStorage<ColumnType::perf_session_id::stored_type> perf_session_id_;
7204 
7205   RefPtr<column::StorageLayer> id_storage_layer_;
7206   RefPtr<column::StorageLayer> type_storage_layer_;
7207   RefPtr<column::StorageLayer> ts_storage_layer_;
7208   RefPtr<column::StorageLayer> utid_storage_layer_;
7209   RefPtr<column::StorageLayer> cpu_storage_layer_;
7210   RefPtr<column::StorageLayer> cpu_mode_storage_layer_;
7211   RefPtr<column::StorageLayer> callsite_id_storage_layer_;
7212   RefPtr<column::StorageLayer> unwind_error_storage_layer_;
7213   RefPtr<column::StorageLayer> perf_session_id_storage_layer_;
7214 
7215   RefPtr<column::OverlayLayer> cpu_null_layer_;
7216   RefPtr<column::OverlayLayer> callsite_id_null_layer_;
7217 };
7218 
7219 
7220 class ProfilerSmapsTable : public macros_internal::MacroTable {
7221  public:
7222   static constexpr uint32_t kColumnCount = 19;
7223 
7224   struct Id : public BaseId {
7225     Id() = default;
IdId7226     explicit constexpr Id(uint32_t v) : BaseId(v) {}
7227   };
7228   static_assert(std::is_trivially_destructible_v<Id>,
7229                 "Inheritance used without trivial destruction");
7230 
7231   struct ColumnIndex {
7232     static constexpr uint32_t id = 0;
7233     static constexpr uint32_t type = 1;
7234     static constexpr uint32_t upid = 2;
7235     static constexpr uint32_t ts = 3;
7236     static constexpr uint32_t path = 4;
7237     static constexpr uint32_t size_kb = 5;
7238     static constexpr uint32_t private_dirty_kb = 6;
7239     static constexpr uint32_t swap_kb = 7;
7240     static constexpr uint32_t file_name = 8;
7241     static constexpr uint32_t start_address = 9;
7242     static constexpr uint32_t module_timestamp = 10;
7243     static constexpr uint32_t module_debugid = 11;
7244     static constexpr uint32_t module_debug_path = 12;
7245     static constexpr uint32_t protection_flags = 13;
7246     static constexpr uint32_t private_clean_resident_kb = 14;
7247     static constexpr uint32_t shared_dirty_resident_kb = 15;
7248     static constexpr uint32_t shared_clean_resident_kb = 16;
7249     static constexpr uint32_t locked_kb = 17;
7250     static constexpr uint32_t proportional_resident_kb = 18;
7251   };
7252   struct ColumnType {
7253     using id = IdColumn<ProfilerSmapsTable::Id>;
7254     using type = TypedColumn<StringPool::Id>;
7255     using upid = TypedColumn<uint32_t>;
7256     using ts = TypedColumn<int64_t>;
7257     using path = TypedColumn<StringPool::Id>;
7258     using size_kb = TypedColumn<int64_t>;
7259     using private_dirty_kb = TypedColumn<int64_t>;
7260     using swap_kb = TypedColumn<int64_t>;
7261     using file_name = TypedColumn<StringPool::Id>;
7262     using start_address = TypedColumn<int64_t>;
7263     using module_timestamp = TypedColumn<int64_t>;
7264     using module_debugid = TypedColumn<StringPool::Id>;
7265     using module_debug_path = TypedColumn<StringPool::Id>;
7266     using protection_flags = TypedColumn<int64_t>;
7267     using private_clean_resident_kb = TypedColumn<int64_t>;
7268     using shared_dirty_resident_kb = TypedColumn<int64_t>;
7269     using shared_clean_resident_kb = TypedColumn<int64_t>;
7270     using locked_kb = TypedColumn<int64_t>;
7271     using proportional_resident_kb = TypedColumn<int64_t>;
7272   };
7273   struct Row : public macros_internal::RootParentTable::Row {
7274     Row(uint32_t in_upid = {},
7275         int64_t in_ts = {},
7276         StringPool::Id in_path = {},
7277         int64_t in_size_kb = {},
7278         int64_t in_private_dirty_kb = {},
7279         int64_t in_swap_kb = {},
7280         StringPool::Id in_file_name = {},
7281         int64_t in_start_address = {},
7282         int64_t in_module_timestamp = {},
7283         StringPool::Id in_module_debugid = {},
7284         StringPool::Id in_module_debug_path = {},
7285         int64_t in_protection_flags = {},
7286         int64_t in_private_clean_resident_kb = {},
7287         int64_t in_shared_dirty_resident_kb = {},
7288         int64_t in_shared_clean_resident_kb = {},
7289         int64_t in_locked_kb = {},
7290         int64_t in_proportional_resident_kb = {},
7291         std::nullptr_t = nullptr)
RowRow7292         : macros_internal::RootParentTable::Row(),
7293           upid(in_upid),
7294           ts(in_ts),
7295           path(in_path),
7296           size_kb(in_size_kb),
7297           private_dirty_kb(in_private_dirty_kb),
7298           swap_kb(in_swap_kb),
7299           file_name(in_file_name),
7300           start_address(in_start_address),
7301           module_timestamp(in_module_timestamp),
7302           module_debugid(in_module_debugid),
7303           module_debug_path(in_module_debug_path),
7304           protection_flags(in_protection_flags),
7305           private_clean_resident_kb(in_private_clean_resident_kb),
7306           shared_dirty_resident_kb(in_shared_dirty_resident_kb),
7307           shared_clean_resident_kb(in_shared_clean_resident_kb),
7308           locked_kb(in_locked_kb),
7309           proportional_resident_kb(in_proportional_resident_kb) {
7310       type_ = "profiler_smaps";
7311     }
7312     uint32_t upid;
7313     int64_t ts;
7314     StringPool::Id path;
7315     int64_t size_kb;
7316     int64_t private_dirty_kb;
7317     int64_t swap_kb;
7318     StringPool::Id file_name;
7319     int64_t start_address;
7320     int64_t module_timestamp;
7321     StringPool::Id module_debugid;
7322     StringPool::Id module_debug_path;
7323     int64_t protection_flags;
7324     int64_t private_clean_resident_kb;
7325     int64_t shared_dirty_resident_kb;
7326     int64_t shared_clean_resident_kb;
7327     int64_t locked_kb;
7328     int64_t proportional_resident_kb;
7329 
7330     bool operator==(const ProfilerSmapsTable::Row& other) const {
7331       return type() == other.type() && ColumnType::upid::Equals(upid, other.upid) &&
7332        ColumnType::ts::Equals(ts, other.ts) &&
7333        ColumnType::path::Equals(path, other.path) &&
7334        ColumnType::size_kb::Equals(size_kb, other.size_kb) &&
7335        ColumnType::private_dirty_kb::Equals(private_dirty_kb, other.private_dirty_kb) &&
7336        ColumnType::swap_kb::Equals(swap_kb, other.swap_kb) &&
7337        ColumnType::file_name::Equals(file_name, other.file_name) &&
7338        ColumnType::start_address::Equals(start_address, other.start_address) &&
7339        ColumnType::module_timestamp::Equals(module_timestamp, other.module_timestamp) &&
7340        ColumnType::module_debugid::Equals(module_debugid, other.module_debugid) &&
7341        ColumnType::module_debug_path::Equals(module_debug_path, other.module_debug_path) &&
7342        ColumnType::protection_flags::Equals(protection_flags, other.protection_flags) &&
7343        ColumnType::private_clean_resident_kb::Equals(private_clean_resident_kb, other.private_clean_resident_kb) &&
7344        ColumnType::shared_dirty_resident_kb::Equals(shared_dirty_resident_kb, other.shared_dirty_resident_kb) &&
7345        ColumnType::shared_clean_resident_kb::Equals(shared_clean_resident_kb, other.shared_clean_resident_kb) &&
7346        ColumnType::locked_kb::Equals(locked_kb, other.locked_kb) &&
7347        ColumnType::proportional_resident_kb::Equals(proportional_resident_kb, other.proportional_resident_kb);
7348     }
7349   };
7350   struct ColumnFlag {
7351     static constexpr uint32_t upid = ColumnType::upid::default_flags();
7352     static constexpr uint32_t ts = ColumnType::ts::default_flags();
7353     static constexpr uint32_t path = ColumnType::path::default_flags();
7354     static constexpr uint32_t size_kb = ColumnType::size_kb::default_flags();
7355     static constexpr uint32_t private_dirty_kb = ColumnType::private_dirty_kb::default_flags();
7356     static constexpr uint32_t swap_kb = ColumnType::swap_kb::default_flags();
7357     static constexpr uint32_t file_name = ColumnType::file_name::default_flags();
7358     static constexpr uint32_t start_address = ColumnType::start_address::default_flags();
7359     static constexpr uint32_t module_timestamp = ColumnType::module_timestamp::default_flags();
7360     static constexpr uint32_t module_debugid = ColumnType::module_debugid::default_flags();
7361     static constexpr uint32_t module_debug_path = ColumnType::module_debug_path::default_flags();
7362     static constexpr uint32_t protection_flags = ColumnType::protection_flags::default_flags();
7363     static constexpr uint32_t private_clean_resident_kb = ColumnType::private_clean_resident_kb::default_flags();
7364     static constexpr uint32_t shared_dirty_resident_kb = ColumnType::shared_dirty_resident_kb::default_flags();
7365     static constexpr uint32_t shared_clean_resident_kb = ColumnType::shared_clean_resident_kb::default_flags();
7366     static constexpr uint32_t locked_kb = ColumnType::locked_kb::default_flags();
7367     static constexpr uint32_t proportional_resident_kb = ColumnType::proportional_resident_kb::default_flags();
7368   };
7369 
7370   class RowNumber;
7371   class ConstRowReference;
7372   class RowReference;
7373 
7374   class RowNumber : public macros_internal::AbstractRowNumber<
7375       ProfilerSmapsTable, ConstRowReference, RowReference> {
7376    public:
RowNumber(uint32_t row_number)7377     explicit RowNumber(uint32_t row_number)
7378         : AbstractRowNumber(row_number) {}
7379   };
7380   static_assert(std::is_trivially_destructible_v<RowNumber>,
7381                 "Inheritance used without trivial destruction");
7382 
7383   class ConstRowReference : public macros_internal::AbstractConstRowReference<
7384     ProfilerSmapsTable, RowNumber> {
7385    public:
ConstRowReference(const ProfilerSmapsTable * table,uint32_t row_number)7386     ConstRowReference(const ProfilerSmapsTable* table, uint32_t row_number)
7387         : AbstractConstRowReference(table, row_number) {}
7388 
id()7389     ColumnType::id::type id() const {
7390       return table()->id()[row_number_];
7391     }
type()7392     ColumnType::type::type type() const {
7393       return table()->type()[row_number_];
7394     }
upid()7395     ColumnType::upid::type upid() const {
7396       return table()->upid()[row_number_];
7397     }
ts()7398     ColumnType::ts::type ts() const {
7399       return table()->ts()[row_number_];
7400     }
path()7401     ColumnType::path::type path() const {
7402       return table()->path()[row_number_];
7403     }
size_kb()7404     ColumnType::size_kb::type size_kb() const {
7405       return table()->size_kb()[row_number_];
7406     }
private_dirty_kb()7407     ColumnType::private_dirty_kb::type private_dirty_kb() const {
7408       return table()->private_dirty_kb()[row_number_];
7409     }
swap_kb()7410     ColumnType::swap_kb::type swap_kb() const {
7411       return table()->swap_kb()[row_number_];
7412     }
file_name()7413     ColumnType::file_name::type file_name() const {
7414       return table()->file_name()[row_number_];
7415     }
start_address()7416     ColumnType::start_address::type start_address() const {
7417       return table()->start_address()[row_number_];
7418     }
module_timestamp()7419     ColumnType::module_timestamp::type module_timestamp() const {
7420       return table()->module_timestamp()[row_number_];
7421     }
module_debugid()7422     ColumnType::module_debugid::type module_debugid() const {
7423       return table()->module_debugid()[row_number_];
7424     }
module_debug_path()7425     ColumnType::module_debug_path::type module_debug_path() const {
7426       return table()->module_debug_path()[row_number_];
7427     }
protection_flags()7428     ColumnType::protection_flags::type protection_flags() const {
7429       return table()->protection_flags()[row_number_];
7430     }
private_clean_resident_kb()7431     ColumnType::private_clean_resident_kb::type private_clean_resident_kb() const {
7432       return table()->private_clean_resident_kb()[row_number_];
7433     }
shared_dirty_resident_kb()7434     ColumnType::shared_dirty_resident_kb::type shared_dirty_resident_kb() const {
7435       return table()->shared_dirty_resident_kb()[row_number_];
7436     }
shared_clean_resident_kb()7437     ColumnType::shared_clean_resident_kb::type shared_clean_resident_kb() const {
7438       return table()->shared_clean_resident_kb()[row_number_];
7439     }
locked_kb()7440     ColumnType::locked_kb::type locked_kb() const {
7441       return table()->locked_kb()[row_number_];
7442     }
proportional_resident_kb()7443     ColumnType::proportional_resident_kb::type proportional_resident_kb() const {
7444       return table()->proportional_resident_kb()[row_number_];
7445     }
7446   };
7447   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
7448                 "Inheritance used without trivial destruction");
7449   class RowReference : public ConstRowReference {
7450    public:
RowReference(const ProfilerSmapsTable * table,uint32_t row_number)7451     RowReference(const ProfilerSmapsTable* table, uint32_t row_number)
7452         : ConstRowReference(table, row_number) {}
7453 
set_upid(ColumnType::upid::non_optional_type v)7454     void set_upid(
7455         ColumnType::upid::non_optional_type v) {
7456       return mutable_table()->mutable_upid()->Set(row_number_, v);
7457     }
set_ts(ColumnType::ts::non_optional_type v)7458     void set_ts(
7459         ColumnType::ts::non_optional_type v) {
7460       return mutable_table()->mutable_ts()->Set(row_number_, v);
7461     }
set_path(ColumnType::path::non_optional_type v)7462     void set_path(
7463         ColumnType::path::non_optional_type v) {
7464       return mutable_table()->mutable_path()->Set(row_number_, v);
7465     }
set_size_kb(ColumnType::size_kb::non_optional_type v)7466     void set_size_kb(
7467         ColumnType::size_kb::non_optional_type v) {
7468       return mutable_table()->mutable_size_kb()->Set(row_number_, v);
7469     }
set_private_dirty_kb(ColumnType::private_dirty_kb::non_optional_type v)7470     void set_private_dirty_kb(
7471         ColumnType::private_dirty_kb::non_optional_type v) {
7472       return mutable_table()->mutable_private_dirty_kb()->Set(row_number_, v);
7473     }
set_swap_kb(ColumnType::swap_kb::non_optional_type v)7474     void set_swap_kb(
7475         ColumnType::swap_kb::non_optional_type v) {
7476       return mutable_table()->mutable_swap_kb()->Set(row_number_, v);
7477     }
set_file_name(ColumnType::file_name::non_optional_type v)7478     void set_file_name(
7479         ColumnType::file_name::non_optional_type v) {
7480       return mutable_table()->mutable_file_name()->Set(row_number_, v);
7481     }
set_start_address(ColumnType::start_address::non_optional_type v)7482     void set_start_address(
7483         ColumnType::start_address::non_optional_type v) {
7484       return mutable_table()->mutable_start_address()->Set(row_number_, v);
7485     }
set_module_timestamp(ColumnType::module_timestamp::non_optional_type v)7486     void set_module_timestamp(
7487         ColumnType::module_timestamp::non_optional_type v) {
7488       return mutable_table()->mutable_module_timestamp()->Set(row_number_, v);
7489     }
set_module_debugid(ColumnType::module_debugid::non_optional_type v)7490     void set_module_debugid(
7491         ColumnType::module_debugid::non_optional_type v) {
7492       return mutable_table()->mutable_module_debugid()->Set(row_number_, v);
7493     }
set_module_debug_path(ColumnType::module_debug_path::non_optional_type v)7494     void set_module_debug_path(
7495         ColumnType::module_debug_path::non_optional_type v) {
7496       return mutable_table()->mutable_module_debug_path()->Set(row_number_, v);
7497     }
set_protection_flags(ColumnType::protection_flags::non_optional_type v)7498     void set_protection_flags(
7499         ColumnType::protection_flags::non_optional_type v) {
7500       return mutable_table()->mutable_protection_flags()->Set(row_number_, v);
7501     }
set_private_clean_resident_kb(ColumnType::private_clean_resident_kb::non_optional_type v)7502     void set_private_clean_resident_kb(
7503         ColumnType::private_clean_resident_kb::non_optional_type v) {
7504       return mutable_table()->mutable_private_clean_resident_kb()->Set(row_number_, v);
7505     }
set_shared_dirty_resident_kb(ColumnType::shared_dirty_resident_kb::non_optional_type v)7506     void set_shared_dirty_resident_kb(
7507         ColumnType::shared_dirty_resident_kb::non_optional_type v) {
7508       return mutable_table()->mutable_shared_dirty_resident_kb()->Set(row_number_, v);
7509     }
set_shared_clean_resident_kb(ColumnType::shared_clean_resident_kb::non_optional_type v)7510     void set_shared_clean_resident_kb(
7511         ColumnType::shared_clean_resident_kb::non_optional_type v) {
7512       return mutable_table()->mutable_shared_clean_resident_kb()->Set(row_number_, v);
7513     }
set_locked_kb(ColumnType::locked_kb::non_optional_type v)7514     void set_locked_kb(
7515         ColumnType::locked_kb::non_optional_type v) {
7516       return mutable_table()->mutable_locked_kb()->Set(row_number_, v);
7517     }
set_proportional_resident_kb(ColumnType::proportional_resident_kb::non_optional_type v)7518     void set_proportional_resident_kb(
7519         ColumnType::proportional_resident_kb::non_optional_type v) {
7520       return mutable_table()->mutable_proportional_resident_kb()->Set(row_number_, v);
7521     }
7522 
7523    private:
mutable_table()7524     ProfilerSmapsTable* mutable_table() const {
7525       return const_cast<ProfilerSmapsTable*>(table());
7526     }
7527   };
7528   static_assert(std::is_trivially_destructible_v<RowReference>,
7529                 "Inheritance used without trivial destruction");
7530 
7531   class ConstIterator;
7532   class ConstIterator : public macros_internal::AbstractConstIterator<
7533     ConstIterator, ProfilerSmapsTable, RowNumber, ConstRowReference> {
7534    public:
id()7535     ColumnType::id::type id() const {
7536       const auto& col = table()->id();
7537       return col.GetAtIdx(
7538         iterator_.StorageIndexForColumn(col.index_in_table()));
7539     }
type()7540     ColumnType::type::type type() const {
7541       const auto& col = table()->type();
7542       return col.GetAtIdx(
7543         iterator_.StorageIndexForColumn(col.index_in_table()));
7544     }
upid()7545     ColumnType::upid::type upid() const {
7546       const auto& col = table()->upid();
7547       return col.GetAtIdx(
7548         iterator_.StorageIndexForColumn(col.index_in_table()));
7549     }
ts()7550     ColumnType::ts::type ts() const {
7551       const auto& col = table()->ts();
7552       return col.GetAtIdx(
7553         iterator_.StorageIndexForColumn(col.index_in_table()));
7554     }
path()7555     ColumnType::path::type path() const {
7556       const auto& col = table()->path();
7557       return col.GetAtIdx(
7558         iterator_.StorageIndexForColumn(col.index_in_table()));
7559     }
size_kb()7560     ColumnType::size_kb::type size_kb() const {
7561       const auto& col = table()->size_kb();
7562       return col.GetAtIdx(
7563         iterator_.StorageIndexForColumn(col.index_in_table()));
7564     }
private_dirty_kb()7565     ColumnType::private_dirty_kb::type private_dirty_kb() const {
7566       const auto& col = table()->private_dirty_kb();
7567       return col.GetAtIdx(
7568         iterator_.StorageIndexForColumn(col.index_in_table()));
7569     }
swap_kb()7570     ColumnType::swap_kb::type swap_kb() const {
7571       const auto& col = table()->swap_kb();
7572       return col.GetAtIdx(
7573         iterator_.StorageIndexForColumn(col.index_in_table()));
7574     }
file_name()7575     ColumnType::file_name::type file_name() const {
7576       const auto& col = table()->file_name();
7577       return col.GetAtIdx(
7578         iterator_.StorageIndexForColumn(col.index_in_table()));
7579     }
start_address()7580     ColumnType::start_address::type start_address() const {
7581       const auto& col = table()->start_address();
7582       return col.GetAtIdx(
7583         iterator_.StorageIndexForColumn(col.index_in_table()));
7584     }
module_timestamp()7585     ColumnType::module_timestamp::type module_timestamp() const {
7586       const auto& col = table()->module_timestamp();
7587       return col.GetAtIdx(
7588         iterator_.StorageIndexForColumn(col.index_in_table()));
7589     }
module_debugid()7590     ColumnType::module_debugid::type module_debugid() const {
7591       const auto& col = table()->module_debugid();
7592       return col.GetAtIdx(
7593         iterator_.StorageIndexForColumn(col.index_in_table()));
7594     }
module_debug_path()7595     ColumnType::module_debug_path::type module_debug_path() const {
7596       const auto& col = table()->module_debug_path();
7597       return col.GetAtIdx(
7598         iterator_.StorageIndexForColumn(col.index_in_table()));
7599     }
protection_flags()7600     ColumnType::protection_flags::type protection_flags() const {
7601       const auto& col = table()->protection_flags();
7602       return col.GetAtIdx(
7603         iterator_.StorageIndexForColumn(col.index_in_table()));
7604     }
private_clean_resident_kb()7605     ColumnType::private_clean_resident_kb::type private_clean_resident_kb() const {
7606       const auto& col = table()->private_clean_resident_kb();
7607       return col.GetAtIdx(
7608         iterator_.StorageIndexForColumn(col.index_in_table()));
7609     }
shared_dirty_resident_kb()7610     ColumnType::shared_dirty_resident_kb::type shared_dirty_resident_kb() const {
7611       const auto& col = table()->shared_dirty_resident_kb();
7612       return col.GetAtIdx(
7613         iterator_.StorageIndexForColumn(col.index_in_table()));
7614     }
shared_clean_resident_kb()7615     ColumnType::shared_clean_resident_kb::type shared_clean_resident_kb() const {
7616       const auto& col = table()->shared_clean_resident_kb();
7617       return col.GetAtIdx(
7618         iterator_.StorageIndexForColumn(col.index_in_table()));
7619     }
locked_kb()7620     ColumnType::locked_kb::type locked_kb() const {
7621       const auto& col = table()->locked_kb();
7622       return col.GetAtIdx(
7623         iterator_.StorageIndexForColumn(col.index_in_table()));
7624     }
proportional_resident_kb()7625     ColumnType::proportional_resident_kb::type proportional_resident_kb() const {
7626       const auto& col = table()->proportional_resident_kb();
7627       return col.GetAtIdx(
7628         iterator_.StorageIndexForColumn(col.index_in_table()));
7629     }
7630 
7631    protected:
ConstIterator(const ProfilerSmapsTable * table,Table::Iterator iterator)7632     explicit ConstIterator(const ProfilerSmapsTable* table,
7633                            Table::Iterator iterator)
7634         : AbstractConstIterator(table, std::move(iterator)) {}
7635 
CurrentRowNumber()7636     uint32_t CurrentRowNumber() const {
7637       return iterator_.StorageIndexForLastOverlay();
7638     }
7639 
7640    private:
7641     friend class ProfilerSmapsTable;
7642     friend class macros_internal::AbstractConstIterator<
7643       ConstIterator, ProfilerSmapsTable, RowNumber, ConstRowReference>;
7644   };
7645   class Iterator : public ConstIterator {
7646     public:
row_reference()7647      RowReference row_reference() const {
7648        return {const_cast<ProfilerSmapsTable*>(table()), CurrentRowNumber()};
7649      }
7650 
7651     private:
7652      friend class ProfilerSmapsTable;
7653 
Iterator(ProfilerSmapsTable * table,Table::Iterator iterator)7654      explicit Iterator(ProfilerSmapsTable* table, Table::Iterator iterator)
7655         : ConstIterator(table, std::move(iterator)) {}
7656   };
7657 
7658   struct IdAndRow {
7659     Id id;
7660     uint32_t row;
7661     RowReference row_reference;
7662     RowNumber row_number;
7663   };
7664 
GetColumns(ProfilerSmapsTable * self,const macros_internal::MacroTable * parent)7665   static std::vector<ColumnLegacy> GetColumns(
7666       ProfilerSmapsTable* self,
7667       const macros_internal::MacroTable* parent) {
7668     std::vector<ColumnLegacy> columns =
7669         CopyColumnsFromParentOrAddRootColumns(self, parent);
7670     uint32_t olay_idx = OverlayCount(parent);
7671     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
7672                       static_cast<uint32_t>(columns.size()), olay_idx);
7673     AddColumnToVector(columns, "ts", &self->ts_, ColumnFlag::ts,
7674                       static_cast<uint32_t>(columns.size()), olay_idx);
7675     AddColumnToVector(columns, "path", &self->path_, ColumnFlag::path,
7676                       static_cast<uint32_t>(columns.size()), olay_idx);
7677     AddColumnToVector(columns, "size_kb", &self->size_kb_, ColumnFlag::size_kb,
7678                       static_cast<uint32_t>(columns.size()), olay_idx);
7679     AddColumnToVector(columns, "private_dirty_kb", &self->private_dirty_kb_, ColumnFlag::private_dirty_kb,
7680                       static_cast<uint32_t>(columns.size()), olay_idx);
7681     AddColumnToVector(columns, "swap_kb", &self->swap_kb_, ColumnFlag::swap_kb,
7682                       static_cast<uint32_t>(columns.size()), olay_idx);
7683     AddColumnToVector(columns, "file_name", &self->file_name_, ColumnFlag::file_name,
7684                       static_cast<uint32_t>(columns.size()), olay_idx);
7685     AddColumnToVector(columns, "start_address", &self->start_address_, ColumnFlag::start_address,
7686                       static_cast<uint32_t>(columns.size()), olay_idx);
7687     AddColumnToVector(columns, "module_timestamp", &self->module_timestamp_, ColumnFlag::module_timestamp,
7688                       static_cast<uint32_t>(columns.size()), olay_idx);
7689     AddColumnToVector(columns, "module_debugid", &self->module_debugid_, ColumnFlag::module_debugid,
7690                       static_cast<uint32_t>(columns.size()), olay_idx);
7691     AddColumnToVector(columns, "module_debug_path", &self->module_debug_path_, ColumnFlag::module_debug_path,
7692                       static_cast<uint32_t>(columns.size()), olay_idx);
7693     AddColumnToVector(columns, "protection_flags", &self->protection_flags_, ColumnFlag::protection_flags,
7694                       static_cast<uint32_t>(columns.size()), olay_idx);
7695     AddColumnToVector(columns, "private_clean_resident_kb", &self->private_clean_resident_kb_, ColumnFlag::private_clean_resident_kb,
7696                       static_cast<uint32_t>(columns.size()), olay_idx);
7697     AddColumnToVector(columns, "shared_dirty_resident_kb", &self->shared_dirty_resident_kb_, ColumnFlag::shared_dirty_resident_kb,
7698                       static_cast<uint32_t>(columns.size()), olay_idx);
7699     AddColumnToVector(columns, "shared_clean_resident_kb", &self->shared_clean_resident_kb_, ColumnFlag::shared_clean_resident_kb,
7700                       static_cast<uint32_t>(columns.size()), olay_idx);
7701     AddColumnToVector(columns, "locked_kb", &self->locked_kb_, ColumnFlag::locked_kb,
7702                       static_cast<uint32_t>(columns.size()), olay_idx);
7703     AddColumnToVector(columns, "proportional_resident_kb", &self->proportional_resident_kb_, ColumnFlag::proportional_resident_kb,
7704                       static_cast<uint32_t>(columns.size()), olay_idx);
7705     return columns;
7706   }
7707 
ProfilerSmapsTable(StringPool * pool)7708   PERFETTO_NO_INLINE explicit ProfilerSmapsTable(StringPool* pool)
7709       : macros_internal::MacroTable(
7710           pool,
7711           GetColumns(this, nullptr),
7712           nullptr),
7713         upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>()),
7714         ts_(ColumnStorage<ColumnType::ts::stored_type>::Create<false>()),
7715         path_(ColumnStorage<ColumnType::path::stored_type>::Create<false>()),
7716         size_kb_(ColumnStorage<ColumnType::size_kb::stored_type>::Create<false>()),
7717         private_dirty_kb_(ColumnStorage<ColumnType::private_dirty_kb::stored_type>::Create<false>()),
7718         swap_kb_(ColumnStorage<ColumnType::swap_kb::stored_type>::Create<false>()),
7719         file_name_(ColumnStorage<ColumnType::file_name::stored_type>::Create<false>()),
7720         start_address_(ColumnStorage<ColumnType::start_address::stored_type>::Create<false>()),
7721         module_timestamp_(ColumnStorage<ColumnType::module_timestamp::stored_type>::Create<false>()),
7722         module_debugid_(ColumnStorage<ColumnType::module_debugid::stored_type>::Create<false>()),
7723         module_debug_path_(ColumnStorage<ColumnType::module_debug_path::stored_type>::Create<false>()),
7724         protection_flags_(ColumnStorage<ColumnType::protection_flags::stored_type>::Create<false>()),
7725         private_clean_resident_kb_(ColumnStorage<ColumnType::private_clean_resident_kb::stored_type>::Create<false>()),
7726         shared_dirty_resident_kb_(ColumnStorage<ColumnType::shared_dirty_resident_kb::stored_type>::Create<false>()),
7727         shared_clean_resident_kb_(ColumnStorage<ColumnType::shared_clean_resident_kb::stored_type>::Create<false>()),
7728         locked_kb_(ColumnStorage<ColumnType::locked_kb::stored_type>::Create<false>()),
7729         proportional_resident_kb_(ColumnStorage<ColumnType::proportional_resident_kb::stored_type>::Create<false>())
7730 ,
7731         id_storage_layer_(new column::IdStorage()),
7732         type_storage_layer_(
7733           new column::StringStorage(string_pool(), &type_.vector())),
7734         upid_storage_layer_(
7735         new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
7736           &upid_.vector(),
7737           ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
7738           false)),
7739         ts_storage_layer_(
7740         new column::NumericStorage<ColumnType::ts::non_optional_stored_type>(
7741           &ts_.vector(),
7742           ColumnTypeHelper<ColumnType::ts::stored_type>::ToColumnType(),
7743           false)),
7744         path_storage_layer_(
7745           new column::StringStorage(string_pool(), &path_.vector())),
7746         size_kb_storage_layer_(
7747         new column::NumericStorage<ColumnType::size_kb::non_optional_stored_type>(
7748           &size_kb_.vector(),
7749           ColumnTypeHelper<ColumnType::size_kb::stored_type>::ToColumnType(),
7750           false)),
7751         private_dirty_kb_storage_layer_(
7752         new column::NumericStorage<ColumnType::private_dirty_kb::non_optional_stored_type>(
7753           &private_dirty_kb_.vector(),
7754           ColumnTypeHelper<ColumnType::private_dirty_kb::stored_type>::ToColumnType(),
7755           false)),
7756         swap_kb_storage_layer_(
7757         new column::NumericStorage<ColumnType::swap_kb::non_optional_stored_type>(
7758           &swap_kb_.vector(),
7759           ColumnTypeHelper<ColumnType::swap_kb::stored_type>::ToColumnType(),
7760           false)),
7761         file_name_storage_layer_(
7762           new column::StringStorage(string_pool(), &file_name_.vector())),
7763         start_address_storage_layer_(
7764         new column::NumericStorage<ColumnType::start_address::non_optional_stored_type>(
7765           &start_address_.vector(),
7766           ColumnTypeHelper<ColumnType::start_address::stored_type>::ToColumnType(),
7767           false)),
7768         module_timestamp_storage_layer_(
7769         new column::NumericStorage<ColumnType::module_timestamp::non_optional_stored_type>(
7770           &module_timestamp_.vector(),
7771           ColumnTypeHelper<ColumnType::module_timestamp::stored_type>::ToColumnType(),
7772           false)),
7773         module_debugid_storage_layer_(
7774           new column::StringStorage(string_pool(), &module_debugid_.vector())),
7775         module_debug_path_storage_layer_(
7776           new column::StringStorage(string_pool(), &module_debug_path_.vector())),
7777         protection_flags_storage_layer_(
7778         new column::NumericStorage<ColumnType::protection_flags::non_optional_stored_type>(
7779           &protection_flags_.vector(),
7780           ColumnTypeHelper<ColumnType::protection_flags::stored_type>::ToColumnType(),
7781           false)),
7782         private_clean_resident_kb_storage_layer_(
7783         new column::NumericStorage<ColumnType::private_clean_resident_kb::non_optional_stored_type>(
7784           &private_clean_resident_kb_.vector(),
7785           ColumnTypeHelper<ColumnType::private_clean_resident_kb::stored_type>::ToColumnType(),
7786           false)),
7787         shared_dirty_resident_kb_storage_layer_(
7788         new column::NumericStorage<ColumnType::shared_dirty_resident_kb::non_optional_stored_type>(
7789           &shared_dirty_resident_kb_.vector(),
7790           ColumnTypeHelper<ColumnType::shared_dirty_resident_kb::stored_type>::ToColumnType(),
7791           false)),
7792         shared_clean_resident_kb_storage_layer_(
7793         new column::NumericStorage<ColumnType::shared_clean_resident_kb::non_optional_stored_type>(
7794           &shared_clean_resident_kb_.vector(),
7795           ColumnTypeHelper<ColumnType::shared_clean_resident_kb::stored_type>::ToColumnType(),
7796           false)),
7797         locked_kb_storage_layer_(
7798         new column::NumericStorage<ColumnType::locked_kb::non_optional_stored_type>(
7799           &locked_kb_.vector(),
7800           ColumnTypeHelper<ColumnType::locked_kb::stored_type>::ToColumnType(),
7801           false)),
7802         proportional_resident_kb_storage_layer_(
7803         new column::NumericStorage<ColumnType::proportional_resident_kb::non_optional_stored_type>(
7804           &proportional_resident_kb_.vector(),
7805           ColumnTypeHelper<ColumnType::proportional_resident_kb::stored_type>::ToColumnType(),
7806           false))
7807          {
7808     static_assert(
7809         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
7810           ColumnFlag::upid),
7811         "Column type and flag combination is not valid");
7812       static_assert(
7813         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::ts::stored_type>(
7814           ColumnFlag::ts),
7815         "Column type and flag combination is not valid");
7816       static_assert(
7817         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::path::stored_type>(
7818           ColumnFlag::path),
7819         "Column type and flag combination is not valid");
7820       static_assert(
7821         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::size_kb::stored_type>(
7822           ColumnFlag::size_kb),
7823         "Column type and flag combination is not valid");
7824       static_assert(
7825         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::private_dirty_kb::stored_type>(
7826           ColumnFlag::private_dirty_kb),
7827         "Column type and flag combination is not valid");
7828       static_assert(
7829         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::swap_kb::stored_type>(
7830           ColumnFlag::swap_kb),
7831         "Column type and flag combination is not valid");
7832       static_assert(
7833         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::file_name::stored_type>(
7834           ColumnFlag::file_name),
7835         "Column type and flag combination is not valid");
7836       static_assert(
7837         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::start_address::stored_type>(
7838           ColumnFlag::start_address),
7839         "Column type and flag combination is not valid");
7840       static_assert(
7841         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::module_timestamp::stored_type>(
7842           ColumnFlag::module_timestamp),
7843         "Column type and flag combination is not valid");
7844       static_assert(
7845         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::module_debugid::stored_type>(
7846           ColumnFlag::module_debugid),
7847         "Column type and flag combination is not valid");
7848       static_assert(
7849         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::module_debug_path::stored_type>(
7850           ColumnFlag::module_debug_path),
7851         "Column type and flag combination is not valid");
7852       static_assert(
7853         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::protection_flags::stored_type>(
7854           ColumnFlag::protection_flags),
7855         "Column type and flag combination is not valid");
7856       static_assert(
7857         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::private_clean_resident_kb::stored_type>(
7858           ColumnFlag::private_clean_resident_kb),
7859         "Column type and flag combination is not valid");
7860       static_assert(
7861         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::shared_dirty_resident_kb::stored_type>(
7862           ColumnFlag::shared_dirty_resident_kb),
7863         "Column type and flag combination is not valid");
7864       static_assert(
7865         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::shared_clean_resident_kb::stored_type>(
7866           ColumnFlag::shared_clean_resident_kb),
7867         "Column type and flag combination is not valid");
7868       static_assert(
7869         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::locked_kb::stored_type>(
7870           ColumnFlag::locked_kb),
7871         "Column type and flag combination is not valid");
7872       static_assert(
7873         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::proportional_resident_kb::stored_type>(
7874           ColumnFlag::proportional_resident_kb),
7875         "Column type and flag combination is not valid");
7876     OnConstructionCompletedRegularConstructor(
7877       {id_storage_layer_,type_storage_layer_,upid_storage_layer_,ts_storage_layer_,path_storage_layer_,size_kb_storage_layer_,private_dirty_kb_storage_layer_,swap_kb_storage_layer_,file_name_storage_layer_,start_address_storage_layer_,module_timestamp_storage_layer_,module_debugid_storage_layer_,module_debug_path_storage_layer_,protection_flags_storage_layer_,private_clean_resident_kb_storage_layer_,shared_dirty_resident_kb_storage_layer_,shared_clean_resident_kb_storage_layer_,locked_kb_storage_layer_,proportional_resident_kb_storage_layer_},
7878       {{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}});
7879   }
7880   ~ProfilerSmapsTable() override;
7881 
Name()7882   static const char* Name() { return "profiler_smaps"; }
7883 
ComputeStaticSchema()7884   static Table::Schema ComputeStaticSchema() {
7885     Table::Schema schema;
7886     schema.columns.emplace_back(Table::Schema::Column{
7887         "id", SqlValue::Type::kLong, true, true, false, false});
7888     schema.columns.emplace_back(Table::Schema::Column{
7889         "type", SqlValue::Type::kString, false, false, false, false});
7890     schema.columns.emplace_back(Table::Schema::Column{
7891         "upid", ColumnType::upid::SqlValueType(), false,
7892         false,
7893         false,
7894         false});
7895     schema.columns.emplace_back(Table::Schema::Column{
7896         "ts", ColumnType::ts::SqlValueType(), false,
7897         false,
7898         false,
7899         false});
7900     schema.columns.emplace_back(Table::Schema::Column{
7901         "path", ColumnType::path::SqlValueType(), false,
7902         false,
7903         false,
7904         false});
7905     schema.columns.emplace_back(Table::Schema::Column{
7906         "size_kb", ColumnType::size_kb::SqlValueType(), false,
7907         false,
7908         false,
7909         false});
7910     schema.columns.emplace_back(Table::Schema::Column{
7911         "private_dirty_kb", ColumnType::private_dirty_kb::SqlValueType(), false,
7912         false,
7913         false,
7914         false});
7915     schema.columns.emplace_back(Table::Schema::Column{
7916         "swap_kb", ColumnType::swap_kb::SqlValueType(), false,
7917         false,
7918         false,
7919         false});
7920     schema.columns.emplace_back(Table::Schema::Column{
7921         "file_name", ColumnType::file_name::SqlValueType(), false,
7922         false,
7923         false,
7924         false});
7925     schema.columns.emplace_back(Table::Schema::Column{
7926         "start_address", ColumnType::start_address::SqlValueType(), false,
7927         false,
7928         false,
7929         false});
7930     schema.columns.emplace_back(Table::Schema::Column{
7931         "module_timestamp", ColumnType::module_timestamp::SqlValueType(), false,
7932         false,
7933         false,
7934         false});
7935     schema.columns.emplace_back(Table::Schema::Column{
7936         "module_debugid", ColumnType::module_debugid::SqlValueType(), false,
7937         false,
7938         false,
7939         false});
7940     schema.columns.emplace_back(Table::Schema::Column{
7941         "module_debug_path", ColumnType::module_debug_path::SqlValueType(), false,
7942         false,
7943         false,
7944         false});
7945     schema.columns.emplace_back(Table::Schema::Column{
7946         "protection_flags", ColumnType::protection_flags::SqlValueType(), false,
7947         false,
7948         false,
7949         false});
7950     schema.columns.emplace_back(Table::Schema::Column{
7951         "private_clean_resident_kb", ColumnType::private_clean_resident_kb::SqlValueType(), false,
7952         false,
7953         false,
7954         false});
7955     schema.columns.emplace_back(Table::Schema::Column{
7956         "shared_dirty_resident_kb", ColumnType::shared_dirty_resident_kb::SqlValueType(), false,
7957         false,
7958         false,
7959         false});
7960     schema.columns.emplace_back(Table::Schema::Column{
7961         "shared_clean_resident_kb", ColumnType::shared_clean_resident_kb::SqlValueType(), false,
7962         false,
7963         false,
7964         false});
7965     schema.columns.emplace_back(Table::Schema::Column{
7966         "locked_kb", ColumnType::locked_kb::SqlValueType(), false,
7967         false,
7968         false,
7969         false});
7970     schema.columns.emplace_back(Table::Schema::Column{
7971         "proportional_resident_kb", ColumnType::proportional_resident_kb::SqlValueType(), false,
7972         false,
7973         false,
7974         false});
7975     return schema;
7976   }
7977 
IterateRows()7978   ConstIterator IterateRows() const {
7979     return ConstIterator(this, Table::IterateRows());
7980   }
7981 
IterateRows()7982   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
7983 
FilterToIterator(const Query & q)7984   ConstIterator FilterToIterator(const Query& q) const {
7985     return ConstIterator(this, QueryToIterator(q));
7986   }
7987 
FilterToIterator(const Query & q)7988   Iterator FilterToIterator(const Query& q) {
7989     return Iterator(this, QueryToIterator(q));
7990   }
7991 
ShrinkToFit()7992   void ShrinkToFit() {
7993     type_.ShrinkToFit();
7994     upid_.ShrinkToFit();
7995     ts_.ShrinkToFit();
7996     path_.ShrinkToFit();
7997     size_kb_.ShrinkToFit();
7998     private_dirty_kb_.ShrinkToFit();
7999     swap_kb_.ShrinkToFit();
8000     file_name_.ShrinkToFit();
8001     start_address_.ShrinkToFit();
8002     module_timestamp_.ShrinkToFit();
8003     module_debugid_.ShrinkToFit();
8004     module_debug_path_.ShrinkToFit();
8005     protection_flags_.ShrinkToFit();
8006     private_clean_resident_kb_.ShrinkToFit();
8007     shared_dirty_resident_kb_.ShrinkToFit();
8008     shared_clean_resident_kb_.ShrinkToFit();
8009     locked_kb_.ShrinkToFit();
8010     proportional_resident_kb_.ShrinkToFit();
8011   }
8012 
8013   ConstRowReference operator[](uint32_t r) const {
8014     return ConstRowReference(this, r);
8015   }
8016   RowReference operator[](uint32_t r) { return RowReference(this, r); }
8017   ConstRowReference operator[](RowNumber r) const {
8018     return ConstRowReference(this, r.row_number());
8019   }
8020   RowReference operator[](RowNumber r) {
8021     return RowReference(this, r.row_number());
8022   }
8023 
FindById(Id find_id)8024   std::optional<ConstRowReference> FindById(Id find_id) const {
8025     std::optional<uint32_t> row = id().IndexOf(find_id);
8026     return row ? std::make_optional(ConstRowReference(this, *row))
8027                : std::nullopt;
8028   }
8029 
FindById(Id find_id)8030   std::optional<RowReference> FindById(Id find_id) {
8031     std::optional<uint32_t> row = id().IndexOf(find_id);
8032     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
8033   }
8034 
Insert(const Row & row)8035   IdAndRow Insert(const Row& row) {
8036     uint32_t row_number = row_count();
8037     Id id = Id{row_number};
8038     type_.Append(string_pool()->InternString(row.type()));
8039     mutable_upid()->Append(row.upid);
8040     mutable_ts()->Append(row.ts);
8041     mutable_path()->Append(row.path);
8042     mutable_size_kb()->Append(row.size_kb);
8043     mutable_private_dirty_kb()->Append(row.private_dirty_kb);
8044     mutable_swap_kb()->Append(row.swap_kb);
8045     mutable_file_name()->Append(row.file_name);
8046     mutable_start_address()->Append(row.start_address);
8047     mutable_module_timestamp()->Append(row.module_timestamp);
8048     mutable_module_debugid()->Append(row.module_debugid);
8049     mutable_module_debug_path()->Append(row.module_debug_path);
8050     mutable_protection_flags()->Append(row.protection_flags);
8051     mutable_private_clean_resident_kb()->Append(row.private_clean_resident_kb);
8052     mutable_shared_dirty_resident_kb()->Append(row.shared_dirty_resident_kb);
8053     mutable_shared_clean_resident_kb()->Append(row.shared_clean_resident_kb);
8054     mutable_locked_kb()->Append(row.locked_kb);
8055     mutable_proportional_resident_kb()->Append(row.proportional_resident_kb);
8056     UpdateSelfOverlayAfterInsert();
8057     return IdAndRow{id, row_number, RowReference(this, row_number),
8058                      RowNumber(row_number)};
8059   }
8060 
8061 
8062 
id()8063   const IdColumn<ProfilerSmapsTable::Id>& id() const {
8064     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
8065   }
type()8066   const TypedColumn<StringPool::Id>& type() const {
8067     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
8068   }
upid()8069   const TypedColumn<uint32_t>& upid() const {
8070     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
8071   }
ts()8072   const TypedColumn<int64_t>& ts() const {
8073     return static_cast<const ColumnType::ts&>(columns()[ColumnIndex::ts]);
8074   }
path()8075   const TypedColumn<StringPool::Id>& path() const {
8076     return static_cast<const ColumnType::path&>(columns()[ColumnIndex::path]);
8077   }
size_kb()8078   const TypedColumn<int64_t>& size_kb() const {
8079     return static_cast<const ColumnType::size_kb&>(columns()[ColumnIndex::size_kb]);
8080   }
private_dirty_kb()8081   const TypedColumn<int64_t>& private_dirty_kb() const {
8082     return static_cast<const ColumnType::private_dirty_kb&>(columns()[ColumnIndex::private_dirty_kb]);
8083   }
swap_kb()8084   const TypedColumn<int64_t>& swap_kb() const {
8085     return static_cast<const ColumnType::swap_kb&>(columns()[ColumnIndex::swap_kb]);
8086   }
file_name()8087   const TypedColumn<StringPool::Id>& file_name() const {
8088     return static_cast<const ColumnType::file_name&>(columns()[ColumnIndex::file_name]);
8089   }
start_address()8090   const TypedColumn<int64_t>& start_address() const {
8091     return static_cast<const ColumnType::start_address&>(columns()[ColumnIndex::start_address]);
8092   }
module_timestamp()8093   const TypedColumn<int64_t>& module_timestamp() const {
8094     return static_cast<const ColumnType::module_timestamp&>(columns()[ColumnIndex::module_timestamp]);
8095   }
module_debugid()8096   const TypedColumn<StringPool::Id>& module_debugid() const {
8097     return static_cast<const ColumnType::module_debugid&>(columns()[ColumnIndex::module_debugid]);
8098   }
module_debug_path()8099   const TypedColumn<StringPool::Id>& module_debug_path() const {
8100     return static_cast<const ColumnType::module_debug_path&>(columns()[ColumnIndex::module_debug_path]);
8101   }
protection_flags()8102   const TypedColumn<int64_t>& protection_flags() const {
8103     return static_cast<const ColumnType::protection_flags&>(columns()[ColumnIndex::protection_flags]);
8104   }
private_clean_resident_kb()8105   const TypedColumn<int64_t>& private_clean_resident_kb() const {
8106     return static_cast<const ColumnType::private_clean_resident_kb&>(columns()[ColumnIndex::private_clean_resident_kb]);
8107   }
shared_dirty_resident_kb()8108   const TypedColumn<int64_t>& shared_dirty_resident_kb() const {
8109     return static_cast<const ColumnType::shared_dirty_resident_kb&>(columns()[ColumnIndex::shared_dirty_resident_kb]);
8110   }
shared_clean_resident_kb()8111   const TypedColumn<int64_t>& shared_clean_resident_kb() const {
8112     return static_cast<const ColumnType::shared_clean_resident_kb&>(columns()[ColumnIndex::shared_clean_resident_kb]);
8113   }
locked_kb()8114   const TypedColumn<int64_t>& locked_kb() const {
8115     return static_cast<const ColumnType::locked_kb&>(columns()[ColumnIndex::locked_kb]);
8116   }
proportional_resident_kb()8117   const TypedColumn<int64_t>& proportional_resident_kb() const {
8118     return static_cast<const ColumnType::proportional_resident_kb&>(columns()[ColumnIndex::proportional_resident_kb]);
8119   }
8120 
mutable_upid()8121   TypedColumn<uint32_t>* mutable_upid() {
8122     return static_cast<ColumnType::upid*>(
8123         GetColumn(ColumnIndex::upid));
8124   }
mutable_ts()8125   TypedColumn<int64_t>* mutable_ts() {
8126     return static_cast<ColumnType::ts*>(
8127         GetColumn(ColumnIndex::ts));
8128   }
mutable_path()8129   TypedColumn<StringPool::Id>* mutable_path() {
8130     return static_cast<ColumnType::path*>(
8131         GetColumn(ColumnIndex::path));
8132   }
mutable_size_kb()8133   TypedColumn<int64_t>* mutable_size_kb() {
8134     return static_cast<ColumnType::size_kb*>(
8135         GetColumn(ColumnIndex::size_kb));
8136   }
mutable_private_dirty_kb()8137   TypedColumn<int64_t>* mutable_private_dirty_kb() {
8138     return static_cast<ColumnType::private_dirty_kb*>(
8139         GetColumn(ColumnIndex::private_dirty_kb));
8140   }
mutable_swap_kb()8141   TypedColumn<int64_t>* mutable_swap_kb() {
8142     return static_cast<ColumnType::swap_kb*>(
8143         GetColumn(ColumnIndex::swap_kb));
8144   }
mutable_file_name()8145   TypedColumn<StringPool::Id>* mutable_file_name() {
8146     return static_cast<ColumnType::file_name*>(
8147         GetColumn(ColumnIndex::file_name));
8148   }
mutable_start_address()8149   TypedColumn<int64_t>* mutable_start_address() {
8150     return static_cast<ColumnType::start_address*>(
8151         GetColumn(ColumnIndex::start_address));
8152   }
mutable_module_timestamp()8153   TypedColumn<int64_t>* mutable_module_timestamp() {
8154     return static_cast<ColumnType::module_timestamp*>(
8155         GetColumn(ColumnIndex::module_timestamp));
8156   }
mutable_module_debugid()8157   TypedColumn<StringPool::Id>* mutable_module_debugid() {
8158     return static_cast<ColumnType::module_debugid*>(
8159         GetColumn(ColumnIndex::module_debugid));
8160   }
mutable_module_debug_path()8161   TypedColumn<StringPool::Id>* mutable_module_debug_path() {
8162     return static_cast<ColumnType::module_debug_path*>(
8163         GetColumn(ColumnIndex::module_debug_path));
8164   }
mutable_protection_flags()8165   TypedColumn<int64_t>* mutable_protection_flags() {
8166     return static_cast<ColumnType::protection_flags*>(
8167         GetColumn(ColumnIndex::protection_flags));
8168   }
mutable_private_clean_resident_kb()8169   TypedColumn<int64_t>* mutable_private_clean_resident_kb() {
8170     return static_cast<ColumnType::private_clean_resident_kb*>(
8171         GetColumn(ColumnIndex::private_clean_resident_kb));
8172   }
mutable_shared_dirty_resident_kb()8173   TypedColumn<int64_t>* mutable_shared_dirty_resident_kb() {
8174     return static_cast<ColumnType::shared_dirty_resident_kb*>(
8175         GetColumn(ColumnIndex::shared_dirty_resident_kb));
8176   }
mutable_shared_clean_resident_kb()8177   TypedColumn<int64_t>* mutable_shared_clean_resident_kb() {
8178     return static_cast<ColumnType::shared_clean_resident_kb*>(
8179         GetColumn(ColumnIndex::shared_clean_resident_kb));
8180   }
mutable_locked_kb()8181   TypedColumn<int64_t>* mutable_locked_kb() {
8182     return static_cast<ColumnType::locked_kb*>(
8183         GetColumn(ColumnIndex::locked_kb));
8184   }
mutable_proportional_resident_kb()8185   TypedColumn<int64_t>* mutable_proportional_resident_kb() {
8186     return static_cast<ColumnType::proportional_resident_kb*>(
8187         GetColumn(ColumnIndex::proportional_resident_kb));
8188   }
8189 
8190  private:
8191 
8192 
8193   ColumnStorage<ColumnType::upid::stored_type> upid_;
8194   ColumnStorage<ColumnType::ts::stored_type> ts_;
8195   ColumnStorage<ColumnType::path::stored_type> path_;
8196   ColumnStorage<ColumnType::size_kb::stored_type> size_kb_;
8197   ColumnStorage<ColumnType::private_dirty_kb::stored_type> private_dirty_kb_;
8198   ColumnStorage<ColumnType::swap_kb::stored_type> swap_kb_;
8199   ColumnStorage<ColumnType::file_name::stored_type> file_name_;
8200   ColumnStorage<ColumnType::start_address::stored_type> start_address_;
8201   ColumnStorage<ColumnType::module_timestamp::stored_type> module_timestamp_;
8202   ColumnStorage<ColumnType::module_debugid::stored_type> module_debugid_;
8203   ColumnStorage<ColumnType::module_debug_path::stored_type> module_debug_path_;
8204   ColumnStorage<ColumnType::protection_flags::stored_type> protection_flags_;
8205   ColumnStorage<ColumnType::private_clean_resident_kb::stored_type> private_clean_resident_kb_;
8206   ColumnStorage<ColumnType::shared_dirty_resident_kb::stored_type> shared_dirty_resident_kb_;
8207   ColumnStorage<ColumnType::shared_clean_resident_kb::stored_type> shared_clean_resident_kb_;
8208   ColumnStorage<ColumnType::locked_kb::stored_type> locked_kb_;
8209   ColumnStorage<ColumnType::proportional_resident_kb::stored_type> proportional_resident_kb_;
8210 
8211   RefPtr<column::StorageLayer> id_storage_layer_;
8212   RefPtr<column::StorageLayer> type_storage_layer_;
8213   RefPtr<column::StorageLayer> upid_storage_layer_;
8214   RefPtr<column::StorageLayer> ts_storage_layer_;
8215   RefPtr<column::StorageLayer> path_storage_layer_;
8216   RefPtr<column::StorageLayer> size_kb_storage_layer_;
8217   RefPtr<column::StorageLayer> private_dirty_kb_storage_layer_;
8218   RefPtr<column::StorageLayer> swap_kb_storage_layer_;
8219   RefPtr<column::StorageLayer> file_name_storage_layer_;
8220   RefPtr<column::StorageLayer> start_address_storage_layer_;
8221   RefPtr<column::StorageLayer> module_timestamp_storage_layer_;
8222   RefPtr<column::StorageLayer> module_debugid_storage_layer_;
8223   RefPtr<column::StorageLayer> module_debug_path_storage_layer_;
8224   RefPtr<column::StorageLayer> protection_flags_storage_layer_;
8225   RefPtr<column::StorageLayer> private_clean_resident_kb_storage_layer_;
8226   RefPtr<column::StorageLayer> shared_dirty_resident_kb_storage_layer_;
8227   RefPtr<column::StorageLayer> shared_clean_resident_kb_storage_layer_;
8228   RefPtr<column::StorageLayer> locked_kb_storage_layer_;
8229   RefPtr<column::StorageLayer> proportional_resident_kb_storage_layer_;
8230 
8231 
8232 };
8233 
8234 
8235 class SymbolTable : public macros_internal::MacroTable {
8236  public:
8237   static constexpr uint32_t kColumnCount = 6;
8238 
8239   struct Id : public BaseId {
8240     Id() = default;
IdId8241     explicit constexpr Id(uint32_t v) : BaseId(v) {}
8242   };
8243   static_assert(std::is_trivially_destructible_v<Id>,
8244                 "Inheritance used without trivial destruction");
8245 
8246   struct ColumnIndex {
8247     static constexpr uint32_t id = 0;
8248     static constexpr uint32_t type = 1;
8249     static constexpr uint32_t symbol_set_id = 2;
8250     static constexpr uint32_t name = 3;
8251     static constexpr uint32_t source_file = 4;
8252     static constexpr uint32_t line_number = 5;
8253   };
8254   struct ColumnType {
8255     using id = IdColumn<SymbolTable::Id>;
8256     using type = TypedColumn<StringPool::Id>;
8257     using symbol_set_id = TypedColumn<uint32_t>;
8258     using name = TypedColumn<StringPool::Id>;
8259     using source_file = TypedColumn<std::optional<StringPool::Id>>;
8260     using line_number = TypedColumn<std::optional<uint32_t>>;
8261   };
8262   struct Row : public macros_internal::RootParentTable::Row {
8263     Row(uint32_t in_symbol_set_id = {},
8264         StringPool::Id in_name = {},
8265         std::optional<StringPool::Id> in_source_file = {},
8266         std::optional<uint32_t> in_line_number = {},
8267         std::nullptr_t = nullptr)
RowRow8268         : macros_internal::RootParentTable::Row(),
8269           symbol_set_id(in_symbol_set_id),
8270           name(in_name),
8271           source_file(in_source_file),
8272           line_number(in_line_number) {
8273       type_ = "stack_profile_symbol";
8274     }
8275     uint32_t symbol_set_id;
8276     StringPool::Id name;
8277     std::optional<StringPool::Id> source_file;
8278     std::optional<uint32_t> line_number;
8279 
8280     bool operator==(const SymbolTable::Row& other) const {
8281       return type() == other.type() && ColumnType::symbol_set_id::Equals(symbol_set_id, other.symbol_set_id) &&
8282        ColumnType::name::Equals(name, other.name) &&
8283        ColumnType::source_file::Equals(source_file, other.source_file) &&
8284        ColumnType::line_number::Equals(line_number, other.line_number);
8285     }
8286   };
8287   struct ColumnFlag {
8288     static constexpr uint32_t symbol_set_id = static_cast<uint32_t>(ColumnLegacy::Flag::kSorted | ColumnLegacy::Flag::kSetId) | ColumnType::symbol_set_id::default_flags();
8289     static constexpr uint32_t name = ColumnType::name::default_flags();
8290     static constexpr uint32_t source_file = ColumnType::source_file::default_flags();
8291     static constexpr uint32_t line_number = ColumnType::line_number::default_flags();
8292   };
8293 
8294   class RowNumber;
8295   class ConstRowReference;
8296   class RowReference;
8297 
8298   class RowNumber : public macros_internal::AbstractRowNumber<
8299       SymbolTable, ConstRowReference, RowReference> {
8300    public:
RowNumber(uint32_t row_number)8301     explicit RowNumber(uint32_t row_number)
8302         : AbstractRowNumber(row_number) {}
8303   };
8304   static_assert(std::is_trivially_destructible_v<RowNumber>,
8305                 "Inheritance used without trivial destruction");
8306 
8307   class ConstRowReference : public macros_internal::AbstractConstRowReference<
8308     SymbolTable, RowNumber> {
8309    public:
ConstRowReference(const SymbolTable * table,uint32_t row_number)8310     ConstRowReference(const SymbolTable* table, uint32_t row_number)
8311         : AbstractConstRowReference(table, row_number) {}
8312 
id()8313     ColumnType::id::type id() const {
8314       return table()->id()[row_number_];
8315     }
type()8316     ColumnType::type::type type() const {
8317       return table()->type()[row_number_];
8318     }
symbol_set_id()8319     ColumnType::symbol_set_id::type symbol_set_id() const {
8320       return table()->symbol_set_id()[row_number_];
8321     }
name()8322     ColumnType::name::type name() const {
8323       return table()->name()[row_number_];
8324     }
source_file()8325     ColumnType::source_file::type source_file() const {
8326       return table()->source_file()[row_number_];
8327     }
line_number()8328     ColumnType::line_number::type line_number() const {
8329       return table()->line_number()[row_number_];
8330     }
8331   };
8332   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
8333                 "Inheritance used without trivial destruction");
8334   class RowReference : public ConstRowReference {
8335    public:
RowReference(const SymbolTable * table,uint32_t row_number)8336     RowReference(const SymbolTable* table, uint32_t row_number)
8337         : ConstRowReference(table, row_number) {}
8338 
set_symbol_set_id(ColumnType::symbol_set_id::non_optional_type v)8339     void set_symbol_set_id(
8340         ColumnType::symbol_set_id::non_optional_type v) {
8341       return mutable_table()->mutable_symbol_set_id()->Set(row_number_, v);
8342     }
set_name(ColumnType::name::non_optional_type v)8343     void set_name(
8344         ColumnType::name::non_optional_type v) {
8345       return mutable_table()->mutable_name()->Set(row_number_, v);
8346     }
set_source_file(ColumnType::source_file::non_optional_type v)8347     void set_source_file(
8348         ColumnType::source_file::non_optional_type v) {
8349       return mutable_table()->mutable_source_file()->Set(row_number_, v);
8350     }
set_line_number(ColumnType::line_number::non_optional_type v)8351     void set_line_number(
8352         ColumnType::line_number::non_optional_type v) {
8353       return mutable_table()->mutable_line_number()->Set(row_number_, v);
8354     }
8355 
8356    private:
mutable_table()8357     SymbolTable* mutable_table() const {
8358       return const_cast<SymbolTable*>(table());
8359     }
8360   };
8361   static_assert(std::is_trivially_destructible_v<RowReference>,
8362                 "Inheritance used without trivial destruction");
8363 
8364   class ConstIterator;
8365   class ConstIterator : public macros_internal::AbstractConstIterator<
8366     ConstIterator, SymbolTable, RowNumber, ConstRowReference> {
8367    public:
id()8368     ColumnType::id::type id() const {
8369       const auto& col = table()->id();
8370       return col.GetAtIdx(
8371         iterator_.StorageIndexForColumn(col.index_in_table()));
8372     }
type()8373     ColumnType::type::type type() const {
8374       const auto& col = table()->type();
8375       return col.GetAtIdx(
8376         iterator_.StorageIndexForColumn(col.index_in_table()));
8377     }
symbol_set_id()8378     ColumnType::symbol_set_id::type symbol_set_id() const {
8379       const auto& col = table()->symbol_set_id();
8380       return col.GetAtIdx(
8381         iterator_.StorageIndexForColumn(col.index_in_table()));
8382     }
name()8383     ColumnType::name::type name() const {
8384       const auto& col = table()->name();
8385       return col.GetAtIdx(
8386         iterator_.StorageIndexForColumn(col.index_in_table()));
8387     }
source_file()8388     ColumnType::source_file::type source_file() const {
8389       const auto& col = table()->source_file();
8390       return col.GetAtIdx(
8391         iterator_.StorageIndexForColumn(col.index_in_table()));
8392     }
line_number()8393     ColumnType::line_number::type line_number() const {
8394       const auto& col = table()->line_number();
8395       return col.GetAtIdx(
8396         iterator_.StorageIndexForColumn(col.index_in_table()));
8397     }
8398 
8399    protected:
ConstIterator(const SymbolTable * table,Table::Iterator iterator)8400     explicit ConstIterator(const SymbolTable* table,
8401                            Table::Iterator iterator)
8402         : AbstractConstIterator(table, std::move(iterator)) {}
8403 
CurrentRowNumber()8404     uint32_t CurrentRowNumber() const {
8405       return iterator_.StorageIndexForLastOverlay();
8406     }
8407 
8408    private:
8409     friend class SymbolTable;
8410     friend class macros_internal::AbstractConstIterator<
8411       ConstIterator, SymbolTable, RowNumber, ConstRowReference>;
8412   };
8413   class Iterator : public ConstIterator {
8414     public:
row_reference()8415      RowReference row_reference() const {
8416        return {const_cast<SymbolTable*>(table()), CurrentRowNumber()};
8417      }
8418 
8419     private:
8420      friend class SymbolTable;
8421 
Iterator(SymbolTable * table,Table::Iterator iterator)8422      explicit Iterator(SymbolTable* table, Table::Iterator iterator)
8423         : ConstIterator(table, std::move(iterator)) {}
8424   };
8425 
8426   struct IdAndRow {
8427     Id id;
8428     uint32_t row;
8429     RowReference row_reference;
8430     RowNumber row_number;
8431   };
8432 
GetColumns(SymbolTable * self,const macros_internal::MacroTable * parent)8433   static std::vector<ColumnLegacy> GetColumns(
8434       SymbolTable* self,
8435       const macros_internal::MacroTable* parent) {
8436     std::vector<ColumnLegacy> columns =
8437         CopyColumnsFromParentOrAddRootColumns(self, parent);
8438     uint32_t olay_idx = OverlayCount(parent);
8439     AddColumnToVector(columns, "symbol_set_id", &self->symbol_set_id_, ColumnFlag::symbol_set_id,
8440                       static_cast<uint32_t>(columns.size()), olay_idx);
8441     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
8442                       static_cast<uint32_t>(columns.size()), olay_idx);
8443     AddColumnToVector(columns, "source_file", &self->source_file_, ColumnFlag::source_file,
8444                       static_cast<uint32_t>(columns.size()), olay_idx);
8445     AddColumnToVector(columns, "line_number", &self->line_number_, ColumnFlag::line_number,
8446                       static_cast<uint32_t>(columns.size()), olay_idx);
8447     return columns;
8448   }
8449 
SymbolTable(StringPool * pool)8450   PERFETTO_NO_INLINE explicit SymbolTable(StringPool* pool)
8451       : macros_internal::MacroTable(
8452           pool,
8453           GetColumns(this, nullptr),
8454           nullptr),
8455         symbol_set_id_(ColumnStorage<ColumnType::symbol_set_id::stored_type>::Create<false>()),
8456         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>()),
8457         source_file_(ColumnStorage<ColumnType::source_file::stored_type>::Create<false>()),
8458         line_number_(ColumnStorage<ColumnType::line_number::stored_type>::Create<false>())
8459 ,
8460         id_storage_layer_(new column::IdStorage()),
8461         type_storage_layer_(
8462           new column::StringStorage(string_pool(), &type_.vector())),
8463         symbol_set_id_storage_layer_(
8464           new column::SetIdStorage(&symbol_set_id_.vector())),
8465         name_storage_layer_(
8466           new column::StringStorage(string_pool(), &name_.vector())),
8467         source_file_storage_layer_(
8468           new column::StringStorage(string_pool(), &source_file_.vector())),
8469         line_number_storage_layer_(
8470           new column::NumericStorage<ColumnType::line_number::non_optional_stored_type>(
8471             &line_number_.non_null_vector(),
8472             ColumnTypeHelper<ColumnType::line_number::stored_type>::ToColumnType(),
8473             false))
8474 ,
8475         line_number_null_layer_(new column::NullOverlay(line_number_.bv())) {
8476     static_assert(
8477         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::symbol_set_id::stored_type>(
8478           ColumnFlag::symbol_set_id),
8479         "Column type and flag combination is not valid");
8480       static_assert(
8481         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
8482           ColumnFlag::name),
8483         "Column type and flag combination is not valid");
8484       static_assert(
8485         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::source_file::stored_type>(
8486           ColumnFlag::source_file),
8487         "Column type and flag combination is not valid");
8488       static_assert(
8489         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::line_number::stored_type>(
8490           ColumnFlag::line_number),
8491         "Column type and flag combination is not valid");
8492     OnConstructionCompletedRegularConstructor(
8493       {id_storage_layer_,type_storage_layer_,symbol_set_id_storage_layer_,name_storage_layer_,source_file_storage_layer_,line_number_storage_layer_},
8494       {{},{},{},{},{},line_number_null_layer_});
8495   }
8496   ~SymbolTable() override;
8497 
Name()8498   static const char* Name() { return "stack_profile_symbol"; }
8499 
ComputeStaticSchema()8500   static Table::Schema ComputeStaticSchema() {
8501     Table::Schema schema;
8502     schema.columns.emplace_back(Table::Schema::Column{
8503         "id", SqlValue::Type::kLong, true, true, false, false});
8504     schema.columns.emplace_back(Table::Schema::Column{
8505         "type", SqlValue::Type::kString, false, false, false, false});
8506     schema.columns.emplace_back(Table::Schema::Column{
8507         "symbol_set_id", ColumnType::symbol_set_id::SqlValueType(), false,
8508         true,
8509         false,
8510         true});
8511     schema.columns.emplace_back(Table::Schema::Column{
8512         "name", ColumnType::name::SqlValueType(), false,
8513         false,
8514         false,
8515         false});
8516     schema.columns.emplace_back(Table::Schema::Column{
8517         "source_file", ColumnType::source_file::SqlValueType(), false,
8518         false,
8519         false,
8520         false});
8521     schema.columns.emplace_back(Table::Schema::Column{
8522         "line_number", ColumnType::line_number::SqlValueType(), false,
8523         false,
8524         false,
8525         false});
8526     return schema;
8527   }
8528 
IterateRows()8529   ConstIterator IterateRows() const {
8530     return ConstIterator(this, Table::IterateRows());
8531   }
8532 
IterateRows()8533   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
8534 
FilterToIterator(const Query & q)8535   ConstIterator FilterToIterator(const Query& q) const {
8536     return ConstIterator(this, QueryToIterator(q));
8537   }
8538 
FilterToIterator(const Query & q)8539   Iterator FilterToIterator(const Query& q) {
8540     return Iterator(this, QueryToIterator(q));
8541   }
8542 
ShrinkToFit()8543   void ShrinkToFit() {
8544     type_.ShrinkToFit();
8545     symbol_set_id_.ShrinkToFit();
8546     name_.ShrinkToFit();
8547     source_file_.ShrinkToFit();
8548     line_number_.ShrinkToFit();
8549   }
8550 
8551   ConstRowReference operator[](uint32_t r) const {
8552     return ConstRowReference(this, r);
8553   }
8554   RowReference operator[](uint32_t r) { return RowReference(this, r); }
8555   ConstRowReference operator[](RowNumber r) const {
8556     return ConstRowReference(this, r.row_number());
8557   }
8558   RowReference operator[](RowNumber r) {
8559     return RowReference(this, r.row_number());
8560   }
8561 
FindById(Id find_id)8562   std::optional<ConstRowReference> FindById(Id find_id) const {
8563     std::optional<uint32_t> row = id().IndexOf(find_id);
8564     return row ? std::make_optional(ConstRowReference(this, *row))
8565                : std::nullopt;
8566   }
8567 
FindById(Id find_id)8568   std::optional<RowReference> FindById(Id find_id) {
8569     std::optional<uint32_t> row = id().IndexOf(find_id);
8570     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
8571   }
8572 
Insert(const Row & row)8573   IdAndRow Insert(const Row& row) {
8574     uint32_t row_number = row_count();
8575     Id id = Id{row_number};
8576     type_.Append(string_pool()->InternString(row.type()));
8577     mutable_symbol_set_id()->Append(row.symbol_set_id);
8578     mutable_name()->Append(row.name);
8579     mutable_source_file()->Append(row.source_file);
8580     mutable_line_number()->Append(row.line_number);
8581     UpdateSelfOverlayAfterInsert();
8582     return IdAndRow{id, row_number, RowReference(this, row_number),
8583                      RowNumber(row_number)};
8584   }
8585 
8586 
8587 
id()8588   const IdColumn<SymbolTable::Id>& id() const {
8589     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
8590   }
type()8591   const TypedColumn<StringPool::Id>& type() const {
8592     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
8593   }
symbol_set_id()8594   const TypedColumn<uint32_t>& symbol_set_id() const {
8595     return static_cast<const ColumnType::symbol_set_id&>(columns()[ColumnIndex::symbol_set_id]);
8596   }
name()8597   const TypedColumn<StringPool::Id>& name() const {
8598     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
8599   }
source_file()8600   const TypedColumn<std::optional<StringPool::Id>>& source_file() const {
8601     return static_cast<const ColumnType::source_file&>(columns()[ColumnIndex::source_file]);
8602   }
line_number()8603   const TypedColumn<std::optional<uint32_t>>& line_number() const {
8604     return static_cast<const ColumnType::line_number&>(columns()[ColumnIndex::line_number]);
8605   }
8606 
mutable_symbol_set_id()8607   TypedColumn<uint32_t>* mutable_symbol_set_id() {
8608     return static_cast<ColumnType::symbol_set_id*>(
8609         GetColumn(ColumnIndex::symbol_set_id));
8610   }
mutable_name()8611   TypedColumn<StringPool::Id>* mutable_name() {
8612     return static_cast<ColumnType::name*>(
8613         GetColumn(ColumnIndex::name));
8614   }
mutable_source_file()8615   TypedColumn<std::optional<StringPool::Id>>* mutable_source_file() {
8616     return static_cast<ColumnType::source_file*>(
8617         GetColumn(ColumnIndex::source_file));
8618   }
mutable_line_number()8619   TypedColumn<std::optional<uint32_t>>* mutable_line_number() {
8620     return static_cast<ColumnType::line_number*>(
8621         GetColumn(ColumnIndex::line_number));
8622   }
8623 
8624  private:
8625 
8626 
8627   ColumnStorage<ColumnType::symbol_set_id::stored_type> symbol_set_id_;
8628   ColumnStorage<ColumnType::name::stored_type> name_;
8629   ColumnStorage<ColumnType::source_file::stored_type> source_file_;
8630   ColumnStorage<ColumnType::line_number::stored_type> line_number_;
8631 
8632   RefPtr<column::StorageLayer> id_storage_layer_;
8633   RefPtr<column::StorageLayer> type_storage_layer_;
8634   RefPtr<column::StorageLayer> symbol_set_id_storage_layer_;
8635   RefPtr<column::StorageLayer> name_storage_layer_;
8636   RefPtr<column::StorageLayer> source_file_storage_layer_;
8637   RefPtr<column::StorageLayer> line_number_storage_layer_;
8638 
8639   RefPtr<column::OverlayLayer> line_number_null_layer_;
8640 };
8641 
8642 
8643 class VulkanMemoryAllocationsTable : public macros_internal::MacroTable {
8644  public:
8645   static constexpr uint32_t kColumnCount = 16;
8646 
8647   struct Id : public BaseId {
8648     Id() = default;
IdId8649     explicit constexpr Id(uint32_t v) : BaseId(v) {}
8650   };
8651   static_assert(std::is_trivially_destructible_v<Id>,
8652                 "Inheritance used without trivial destruction");
8653 
8654   struct ColumnIndex {
8655     static constexpr uint32_t id = 0;
8656     static constexpr uint32_t type = 1;
8657     static constexpr uint32_t arg_set_id = 2;
8658     static constexpr uint32_t source = 3;
8659     static constexpr uint32_t operation = 4;
8660     static constexpr uint32_t timestamp = 5;
8661     static constexpr uint32_t upid = 6;
8662     static constexpr uint32_t device = 7;
8663     static constexpr uint32_t device_memory = 8;
8664     static constexpr uint32_t memory_type = 9;
8665     static constexpr uint32_t heap = 10;
8666     static constexpr uint32_t function_name = 11;
8667     static constexpr uint32_t object_handle = 12;
8668     static constexpr uint32_t memory_address = 13;
8669     static constexpr uint32_t memory_size = 14;
8670     static constexpr uint32_t scope = 15;
8671   };
8672   struct ColumnType {
8673     using id = IdColumn<VulkanMemoryAllocationsTable::Id>;
8674     using type = TypedColumn<StringPool::Id>;
8675     using arg_set_id = TypedColumn<std::optional<uint32_t>>;
8676     using source = TypedColumn<StringPool::Id>;
8677     using operation = TypedColumn<StringPool::Id>;
8678     using timestamp = TypedColumn<int64_t>;
8679     using upid = TypedColumn<std::optional<uint32_t>>;
8680     using device = TypedColumn<std::optional<int64_t>>;
8681     using device_memory = TypedColumn<std::optional<int64_t>>;
8682     using memory_type = TypedColumn<std::optional<uint32_t>>;
8683     using heap = TypedColumn<std::optional<uint32_t>>;
8684     using function_name = TypedColumn<std::optional<StringPool::Id>>;
8685     using object_handle = TypedColumn<std::optional<int64_t>>;
8686     using memory_address = TypedColumn<std::optional<int64_t>>;
8687     using memory_size = TypedColumn<std::optional<int64_t>>;
8688     using scope = TypedColumn<StringPool::Id>;
8689   };
8690   struct Row : public macros_internal::RootParentTable::Row {
8691     Row(std::optional<uint32_t> in_arg_set_id = {},
8692         StringPool::Id in_source = {},
8693         StringPool::Id in_operation = {},
8694         int64_t in_timestamp = {},
8695         std::optional<uint32_t> in_upid = {},
8696         std::optional<int64_t> in_device = {},
8697         std::optional<int64_t> in_device_memory = {},
8698         std::optional<uint32_t> in_memory_type = {},
8699         std::optional<uint32_t> in_heap = {},
8700         std::optional<StringPool::Id> in_function_name = {},
8701         std::optional<int64_t> in_object_handle = {},
8702         std::optional<int64_t> in_memory_address = {},
8703         std::optional<int64_t> in_memory_size = {},
8704         StringPool::Id in_scope = {},
8705         std::nullptr_t = nullptr)
RowRow8706         : macros_internal::RootParentTable::Row(),
8707           arg_set_id(in_arg_set_id),
8708           source(in_source),
8709           operation(in_operation),
8710           timestamp(in_timestamp),
8711           upid(in_upid),
8712           device(in_device),
8713           device_memory(in_device_memory),
8714           memory_type(in_memory_type),
8715           heap(in_heap),
8716           function_name(in_function_name),
8717           object_handle(in_object_handle),
8718           memory_address(in_memory_address),
8719           memory_size(in_memory_size),
8720           scope(in_scope) {
8721       type_ = "vulkan_memory_allocations";
8722     }
8723     std::optional<uint32_t> arg_set_id;
8724     StringPool::Id source;
8725     StringPool::Id operation;
8726     int64_t timestamp;
8727     std::optional<uint32_t> upid;
8728     std::optional<int64_t> device;
8729     std::optional<int64_t> device_memory;
8730     std::optional<uint32_t> memory_type;
8731     std::optional<uint32_t> heap;
8732     std::optional<StringPool::Id> function_name;
8733     std::optional<int64_t> object_handle;
8734     std::optional<int64_t> memory_address;
8735     std::optional<int64_t> memory_size;
8736     StringPool::Id scope;
8737 
8738     bool operator==(const VulkanMemoryAllocationsTable::Row& other) const {
8739       return type() == other.type() && ColumnType::arg_set_id::Equals(arg_set_id, other.arg_set_id) &&
8740        ColumnType::source::Equals(source, other.source) &&
8741        ColumnType::operation::Equals(operation, other.operation) &&
8742        ColumnType::timestamp::Equals(timestamp, other.timestamp) &&
8743        ColumnType::upid::Equals(upid, other.upid) &&
8744        ColumnType::device::Equals(device, other.device) &&
8745        ColumnType::device_memory::Equals(device_memory, other.device_memory) &&
8746        ColumnType::memory_type::Equals(memory_type, other.memory_type) &&
8747        ColumnType::heap::Equals(heap, other.heap) &&
8748        ColumnType::function_name::Equals(function_name, other.function_name) &&
8749        ColumnType::object_handle::Equals(object_handle, other.object_handle) &&
8750        ColumnType::memory_address::Equals(memory_address, other.memory_address) &&
8751        ColumnType::memory_size::Equals(memory_size, other.memory_size) &&
8752        ColumnType::scope::Equals(scope, other.scope);
8753     }
8754   };
8755   struct ColumnFlag {
8756     static constexpr uint32_t arg_set_id = ColumnType::arg_set_id::default_flags();
8757     static constexpr uint32_t source = ColumnType::source::default_flags();
8758     static constexpr uint32_t operation = ColumnType::operation::default_flags();
8759     static constexpr uint32_t timestamp = ColumnType::timestamp::default_flags();
8760     static constexpr uint32_t upid = ColumnType::upid::default_flags();
8761     static constexpr uint32_t device = ColumnType::device::default_flags();
8762     static constexpr uint32_t device_memory = ColumnType::device_memory::default_flags();
8763     static constexpr uint32_t memory_type = ColumnType::memory_type::default_flags();
8764     static constexpr uint32_t heap = ColumnType::heap::default_flags();
8765     static constexpr uint32_t function_name = ColumnType::function_name::default_flags();
8766     static constexpr uint32_t object_handle = ColumnType::object_handle::default_flags();
8767     static constexpr uint32_t memory_address = ColumnType::memory_address::default_flags();
8768     static constexpr uint32_t memory_size = ColumnType::memory_size::default_flags();
8769     static constexpr uint32_t scope = ColumnType::scope::default_flags();
8770   };
8771 
8772   class RowNumber;
8773   class ConstRowReference;
8774   class RowReference;
8775 
8776   class RowNumber : public macros_internal::AbstractRowNumber<
8777       VulkanMemoryAllocationsTable, ConstRowReference, RowReference> {
8778    public:
RowNumber(uint32_t row_number)8779     explicit RowNumber(uint32_t row_number)
8780         : AbstractRowNumber(row_number) {}
8781   };
8782   static_assert(std::is_trivially_destructible_v<RowNumber>,
8783                 "Inheritance used without trivial destruction");
8784 
8785   class ConstRowReference : public macros_internal::AbstractConstRowReference<
8786     VulkanMemoryAllocationsTable, RowNumber> {
8787    public:
ConstRowReference(const VulkanMemoryAllocationsTable * table,uint32_t row_number)8788     ConstRowReference(const VulkanMemoryAllocationsTable* table, uint32_t row_number)
8789         : AbstractConstRowReference(table, row_number) {}
8790 
id()8791     ColumnType::id::type id() const {
8792       return table()->id()[row_number_];
8793     }
type()8794     ColumnType::type::type type() const {
8795       return table()->type()[row_number_];
8796     }
arg_set_id()8797     ColumnType::arg_set_id::type arg_set_id() const {
8798       return table()->arg_set_id()[row_number_];
8799     }
source()8800     ColumnType::source::type source() const {
8801       return table()->source()[row_number_];
8802     }
operation()8803     ColumnType::operation::type operation() const {
8804       return table()->operation()[row_number_];
8805     }
timestamp()8806     ColumnType::timestamp::type timestamp() const {
8807       return table()->timestamp()[row_number_];
8808     }
upid()8809     ColumnType::upid::type upid() const {
8810       return table()->upid()[row_number_];
8811     }
device()8812     ColumnType::device::type device() const {
8813       return table()->device()[row_number_];
8814     }
device_memory()8815     ColumnType::device_memory::type device_memory() const {
8816       return table()->device_memory()[row_number_];
8817     }
memory_type()8818     ColumnType::memory_type::type memory_type() const {
8819       return table()->memory_type()[row_number_];
8820     }
heap()8821     ColumnType::heap::type heap() const {
8822       return table()->heap()[row_number_];
8823     }
function_name()8824     ColumnType::function_name::type function_name() const {
8825       return table()->function_name()[row_number_];
8826     }
object_handle()8827     ColumnType::object_handle::type object_handle() const {
8828       return table()->object_handle()[row_number_];
8829     }
memory_address()8830     ColumnType::memory_address::type memory_address() const {
8831       return table()->memory_address()[row_number_];
8832     }
memory_size()8833     ColumnType::memory_size::type memory_size() const {
8834       return table()->memory_size()[row_number_];
8835     }
scope()8836     ColumnType::scope::type scope() const {
8837       return table()->scope()[row_number_];
8838     }
8839   };
8840   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
8841                 "Inheritance used without trivial destruction");
8842   class RowReference : public ConstRowReference {
8843    public:
RowReference(const VulkanMemoryAllocationsTable * table,uint32_t row_number)8844     RowReference(const VulkanMemoryAllocationsTable* table, uint32_t row_number)
8845         : ConstRowReference(table, row_number) {}
8846 
set_arg_set_id(ColumnType::arg_set_id::non_optional_type v)8847     void set_arg_set_id(
8848         ColumnType::arg_set_id::non_optional_type v) {
8849       return mutable_table()->mutable_arg_set_id()->Set(row_number_, v);
8850     }
set_source(ColumnType::source::non_optional_type v)8851     void set_source(
8852         ColumnType::source::non_optional_type v) {
8853       return mutable_table()->mutable_source()->Set(row_number_, v);
8854     }
set_operation(ColumnType::operation::non_optional_type v)8855     void set_operation(
8856         ColumnType::operation::non_optional_type v) {
8857       return mutable_table()->mutable_operation()->Set(row_number_, v);
8858     }
set_timestamp(ColumnType::timestamp::non_optional_type v)8859     void set_timestamp(
8860         ColumnType::timestamp::non_optional_type v) {
8861       return mutable_table()->mutable_timestamp()->Set(row_number_, v);
8862     }
set_upid(ColumnType::upid::non_optional_type v)8863     void set_upid(
8864         ColumnType::upid::non_optional_type v) {
8865       return mutable_table()->mutable_upid()->Set(row_number_, v);
8866     }
set_device(ColumnType::device::non_optional_type v)8867     void set_device(
8868         ColumnType::device::non_optional_type v) {
8869       return mutable_table()->mutable_device()->Set(row_number_, v);
8870     }
set_device_memory(ColumnType::device_memory::non_optional_type v)8871     void set_device_memory(
8872         ColumnType::device_memory::non_optional_type v) {
8873       return mutable_table()->mutable_device_memory()->Set(row_number_, v);
8874     }
set_memory_type(ColumnType::memory_type::non_optional_type v)8875     void set_memory_type(
8876         ColumnType::memory_type::non_optional_type v) {
8877       return mutable_table()->mutable_memory_type()->Set(row_number_, v);
8878     }
set_heap(ColumnType::heap::non_optional_type v)8879     void set_heap(
8880         ColumnType::heap::non_optional_type v) {
8881       return mutable_table()->mutable_heap()->Set(row_number_, v);
8882     }
set_function_name(ColumnType::function_name::non_optional_type v)8883     void set_function_name(
8884         ColumnType::function_name::non_optional_type v) {
8885       return mutable_table()->mutable_function_name()->Set(row_number_, v);
8886     }
set_object_handle(ColumnType::object_handle::non_optional_type v)8887     void set_object_handle(
8888         ColumnType::object_handle::non_optional_type v) {
8889       return mutable_table()->mutable_object_handle()->Set(row_number_, v);
8890     }
set_memory_address(ColumnType::memory_address::non_optional_type v)8891     void set_memory_address(
8892         ColumnType::memory_address::non_optional_type v) {
8893       return mutable_table()->mutable_memory_address()->Set(row_number_, v);
8894     }
set_memory_size(ColumnType::memory_size::non_optional_type v)8895     void set_memory_size(
8896         ColumnType::memory_size::non_optional_type v) {
8897       return mutable_table()->mutable_memory_size()->Set(row_number_, v);
8898     }
set_scope(ColumnType::scope::non_optional_type v)8899     void set_scope(
8900         ColumnType::scope::non_optional_type v) {
8901       return mutable_table()->mutable_scope()->Set(row_number_, v);
8902     }
8903 
8904    private:
mutable_table()8905     VulkanMemoryAllocationsTable* mutable_table() const {
8906       return const_cast<VulkanMemoryAllocationsTable*>(table());
8907     }
8908   };
8909   static_assert(std::is_trivially_destructible_v<RowReference>,
8910                 "Inheritance used without trivial destruction");
8911 
8912   class ConstIterator;
8913   class ConstIterator : public macros_internal::AbstractConstIterator<
8914     ConstIterator, VulkanMemoryAllocationsTable, RowNumber, ConstRowReference> {
8915    public:
id()8916     ColumnType::id::type id() const {
8917       const auto& col = table()->id();
8918       return col.GetAtIdx(
8919         iterator_.StorageIndexForColumn(col.index_in_table()));
8920     }
type()8921     ColumnType::type::type type() const {
8922       const auto& col = table()->type();
8923       return col.GetAtIdx(
8924         iterator_.StorageIndexForColumn(col.index_in_table()));
8925     }
arg_set_id()8926     ColumnType::arg_set_id::type arg_set_id() const {
8927       const auto& col = table()->arg_set_id();
8928       return col.GetAtIdx(
8929         iterator_.StorageIndexForColumn(col.index_in_table()));
8930     }
source()8931     ColumnType::source::type source() const {
8932       const auto& col = table()->source();
8933       return col.GetAtIdx(
8934         iterator_.StorageIndexForColumn(col.index_in_table()));
8935     }
operation()8936     ColumnType::operation::type operation() const {
8937       const auto& col = table()->operation();
8938       return col.GetAtIdx(
8939         iterator_.StorageIndexForColumn(col.index_in_table()));
8940     }
timestamp()8941     ColumnType::timestamp::type timestamp() const {
8942       const auto& col = table()->timestamp();
8943       return col.GetAtIdx(
8944         iterator_.StorageIndexForColumn(col.index_in_table()));
8945     }
upid()8946     ColumnType::upid::type upid() const {
8947       const auto& col = table()->upid();
8948       return col.GetAtIdx(
8949         iterator_.StorageIndexForColumn(col.index_in_table()));
8950     }
device()8951     ColumnType::device::type device() const {
8952       const auto& col = table()->device();
8953       return col.GetAtIdx(
8954         iterator_.StorageIndexForColumn(col.index_in_table()));
8955     }
device_memory()8956     ColumnType::device_memory::type device_memory() const {
8957       const auto& col = table()->device_memory();
8958       return col.GetAtIdx(
8959         iterator_.StorageIndexForColumn(col.index_in_table()));
8960     }
memory_type()8961     ColumnType::memory_type::type memory_type() const {
8962       const auto& col = table()->memory_type();
8963       return col.GetAtIdx(
8964         iterator_.StorageIndexForColumn(col.index_in_table()));
8965     }
heap()8966     ColumnType::heap::type heap() const {
8967       const auto& col = table()->heap();
8968       return col.GetAtIdx(
8969         iterator_.StorageIndexForColumn(col.index_in_table()));
8970     }
function_name()8971     ColumnType::function_name::type function_name() const {
8972       const auto& col = table()->function_name();
8973       return col.GetAtIdx(
8974         iterator_.StorageIndexForColumn(col.index_in_table()));
8975     }
object_handle()8976     ColumnType::object_handle::type object_handle() const {
8977       const auto& col = table()->object_handle();
8978       return col.GetAtIdx(
8979         iterator_.StorageIndexForColumn(col.index_in_table()));
8980     }
memory_address()8981     ColumnType::memory_address::type memory_address() const {
8982       const auto& col = table()->memory_address();
8983       return col.GetAtIdx(
8984         iterator_.StorageIndexForColumn(col.index_in_table()));
8985     }
memory_size()8986     ColumnType::memory_size::type memory_size() const {
8987       const auto& col = table()->memory_size();
8988       return col.GetAtIdx(
8989         iterator_.StorageIndexForColumn(col.index_in_table()));
8990     }
scope()8991     ColumnType::scope::type scope() const {
8992       const auto& col = table()->scope();
8993       return col.GetAtIdx(
8994         iterator_.StorageIndexForColumn(col.index_in_table()));
8995     }
8996 
8997    protected:
ConstIterator(const VulkanMemoryAllocationsTable * table,Table::Iterator iterator)8998     explicit ConstIterator(const VulkanMemoryAllocationsTable* table,
8999                            Table::Iterator iterator)
9000         : AbstractConstIterator(table, std::move(iterator)) {}
9001 
CurrentRowNumber()9002     uint32_t CurrentRowNumber() const {
9003       return iterator_.StorageIndexForLastOverlay();
9004     }
9005 
9006    private:
9007     friend class VulkanMemoryAllocationsTable;
9008     friend class macros_internal::AbstractConstIterator<
9009       ConstIterator, VulkanMemoryAllocationsTable, RowNumber, ConstRowReference>;
9010   };
9011   class Iterator : public ConstIterator {
9012     public:
row_reference()9013      RowReference row_reference() const {
9014        return {const_cast<VulkanMemoryAllocationsTable*>(table()), CurrentRowNumber()};
9015      }
9016 
9017     private:
9018      friend class VulkanMemoryAllocationsTable;
9019 
Iterator(VulkanMemoryAllocationsTable * table,Table::Iterator iterator)9020      explicit Iterator(VulkanMemoryAllocationsTable* table, Table::Iterator iterator)
9021         : ConstIterator(table, std::move(iterator)) {}
9022   };
9023 
9024   struct IdAndRow {
9025     Id id;
9026     uint32_t row;
9027     RowReference row_reference;
9028     RowNumber row_number;
9029   };
9030 
GetColumns(VulkanMemoryAllocationsTable * self,const macros_internal::MacroTable * parent)9031   static std::vector<ColumnLegacy> GetColumns(
9032       VulkanMemoryAllocationsTable* self,
9033       const macros_internal::MacroTable* parent) {
9034     std::vector<ColumnLegacy> columns =
9035         CopyColumnsFromParentOrAddRootColumns(self, parent);
9036     uint32_t olay_idx = OverlayCount(parent);
9037     AddColumnToVector(columns, "arg_set_id", &self->arg_set_id_, ColumnFlag::arg_set_id,
9038                       static_cast<uint32_t>(columns.size()), olay_idx);
9039     AddColumnToVector(columns, "source", &self->source_, ColumnFlag::source,
9040                       static_cast<uint32_t>(columns.size()), olay_idx);
9041     AddColumnToVector(columns, "operation", &self->operation_, ColumnFlag::operation,
9042                       static_cast<uint32_t>(columns.size()), olay_idx);
9043     AddColumnToVector(columns, "timestamp", &self->timestamp_, ColumnFlag::timestamp,
9044                       static_cast<uint32_t>(columns.size()), olay_idx);
9045     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
9046                       static_cast<uint32_t>(columns.size()), olay_idx);
9047     AddColumnToVector(columns, "device", &self->device_, ColumnFlag::device,
9048                       static_cast<uint32_t>(columns.size()), olay_idx);
9049     AddColumnToVector(columns, "device_memory", &self->device_memory_, ColumnFlag::device_memory,
9050                       static_cast<uint32_t>(columns.size()), olay_idx);
9051     AddColumnToVector(columns, "memory_type", &self->memory_type_, ColumnFlag::memory_type,
9052                       static_cast<uint32_t>(columns.size()), olay_idx);
9053     AddColumnToVector(columns, "heap", &self->heap_, ColumnFlag::heap,
9054                       static_cast<uint32_t>(columns.size()), olay_idx);
9055     AddColumnToVector(columns, "function_name", &self->function_name_, ColumnFlag::function_name,
9056                       static_cast<uint32_t>(columns.size()), olay_idx);
9057     AddColumnToVector(columns, "object_handle", &self->object_handle_, ColumnFlag::object_handle,
9058                       static_cast<uint32_t>(columns.size()), olay_idx);
9059     AddColumnToVector(columns, "memory_address", &self->memory_address_, ColumnFlag::memory_address,
9060                       static_cast<uint32_t>(columns.size()), olay_idx);
9061     AddColumnToVector(columns, "memory_size", &self->memory_size_, ColumnFlag::memory_size,
9062                       static_cast<uint32_t>(columns.size()), olay_idx);
9063     AddColumnToVector(columns, "scope", &self->scope_, ColumnFlag::scope,
9064                       static_cast<uint32_t>(columns.size()), olay_idx);
9065     return columns;
9066   }
9067 
VulkanMemoryAllocationsTable(StringPool * pool)9068   PERFETTO_NO_INLINE explicit VulkanMemoryAllocationsTable(StringPool* pool)
9069       : macros_internal::MacroTable(
9070           pool,
9071           GetColumns(this, nullptr),
9072           nullptr),
9073         arg_set_id_(ColumnStorage<ColumnType::arg_set_id::stored_type>::Create<false>()),
9074         source_(ColumnStorage<ColumnType::source::stored_type>::Create<false>()),
9075         operation_(ColumnStorage<ColumnType::operation::stored_type>::Create<false>()),
9076         timestamp_(ColumnStorage<ColumnType::timestamp::stored_type>::Create<false>()),
9077         upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>()),
9078         device_(ColumnStorage<ColumnType::device::stored_type>::Create<false>()),
9079         device_memory_(ColumnStorage<ColumnType::device_memory::stored_type>::Create<false>()),
9080         memory_type_(ColumnStorage<ColumnType::memory_type::stored_type>::Create<false>()),
9081         heap_(ColumnStorage<ColumnType::heap::stored_type>::Create<false>()),
9082         function_name_(ColumnStorage<ColumnType::function_name::stored_type>::Create<false>()),
9083         object_handle_(ColumnStorage<ColumnType::object_handle::stored_type>::Create<false>()),
9084         memory_address_(ColumnStorage<ColumnType::memory_address::stored_type>::Create<false>()),
9085         memory_size_(ColumnStorage<ColumnType::memory_size::stored_type>::Create<false>()),
9086         scope_(ColumnStorage<ColumnType::scope::stored_type>::Create<false>())
9087 ,
9088         id_storage_layer_(new column::IdStorage()),
9089         type_storage_layer_(
9090           new column::StringStorage(string_pool(), &type_.vector())),
9091         arg_set_id_storage_layer_(
9092           new column::NumericStorage<ColumnType::arg_set_id::non_optional_stored_type>(
9093             &arg_set_id_.non_null_vector(),
9094             ColumnTypeHelper<ColumnType::arg_set_id::stored_type>::ToColumnType(),
9095             false)),
9096         source_storage_layer_(
9097           new column::StringStorage(string_pool(), &source_.vector())),
9098         operation_storage_layer_(
9099           new column::StringStorage(string_pool(), &operation_.vector())),
9100         timestamp_storage_layer_(
9101         new column::NumericStorage<ColumnType::timestamp::non_optional_stored_type>(
9102           &timestamp_.vector(),
9103           ColumnTypeHelper<ColumnType::timestamp::stored_type>::ToColumnType(),
9104           false)),
9105         upid_storage_layer_(
9106           new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
9107             &upid_.non_null_vector(),
9108             ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
9109             false)),
9110         device_storage_layer_(
9111           new column::NumericStorage<ColumnType::device::non_optional_stored_type>(
9112             &device_.non_null_vector(),
9113             ColumnTypeHelper<ColumnType::device::stored_type>::ToColumnType(),
9114             false)),
9115         device_memory_storage_layer_(
9116           new column::NumericStorage<ColumnType::device_memory::non_optional_stored_type>(
9117             &device_memory_.non_null_vector(),
9118             ColumnTypeHelper<ColumnType::device_memory::stored_type>::ToColumnType(),
9119             false)),
9120         memory_type_storage_layer_(
9121           new column::NumericStorage<ColumnType::memory_type::non_optional_stored_type>(
9122             &memory_type_.non_null_vector(),
9123             ColumnTypeHelper<ColumnType::memory_type::stored_type>::ToColumnType(),
9124             false)),
9125         heap_storage_layer_(
9126           new column::NumericStorage<ColumnType::heap::non_optional_stored_type>(
9127             &heap_.non_null_vector(),
9128             ColumnTypeHelper<ColumnType::heap::stored_type>::ToColumnType(),
9129             false)),
9130         function_name_storage_layer_(
9131           new column::StringStorage(string_pool(), &function_name_.vector())),
9132         object_handle_storage_layer_(
9133           new column::NumericStorage<ColumnType::object_handle::non_optional_stored_type>(
9134             &object_handle_.non_null_vector(),
9135             ColumnTypeHelper<ColumnType::object_handle::stored_type>::ToColumnType(),
9136             false)),
9137         memory_address_storage_layer_(
9138           new column::NumericStorage<ColumnType::memory_address::non_optional_stored_type>(
9139             &memory_address_.non_null_vector(),
9140             ColumnTypeHelper<ColumnType::memory_address::stored_type>::ToColumnType(),
9141             false)),
9142         memory_size_storage_layer_(
9143           new column::NumericStorage<ColumnType::memory_size::non_optional_stored_type>(
9144             &memory_size_.non_null_vector(),
9145             ColumnTypeHelper<ColumnType::memory_size::stored_type>::ToColumnType(),
9146             false)),
9147         scope_storage_layer_(
9148           new column::StringStorage(string_pool(), &scope_.vector()))
9149 ,
9150         arg_set_id_null_layer_(new column::NullOverlay(arg_set_id_.bv())),
9151         upid_null_layer_(new column::NullOverlay(upid_.bv())),
9152         device_null_layer_(new column::NullOverlay(device_.bv())),
9153         device_memory_null_layer_(new column::NullOverlay(device_memory_.bv())),
9154         memory_type_null_layer_(new column::NullOverlay(memory_type_.bv())),
9155         heap_null_layer_(new column::NullOverlay(heap_.bv())),
9156         object_handle_null_layer_(new column::NullOverlay(object_handle_.bv())),
9157         memory_address_null_layer_(new column::NullOverlay(memory_address_.bv())),
9158         memory_size_null_layer_(new column::NullOverlay(memory_size_.bv())) {
9159     static_assert(
9160         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::arg_set_id::stored_type>(
9161           ColumnFlag::arg_set_id),
9162         "Column type and flag combination is not valid");
9163       static_assert(
9164         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::source::stored_type>(
9165           ColumnFlag::source),
9166         "Column type and flag combination is not valid");
9167       static_assert(
9168         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::operation::stored_type>(
9169           ColumnFlag::operation),
9170         "Column type and flag combination is not valid");
9171       static_assert(
9172         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::timestamp::stored_type>(
9173           ColumnFlag::timestamp),
9174         "Column type and flag combination is not valid");
9175       static_assert(
9176         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
9177           ColumnFlag::upid),
9178         "Column type and flag combination is not valid");
9179       static_assert(
9180         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::device::stored_type>(
9181           ColumnFlag::device),
9182         "Column type and flag combination is not valid");
9183       static_assert(
9184         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::device_memory::stored_type>(
9185           ColumnFlag::device_memory),
9186         "Column type and flag combination is not valid");
9187       static_assert(
9188         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::memory_type::stored_type>(
9189           ColumnFlag::memory_type),
9190         "Column type and flag combination is not valid");
9191       static_assert(
9192         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::heap::stored_type>(
9193           ColumnFlag::heap),
9194         "Column type and flag combination is not valid");
9195       static_assert(
9196         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::function_name::stored_type>(
9197           ColumnFlag::function_name),
9198         "Column type and flag combination is not valid");
9199       static_assert(
9200         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::object_handle::stored_type>(
9201           ColumnFlag::object_handle),
9202         "Column type and flag combination is not valid");
9203       static_assert(
9204         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::memory_address::stored_type>(
9205           ColumnFlag::memory_address),
9206         "Column type and flag combination is not valid");
9207       static_assert(
9208         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::memory_size::stored_type>(
9209           ColumnFlag::memory_size),
9210         "Column type and flag combination is not valid");
9211       static_assert(
9212         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::scope::stored_type>(
9213           ColumnFlag::scope),
9214         "Column type and flag combination is not valid");
9215     OnConstructionCompletedRegularConstructor(
9216       {id_storage_layer_,type_storage_layer_,arg_set_id_storage_layer_,source_storage_layer_,operation_storage_layer_,timestamp_storage_layer_,upid_storage_layer_,device_storage_layer_,device_memory_storage_layer_,memory_type_storage_layer_,heap_storage_layer_,function_name_storage_layer_,object_handle_storage_layer_,memory_address_storage_layer_,memory_size_storage_layer_,scope_storage_layer_},
9217       {{},{},arg_set_id_null_layer_,{},{},{},upid_null_layer_,device_null_layer_,device_memory_null_layer_,memory_type_null_layer_,heap_null_layer_,{},object_handle_null_layer_,memory_address_null_layer_,memory_size_null_layer_,{}});
9218   }
9219   ~VulkanMemoryAllocationsTable() override;
9220 
Name()9221   static const char* Name() { return "vulkan_memory_allocations"; }
9222 
ComputeStaticSchema()9223   static Table::Schema ComputeStaticSchema() {
9224     Table::Schema schema;
9225     schema.columns.emplace_back(Table::Schema::Column{
9226         "id", SqlValue::Type::kLong, true, true, false, false});
9227     schema.columns.emplace_back(Table::Schema::Column{
9228         "type", SqlValue::Type::kString, false, false, false, false});
9229     schema.columns.emplace_back(Table::Schema::Column{
9230         "arg_set_id", ColumnType::arg_set_id::SqlValueType(), false,
9231         false,
9232         false,
9233         false});
9234     schema.columns.emplace_back(Table::Schema::Column{
9235         "source", ColumnType::source::SqlValueType(), false,
9236         false,
9237         false,
9238         false});
9239     schema.columns.emplace_back(Table::Schema::Column{
9240         "operation", ColumnType::operation::SqlValueType(), false,
9241         false,
9242         false,
9243         false});
9244     schema.columns.emplace_back(Table::Schema::Column{
9245         "timestamp", ColumnType::timestamp::SqlValueType(), false,
9246         false,
9247         false,
9248         false});
9249     schema.columns.emplace_back(Table::Schema::Column{
9250         "upid", ColumnType::upid::SqlValueType(), false,
9251         false,
9252         false,
9253         false});
9254     schema.columns.emplace_back(Table::Schema::Column{
9255         "device", ColumnType::device::SqlValueType(), false,
9256         false,
9257         false,
9258         false});
9259     schema.columns.emplace_back(Table::Schema::Column{
9260         "device_memory", ColumnType::device_memory::SqlValueType(), false,
9261         false,
9262         false,
9263         false});
9264     schema.columns.emplace_back(Table::Schema::Column{
9265         "memory_type", ColumnType::memory_type::SqlValueType(), false,
9266         false,
9267         false,
9268         false});
9269     schema.columns.emplace_back(Table::Schema::Column{
9270         "heap", ColumnType::heap::SqlValueType(), false,
9271         false,
9272         false,
9273         false});
9274     schema.columns.emplace_back(Table::Schema::Column{
9275         "function_name", ColumnType::function_name::SqlValueType(), false,
9276         false,
9277         false,
9278         false});
9279     schema.columns.emplace_back(Table::Schema::Column{
9280         "object_handle", ColumnType::object_handle::SqlValueType(), false,
9281         false,
9282         false,
9283         false});
9284     schema.columns.emplace_back(Table::Schema::Column{
9285         "memory_address", ColumnType::memory_address::SqlValueType(), false,
9286         false,
9287         false,
9288         false});
9289     schema.columns.emplace_back(Table::Schema::Column{
9290         "memory_size", ColumnType::memory_size::SqlValueType(), false,
9291         false,
9292         false,
9293         false});
9294     schema.columns.emplace_back(Table::Schema::Column{
9295         "scope", ColumnType::scope::SqlValueType(), false,
9296         false,
9297         false,
9298         false});
9299     return schema;
9300   }
9301 
IterateRows()9302   ConstIterator IterateRows() const {
9303     return ConstIterator(this, Table::IterateRows());
9304   }
9305 
IterateRows()9306   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
9307 
FilterToIterator(const Query & q)9308   ConstIterator FilterToIterator(const Query& q) const {
9309     return ConstIterator(this, QueryToIterator(q));
9310   }
9311 
FilterToIterator(const Query & q)9312   Iterator FilterToIterator(const Query& q) {
9313     return Iterator(this, QueryToIterator(q));
9314   }
9315 
ShrinkToFit()9316   void ShrinkToFit() {
9317     type_.ShrinkToFit();
9318     arg_set_id_.ShrinkToFit();
9319     source_.ShrinkToFit();
9320     operation_.ShrinkToFit();
9321     timestamp_.ShrinkToFit();
9322     upid_.ShrinkToFit();
9323     device_.ShrinkToFit();
9324     device_memory_.ShrinkToFit();
9325     memory_type_.ShrinkToFit();
9326     heap_.ShrinkToFit();
9327     function_name_.ShrinkToFit();
9328     object_handle_.ShrinkToFit();
9329     memory_address_.ShrinkToFit();
9330     memory_size_.ShrinkToFit();
9331     scope_.ShrinkToFit();
9332   }
9333 
9334   ConstRowReference operator[](uint32_t r) const {
9335     return ConstRowReference(this, r);
9336   }
9337   RowReference operator[](uint32_t r) { return RowReference(this, r); }
9338   ConstRowReference operator[](RowNumber r) const {
9339     return ConstRowReference(this, r.row_number());
9340   }
9341   RowReference operator[](RowNumber r) {
9342     return RowReference(this, r.row_number());
9343   }
9344 
FindById(Id find_id)9345   std::optional<ConstRowReference> FindById(Id find_id) const {
9346     std::optional<uint32_t> row = id().IndexOf(find_id);
9347     return row ? std::make_optional(ConstRowReference(this, *row))
9348                : std::nullopt;
9349   }
9350 
FindById(Id find_id)9351   std::optional<RowReference> FindById(Id find_id) {
9352     std::optional<uint32_t> row = id().IndexOf(find_id);
9353     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
9354   }
9355 
Insert(const Row & row)9356   IdAndRow Insert(const Row& row) {
9357     uint32_t row_number = row_count();
9358     Id id = Id{row_number};
9359     type_.Append(string_pool()->InternString(row.type()));
9360     mutable_arg_set_id()->Append(row.arg_set_id);
9361     mutable_source()->Append(row.source);
9362     mutable_operation()->Append(row.operation);
9363     mutable_timestamp()->Append(row.timestamp);
9364     mutable_upid()->Append(row.upid);
9365     mutable_device()->Append(row.device);
9366     mutable_device_memory()->Append(row.device_memory);
9367     mutable_memory_type()->Append(row.memory_type);
9368     mutable_heap()->Append(row.heap);
9369     mutable_function_name()->Append(row.function_name);
9370     mutable_object_handle()->Append(row.object_handle);
9371     mutable_memory_address()->Append(row.memory_address);
9372     mutable_memory_size()->Append(row.memory_size);
9373     mutable_scope()->Append(row.scope);
9374     UpdateSelfOverlayAfterInsert();
9375     return IdAndRow{id, row_number, RowReference(this, row_number),
9376                      RowNumber(row_number)};
9377   }
9378 
9379 
9380 
id()9381   const IdColumn<VulkanMemoryAllocationsTable::Id>& id() const {
9382     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
9383   }
type()9384   const TypedColumn<StringPool::Id>& type() const {
9385     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
9386   }
arg_set_id()9387   const TypedColumn<std::optional<uint32_t>>& arg_set_id() const {
9388     return static_cast<const ColumnType::arg_set_id&>(columns()[ColumnIndex::arg_set_id]);
9389   }
source()9390   const TypedColumn<StringPool::Id>& source() const {
9391     return static_cast<const ColumnType::source&>(columns()[ColumnIndex::source]);
9392   }
operation()9393   const TypedColumn<StringPool::Id>& operation() const {
9394     return static_cast<const ColumnType::operation&>(columns()[ColumnIndex::operation]);
9395   }
timestamp()9396   const TypedColumn<int64_t>& timestamp() const {
9397     return static_cast<const ColumnType::timestamp&>(columns()[ColumnIndex::timestamp]);
9398   }
upid()9399   const TypedColumn<std::optional<uint32_t>>& upid() const {
9400     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
9401   }
device()9402   const TypedColumn<std::optional<int64_t>>& device() const {
9403     return static_cast<const ColumnType::device&>(columns()[ColumnIndex::device]);
9404   }
device_memory()9405   const TypedColumn<std::optional<int64_t>>& device_memory() const {
9406     return static_cast<const ColumnType::device_memory&>(columns()[ColumnIndex::device_memory]);
9407   }
memory_type()9408   const TypedColumn<std::optional<uint32_t>>& memory_type() const {
9409     return static_cast<const ColumnType::memory_type&>(columns()[ColumnIndex::memory_type]);
9410   }
heap()9411   const TypedColumn<std::optional<uint32_t>>& heap() const {
9412     return static_cast<const ColumnType::heap&>(columns()[ColumnIndex::heap]);
9413   }
function_name()9414   const TypedColumn<std::optional<StringPool::Id>>& function_name() const {
9415     return static_cast<const ColumnType::function_name&>(columns()[ColumnIndex::function_name]);
9416   }
object_handle()9417   const TypedColumn<std::optional<int64_t>>& object_handle() const {
9418     return static_cast<const ColumnType::object_handle&>(columns()[ColumnIndex::object_handle]);
9419   }
memory_address()9420   const TypedColumn<std::optional<int64_t>>& memory_address() const {
9421     return static_cast<const ColumnType::memory_address&>(columns()[ColumnIndex::memory_address]);
9422   }
memory_size()9423   const TypedColumn<std::optional<int64_t>>& memory_size() const {
9424     return static_cast<const ColumnType::memory_size&>(columns()[ColumnIndex::memory_size]);
9425   }
scope()9426   const TypedColumn<StringPool::Id>& scope() const {
9427     return static_cast<const ColumnType::scope&>(columns()[ColumnIndex::scope]);
9428   }
9429 
mutable_arg_set_id()9430   TypedColumn<std::optional<uint32_t>>* mutable_arg_set_id() {
9431     return static_cast<ColumnType::arg_set_id*>(
9432         GetColumn(ColumnIndex::arg_set_id));
9433   }
mutable_source()9434   TypedColumn<StringPool::Id>* mutable_source() {
9435     return static_cast<ColumnType::source*>(
9436         GetColumn(ColumnIndex::source));
9437   }
mutable_operation()9438   TypedColumn<StringPool::Id>* mutable_operation() {
9439     return static_cast<ColumnType::operation*>(
9440         GetColumn(ColumnIndex::operation));
9441   }
mutable_timestamp()9442   TypedColumn<int64_t>* mutable_timestamp() {
9443     return static_cast<ColumnType::timestamp*>(
9444         GetColumn(ColumnIndex::timestamp));
9445   }
mutable_upid()9446   TypedColumn<std::optional<uint32_t>>* mutable_upid() {
9447     return static_cast<ColumnType::upid*>(
9448         GetColumn(ColumnIndex::upid));
9449   }
mutable_device()9450   TypedColumn<std::optional<int64_t>>* mutable_device() {
9451     return static_cast<ColumnType::device*>(
9452         GetColumn(ColumnIndex::device));
9453   }
mutable_device_memory()9454   TypedColumn<std::optional<int64_t>>* mutable_device_memory() {
9455     return static_cast<ColumnType::device_memory*>(
9456         GetColumn(ColumnIndex::device_memory));
9457   }
mutable_memory_type()9458   TypedColumn<std::optional<uint32_t>>* mutable_memory_type() {
9459     return static_cast<ColumnType::memory_type*>(
9460         GetColumn(ColumnIndex::memory_type));
9461   }
mutable_heap()9462   TypedColumn<std::optional<uint32_t>>* mutable_heap() {
9463     return static_cast<ColumnType::heap*>(
9464         GetColumn(ColumnIndex::heap));
9465   }
mutable_function_name()9466   TypedColumn<std::optional<StringPool::Id>>* mutable_function_name() {
9467     return static_cast<ColumnType::function_name*>(
9468         GetColumn(ColumnIndex::function_name));
9469   }
mutable_object_handle()9470   TypedColumn<std::optional<int64_t>>* mutable_object_handle() {
9471     return static_cast<ColumnType::object_handle*>(
9472         GetColumn(ColumnIndex::object_handle));
9473   }
mutable_memory_address()9474   TypedColumn<std::optional<int64_t>>* mutable_memory_address() {
9475     return static_cast<ColumnType::memory_address*>(
9476         GetColumn(ColumnIndex::memory_address));
9477   }
mutable_memory_size()9478   TypedColumn<std::optional<int64_t>>* mutable_memory_size() {
9479     return static_cast<ColumnType::memory_size*>(
9480         GetColumn(ColumnIndex::memory_size));
9481   }
mutable_scope()9482   TypedColumn<StringPool::Id>* mutable_scope() {
9483     return static_cast<ColumnType::scope*>(
9484         GetColumn(ColumnIndex::scope));
9485   }
9486 
9487  private:
9488 
9489 
9490   ColumnStorage<ColumnType::arg_set_id::stored_type> arg_set_id_;
9491   ColumnStorage<ColumnType::source::stored_type> source_;
9492   ColumnStorage<ColumnType::operation::stored_type> operation_;
9493   ColumnStorage<ColumnType::timestamp::stored_type> timestamp_;
9494   ColumnStorage<ColumnType::upid::stored_type> upid_;
9495   ColumnStorage<ColumnType::device::stored_type> device_;
9496   ColumnStorage<ColumnType::device_memory::stored_type> device_memory_;
9497   ColumnStorage<ColumnType::memory_type::stored_type> memory_type_;
9498   ColumnStorage<ColumnType::heap::stored_type> heap_;
9499   ColumnStorage<ColumnType::function_name::stored_type> function_name_;
9500   ColumnStorage<ColumnType::object_handle::stored_type> object_handle_;
9501   ColumnStorage<ColumnType::memory_address::stored_type> memory_address_;
9502   ColumnStorage<ColumnType::memory_size::stored_type> memory_size_;
9503   ColumnStorage<ColumnType::scope::stored_type> scope_;
9504 
9505   RefPtr<column::StorageLayer> id_storage_layer_;
9506   RefPtr<column::StorageLayer> type_storage_layer_;
9507   RefPtr<column::StorageLayer> arg_set_id_storage_layer_;
9508   RefPtr<column::StorageLayer> source_storage_layer_;
9509   RefPtr<column::StorageLayer> operation_storage_layer_;
9510   RefPtr<column::StorageLayer> timestamp_storage_layer_;
9511   RefPtr<column::StorageLayer> upid_storage_layer_;
9512   RefPtr<column::StorageLayer> device_storage_layer_;
9513   RefPtr<column::StorageLayer> device_memory_storage_layer_;
9514   RefPtr<column::StorageLayer> memory_type_storage_layer_;
9515   RefPtr<column::StorageLayer> heap_storage_layer_;
9516   RefPtr<column::StorageLayer> function_name_storage_layer_;
9517   RefPtr<column::StorageLayer> object_handle_storage_layer_;
9518   RefPtr<column::StorageLayer> memory_address_storage_layer_;
9519   RefPtr<column::StorageLayer> memory_size_storage_layer_;
9520   RefPtr<column::StorageLayer> scope_storage_layer_;
9521 
9522   RefPtr<column::OverlayLayer> arg_set_id_null_layer_;
9523   RefPtr<column::OverlayLayer> upid_null_layer_;
9524   RefPtr<column::OverlayLayer> device_null_layer_;
9525   RefPtr<column::OverlayLayer> device_memory_null_layer_;
9526   RefPtr<column::OverlayLayer> memory_type_null_layer_;
9527   RefPtr<column::OverlayLayer> heap_null_layer_;
9528   RefPtr<column::OverlayLayer> object_handle_null_layer_;
9529   RefPtr<column::OverlayLayer> memory_address_null_layer_;
9530   RefPtr<column::OverlayLayer> memory_size_null_layer_;
9531 };
9532 
9533 }  // namespace perfetto
9534 
9535 #endif  // SRC_TRACE_PROCESSOR_TABLES_PROFILER_TABLES_PY_H_
9536