1 #ifndef SRC_TRACE_PROCESSOR_TABLES_TRACK_TABLES_PY_H_
2 #define SRC_TRACE_PROCESSOR_TABLES_TRACK_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/metadata_tables_py.h"
38 
39 namespace perfetto::trace_processor::tables {
40 
41 class TrackTable : public macros_internal::MacroTable {
42  public:
43   static constexpr uint32_t kColumnCount = 10;
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 name = 2;
56     static constexpr uint32_t parent_id = 3;
57     static constexpr uint32_t source_arg_set_id = 4;
58     static constexpr uint32_t machine_id = 5;
59     static constexpr uint32_t classification = 6;
60     static constexpr uint32_t dimension_arg_set_id = 7;
61     static constexpr uint32_t event_type = 8;
62     static constexpr uint32_t counter_unit = 9;
63   };
64   struct ColumnType {
65     using id = IdColumn<TrackTable::Id>;
66     using type = TypedColumn<StringPool::Id>;
67     using name = TypedColumn<StringPool::Id>;
68     using parent_id = TypedColumn<std::optional<TrackTable::Id>>;
69     using source_arg_set_id = TypedColumn<std::optional<uint32_t>>;
70     using machine_id = TypedColumn<std::optional<MachineTable::Id>>;
71     using classification = TypedColumn<StringPool::Id>;
72     using dimension_arg_set_id = TypedColumn<std::optional<uint32_t>>;
73     using event_type = TypedColumn<StringPool::Id>;
74     using counter_unit = TypedColumn<std::optional<StringPool::Id>>;
75   };
76   struct Row : public macros_internal::RootParentTable::Row {
77     Row(StringPool::Id in_name = {},
78         std::optional<TrackTable::Id> in_parent_id = {},
79         std::optional<uint32_t> in_source_arg_set_id = {},
80         std::optional<MachineTable::Id> in_machine_id = {},
81         StringPool::Id in_classification = {},
82         std::optional<uint32_t> in_dimension_arg_set_id = {},
83         StringPool::Id in_event_type = {},
84         std::optional<StringPool::Id> in_counter_unit = {},
85         std::nullptr_t = nullptr)
RowRow86         : macros_internal::RootParentTable::Row(),
87           name(in_name),
88           parent_id(in_parent_id),
89           source_arg_set_id(in_source_arg_set_id),
90           machine_id(in_machine_id),
91           classification(in_classification),
92           dimension_arg_set_id(in_dimension_arg_set_id),
93           event_type(in_event_type),
94           counter_unit(in_counter_unit) {
95       type_ = "__intrinsic_track";
96     }
97     StringPool::Id name;
98     std::optional<TrackTable::Id> parent_id;
99     std::optional<uint32_t> source_arg_set_id;
100     std::optional<MachineTable::Id> machine_id;
101     StringPool::Id classification;
102     std::optional<uint32_t> dimension_arg_set_id;
103     StringPool::Id event_type;
104     std::optional<StringPool::Id> counter_unit;
105 
106     bool operator==(const TrackTable::Row& other) const {
107       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
108        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
109        ColumnType::source_arg_set_id::Equals(source_arg_set_id, other.source_arg_set_id) &&
110        ColumnType::machine_id::Equals(machine_id, other.machine_id) &&
111        ColumnType::classification::Equals(classification, other.classification) &&
112        ColumnType::dimension_arg_set_id::Equals(dimension_arg_set_id, other.dimension_arg_set_id) &&
113        ColumnType::event_type::Equals(event_type, other.event_type) &&
114        ColumnType::counter_unit::Equals(counter_unit, other.counter_unit);
115     }
116   };
117   struct ColumnFlag {
118     static constexpr uint32_t name = ColumnType::name::default_flags();
119     static constexpr uint32_t parent_id = ColumnType::parent_id::default_flags();
120     static constexpr uint32_t source_arg_set_id = ColumnType::source_arg_set_id::default_flags();
121     static constexpr uint32_t machine_id = ColumnType::machine_id::default_flags();
122     static constexpr uint32_t classification = ColumnType::classification::default_flags();
123     static constexpr uint32_t dimension_arg_set_id = ColumnType::dimension_arg_set_id::default_flags();
124     static constexpr uint32_t event_type = ColumnType::event_type::default_flags();
125     static constexpr uint32_t counter_unit = ColumnType::counter_unit::default_flags();
126   };
127 
128   class RowNumber;
129   class ConstRowReference;
130   class RowReference;
131 
132   class RowNumber : public macros_internal::AbstractRowNumber<
133       TrackTable, ConstRowReference, RowReference> {
134    public:
RowNumber(uint32_t row_number)135     explicit RowNumber(uint32_t row_number)
136         : AbstractRowNumber(row_number) {}
137   };
138   static_assert(std::is_trivially_destructible_v<RowNumber>,
139                 "Inheritance used without trivial destruction");
140 
141   class ConstRowReference : public macros_internal::AbstractConstRowReference<
142     TrackTable, RowNumber> {
143    public:
ConstRowReference(const TrackTable * table,uint32_t row_number)144     ConstRowReference(const TrackTable* table, uint32_t row_number)
145         : AbstractConstRowReference(table, row_number) {}
146 
id()147     ColumnType::id::type id() const {
148       return table()->id()[row_number_];
149     }
type()150     ColumnType::type::type type() const {
151       return table()->type()[row_number_];
152     }
name()153     ColumnType::name::type name() const {
154       return table()->name()[row_number_];
155     }
parent_id()156     ColumnType::parent_id::type parent_id() const {
157       return table()->parent_id()[row_number_];
158     }
source_arg_set_id()159     ColumnType::source_arg_set_id::type source_arg_set_id() const {
160       return table()->source_arg_set_id()[row_number_];
161     }
machine_id()162     ColumnType::machine_id::type machine_id() const {
163       return table()->machine_id()[row_number_];
164     }
classification()165     ColumnType::classification::type classification() const {
166       return table()->classification()[row_number_];
167     }
dimension_arg_set_id()168     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
169       return table()->dimension_arg_set_id()[row_number_];
170     }
event_type()171     ColumnType::event_type::type event_type() const {
172       return table()->event_type()[row_number_];
173     }
counter_unit()174     ColumnType::counter_unit::type counter_unit() const {
175       return table()->counter_unit()[row_number_];
176     }
177   };
178   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
179                 "Inheritance used without trivial destruction");
180   class RowReference : public ConstRowReference {
181    public:
RowReference(const TrackTable * table,uint32_t row_number)182     RowReference(const TrackTable* table, uint32_t row_number)
183         : ConstRowReference(table, row_number) {}
184 
set_name(ColumnType::name::non_optional_type v)185     void set_name(
186         ColumnType::name::non_optional_type v) {
187       return mutable_table()->mutable_name()->Set(row_number_, v);
188     }
set_parent_id(ColumnType::parent_id::non_optional_type v)189     void set_parent_id(
190         ColumnType::parent_id::non_optional_type v) {
191       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
192     }
set_source_arg_set_id(ColumnType::source_arg_set_id::non_optional_type v)193     void set_source_arg_set_id(
194         ColumnType::source_arg_set_id::non_optional_type v) {
195       return mutable_table()->mutable_source_arg_set_id()->Set(row_number_, v);
196     }
set_machine_id(ColumnType::machine_id::non_optional_type v)197     void set_machine_id(
198         ColumnType::machine_id::non_optional_type v) {
199       return mutable_table()->mutable_machine_id()->Set(row_number_, v);
200     }
set_classification(ColumnType::classification::non_optional_type v)201     void set_classification(
202         ColumnType::classification::non_optional_type v) {
203       return mutable_table()->mutable_classification()->Set(row_number_, v);
204     }
set_dimension_arg_set_id(ColumnType::dimension_arg_set_id::non_optional_type v)205     void set_dimension_arg_set_id(
206         ColumnType::dimension_arg_set_id::non_optional_type v) {
207       return mutable_table()->mutable_dimension_arg_set_id()->Set(row_number_, v);
208     }
set_event_type(ColumnType::event_type::non_optional_type v)209     void set_event_type(
210         ColumnType::event_type::non_optional_type v) {
211       return mutable_table()->mutable_event_type()->Set(row_number_, v);
212     }
set_counter_unit(ColumnType::counter_unit::non_optional_type v)213     void set_counter_unit(
214         ColumnType::counter_unit::non_optional_type v) {
215       return mutable_table()->mutable_counter_unit()->Set(row_number_, v);
216     }
217 
218    private:
mutable_table()219     TrackTable* mutable_table() const {
220       return const_cast<TrackTable*>(table());
221     }
222   };
223   static_assert(std::is_trivially_destructible_v<RowReference>,
224                 "Inheritance used without trivial destruction");
225 
226   class ConstIterator;
227   class ConstIterator : public macros_internal::AbstractConstIterator<
228     ConstIterator, TrackTable, RowNumber, ConstRowReference> {
229    public:
id()230     ColumnType::id::type id() const {
231       const auto& col = table()->id();
232       return col.GetAtIdx(
233         iterator_.StorageIndexForColumn(col.index_in_table()));
234     }
type()235     ColumnType::type::type type() const {
236       const auto& col = table()->type();
237       return col.GetAtIdx(
238         iterator_.StorageIndexForColumn(col.index_in_table()));
239     }
name()240     ColumnType::name::type name() const {
241       const auto& col = table()->name();
242       return col.GetAtIdx(
243         iterator_.StorageIndexForColumn(col.index_in_table()));
244     }
parent_id()245     ColumnType::parent_id::type parent_id() const {
246       const auto& col = table()->parent_id();
247       return col.GetAtIdx(
248         iterator_.StorageIndexForColumn(col.index_in_table()));
249     }
source_arg_set_id()250     ColumnType::source_arg_set_id::type source_arg_set_id() const {
251       const auto& col = table()->source_arg_set_id();
252       return col.GetAtIdx(
253         iterator_.StorageIndexForColumn(col.index_in_table()));
254     }
machine_id()255     ColumnType::machine_id::type machine_id() const {
256       const auto& col = table()->machine_id();
257       return col.GetAtIdx(
258         iterator_.StorageIndexForColumn(col.index_in_table()));
259     }
classification()260     ColumnType::classification::type classification() const {
261       const auto& col = table()->classification();
262       return col.GetAtIdx(
263         iterator_.StorageIndexForColumn(col.index_in_table()));
264     }
dimension_arg_set_id()265     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
266       const auto& col = table()->dimension_arg_set_id();
267       return col.GetAtIdx(
268         iterator_.StorageIndexForColumn(col.index_in_table()));
269     }
event_type()270     ColumnType::event_type::type event_type() const {
271       const auto& col = table()->event_type();
272       return col.GetAtIdx(
273         iterator_.StorageIndexForColumn(col.index_in_table()));
274     }
counter_unit()275     ColumnType::counter_unit::type counter_unit() const {
276       const auto& col = table()->counter_unit();
277       return col.GetAtIdx(
278         iterator_.StorageIndexForColumn(col.index_in_table()));
279     }
280 
281    protected:
ConstIterator(const TrackTable * table,Table::Iterator iterator)282     explicit ConstIterator(const TrackTable* table,
283                            Table::Iterator iterator)
284         : AbstractConstIterator(table, std::move(iterator)) {}
285 
CurrentRowNumber()286     uint32_t CurrentRowNumber() const {
287       return iterator_.StorageIndexForLastOverlay();
288     }
289 
290    private:
291     friend class TrackTable;
292     friend class macros_internal::AbstractConstIterator<
293       ConstIterator, TrackTable, RowNumber, ConstRowReference>;
294   };
295   class Iterator : public ConstIterator {
296     public:
row_reference()297      RowReference row_reference() const {
298        return {const_cast<TrackTable*>(table()), CurrentRowNumber()};
299      }
300 
301     private:
302      friend class TrackTable;
303 
Iterator(TrackTable * table,Table::Iterator iterator)304      explicit Iterator(TrackTable* table, Table::Iterator iterator)
305         : ConstIterator(table, std::move(iterator)) {}
306   };
307 
308   struct IdAndRow {
309     Id id;
310     uint32_t row;
311     RowReference row_reference;
312     RowNumber row_number;
313   };
314 
GetColumns(TrackTable * self,const macros_internal::MacroTable * parent)315   static std::vector<ColumnLegacy> GetColumns(
316       TrackTable* self,
317       const macros_internal::MacroTable* parent) {
318     std::vector<ColumnLegacy> columns =
319         CopyColumnsFromParentOrAddRootColumns(self, parent);
320     uint32_t olay_idx = OverlayCount(parent);
321     AddColumnToVector(columns, "name", &self->name_, ColumnFlag::name,
322                       static_cast<uint32_t>(columns.size()), olay_idx);
323     AddColumnToVector(columns, "parent_id", &self->parent_id_, ColumnFlag::parent_id,
324                       static_cast<uint32_t>(columns.size()), olay_idx);
325     AddColumnToVector(columns, "source_arg_set_id", &self->source_arg_set_id_, ColumnFlag::source_arg_set_id,
326                       static_cast<uint32_t>(columns.size()), olay_idx);
327     AddColumnToVector(columns, "machine_id", &self->machine_id_, ColumnFlag::machine_id,
328                       static_cast<uint32_t>(columns.size()), olay_idx);
329     AddColumnToVector(columns, "classification", &self->classification_, ColumnFlag::classification,
330                       static_cast<uint32_t>(columns.size()), olay_idx);
331     AddColumnToVector(columns, "dimension_arg_set_id", &self->dimension_arg_set_id_, ColumnFlag::dimension_arg_set_id,
332                       static_cast<uint32_t>(columns.size()), olay_idx);
333     AddColumnToVector(columns, "event_type", &self->event_type_, ColumnFlag::event_type,
334                       static_cast<uint32_t>(columns.size()), olay_idx);
335     AddColumnToVector(columns, "counter_unit", &self->counter_unit_, ColumnFlag::counter_unit,
336                       static_cast<uint32_t>(columns.size()), olay_idx);
337     return columns;
338   }
339 
TrackTable(StringPool * pool)340   PERFETTO_NO_INLINE explicit TrackTable(StringPool* pool)
341       : macros_internal::MacroTable(
342           pool,
343           GetColumns(this, nullptr),
344           nullptr),
345         name_(ColumnStorage<ColumnType::name::stored_type>::Create<false>()),
346         parent_id_(ColumnStorage<ColumnType::parent_id::stored_type>::Create<false>()),
347         source_arg_set_id_(ColumnStorage<ColumnType::source_arg_set_id::stored_type>::Create<false>()),
348         machine_id_(ColumnStorage<ColumnType::machine_id::stored_type>::Create<false>()),
349         classification_(ColumnStorage<ColumnType::classification::stored_type>::Create<false>()),
350         dimension_arg_set_id_(ColumnStorage<ColumnType::dimension_arg_set_id::stored_type>::Create<false>()),
351         event_type_(ColumnStorage<ColumnType::event_type::stored_type>::Create<false>()),
352         counter_unit_(ColumnStorage<ColumnType::counter_unit::stored_type>::Create<false>())
353 ,
354         id_storage_layer_(new column::IdStorage()),
355         type_storage_layer_(
356           new column::StringStorage(string_pool(), &type_.vector())),
357         name_storage_layer_(
358           new column::StringStorage(string_pool(), &name_.vector())),
359         parent_id_storage_layer_(
360           new column::NumericStorage<ColumnType::parent_id::non_optional_stored_type>(
361             &parent_id_.non_null_vector(),
362             ColumnTypeHelper<ColumnType::parent_id::stored_type>::ToColumnType(),
363             false)),
364         source_arg_set_id_storage_layer_(
365           new column::NumericStorage<ColumnType::source_arg_set_id::non_optional_stored_type>(
366             &source_arg_set_id_.non_null_vector(),
367             ColumnTypeHelper<ColumnType::source_arg_set_id::stored_type>::ToColumnType(),
368             false)),
369         machine_id_storage_layer_(
370           new column::NumericStorage<ColumnType::machine_id::non_optional_stored_type>(
371             &machine_id_.non_null_vector(),
372             ColumnTypeHelper<ColumnType::machine_id::stored_type>::ToColumnType(),
373             false)),
374         classification_storage_layer_(
375           new column::StringStorage(string_pool(), &classification_.vector())),
376         dimension_arg_set_id_storage_layer_(
377           new column::NumericStorage<ColumnType::dimension_arg_set_id::non_optional_stored_type>(
378             &dimension_arg_set_id_.non_null_vector(),
379             ColumnTypeHelper<ColumnType::dimension_arg_set_id::stored_type>::ToColumnType(),
380             false)),
381         event_type_storage_layer_(
382           new column::StringStorage(string_pool(), &event_type_.vector())),
383         counter_unit_storage_layer_(
384           new column::StringStorage(string_pool(), &counter_unit_.vector()))
385 ,
386         parent_id_null_layer_(new column::NullOverlay(parent_id_.bv())),
387         source_arg_set_id_null_layer_(new column::NullOverlay(source_arg_set_id_.bv())),
388         machine_id_null_layer_(new column::NullOverlay(machine_id_.bv())),
389         dimension_arg_set_id_null_layer_(new column::NullOverlay(dimension_arg_set_id_.bv())) {
390     static_assert(
391         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::name::stored_type>(
392           ColumnFlag::name),
393         "Column type and flag combination is not valid");
394       static_assert(
395         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::parent_id::stored_type>(
396           ColumnFlag::parent_id),
397         "Column type and flag combination is not valid");
398       static_assert(
399         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::source_arg_set_id::stored_type>(
400           ColumnFlag::source_arg_set_id),
401         "Column type and flag combination is not valid");
402       static_assert(
403         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::machine_id::stored_type>(
404           ColumnFlag::machine_id),
405         "Column type and flag combination is not valid");
406       static_assert(
407         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::classification::stored_type>(
408           ColumnFlag::classification),
409         "Column type and flag combination is not valid");
410       static_assert(
411         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::dimension_arg_set_id::stored_type>(
412           ColumnFlag::dimension_arg_set_id),
413         "Column type and flag combination is not valid");
414       static_assert(
415         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::event_type::stored_type>(
416           ColumnFlag::event_type),
417         "Column type and flag combination is not valid");
418       static_assert(
419         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::counter_unit::stored_type>(
420           ColumnFlag::counter_unit),
421         "Column type and flag combination is not valid");
422     OnConstructionCompletedRegularConstructor(
423       {id_storage_layer_,type_storage_layer_,name_storage_layer_,parent_id_storage_layer_,source_arg_set_id_storage_layer_,machine_id_storage_layer_,classification_storage_layer_,dimension_arg_set_id_storage_layer_,event_type_storage_layer_,counter_unit_storage_layer_},
424       {{},{},{},parent_id_null_layer_,source_arg_set_id_null_layer_,machine_id_null_layer_,{},dimension_arg_set_id_null_layer_,{},{}});
425   }
426   ~TrackTable() override;
427 
Name()428   static const char* Name() { return "__intrinsic_track"; }
429 
ComputeStaticSchema()430   static Table::Schema ComputeStaticSchema() {
431     Table::Schema schema;
432     schema.columns.emplace_back(Table::Schema::Column{
433         "id", SqlValue::Type::kLong, true, true, false, false});
434     schema.columns.emplace_back(Table::Schema::Column{
435         "type", SqlValue::Type::kString, false, false, false, false});
436     schema.columns.emplace_back(Table::Schema::Column{
437         "name", ColumnType::name::SqlValueType(), false,
438         false,
439         false,
440         false});
441     schema.columns.emplace_back(Table::Schema::Column{
442         "parent_id", ColumnType::parent_id::SqlValueType(), false,
443         false,
444         false,
445         false});
446     schema.columns.emplace_back(Table::Schema::Column{
447         "source_arg_set_id", ColumnType::source_arg_set_id::SqlValueType(), false,
448         false,
449         false,
450         false});
451     schema.columns.emplace_back(Table::Schema::Column{
452         "machine_id", ColumnType::machine_id::SqlValueType(), false,
453         false,
454         false,
455         false});
456     schema.columns.emplace_back(Table::Schema::Column{
457         "classification", ColumnType::classification::SqlValueType(), false,
458         false,
459         false,
460         false});
461     schema.columns.emplace_back(Table::Schema::Column{
462         "dimension_arg_set_id", ColumnType::dimension_arg_set_id::SqlValueType(), false,
463         false,
464         false,
465         false});
466     schema.columns.emplace_back(Table::Schema::Column{
467         "event_type", ColumnType::event_type::SqlValueType(), false,
468         false,
469         false,
470         false});
471     schema.columns.emplace_back(Table::Schema::Column{
472         "counter_unit", ColumnType::counter_unit::SqlValueType(), false,
473         false,
474         false,
475         false});
476     return schema;
477   }
478 
IterateRows()479   ConstIterator IterateRows() const {
480     return ConstIterator(this, Table::IterateRows());
481   }
482 
IterateRows()483   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
484 
FilterToIterator(const Query & q)485   ConstIterator FilterToIterator(const Query& q) const {
486     return ConstIterator(this, QueryToIterator(q));
487   }
488 
FilterToIterator(const Query & q)489   Iterator FilterToIterator(const Query& q) {
490     return Iterator(this, QueryToIterator(q));
491   }
492 
ShrinkToFit()493   void ShrinkToFit() {
494     type_.ShrinkToFit();
495     name_.ShrinkToFit();
496     parent_id_.ShrinkToFit();
497     source_arg_set_id_.ShrinkToFit();
498     machine_id_.ShrinkToFit();
499     classification_.ShrinkToFit();
500     dimension_arg_set_id_.ShrinkToFit();
501     event_type_.ShrinkToFit();
502     counter_unit_.ShrinkToFit();
503   }
504 
505   ConstRowReference operator[](uint32_t r) const {
506     return ConstRowReference(this, r);
507   }
508   RowReference operator[](uint32_t r) { return RowReference(this, r); }
509   ConstRowReference operator[](RowNumber r) const {
510     return ConstRowReference(this, r.row_number());
511   }
512   RowReference operator[](RowNumber r) {
513     return RowReference(this, r.row_number());
514   }
515 
FindById(Id find_id)516   std::optional<ConstRowReference> FindById(Id find_id) const {
517     std::optional<uint32_t> row = id().IndexOf(find_id);
518     return row ? std::make_optional(ConstRowReference(this, *row))
519                : std::nullopt;
520   }
521 
FindById(Id find_id)522   std::optional<RowReference> FindById(Id find_id) {
523     std::optional<uint32_t> row = id().IndexOf(find_id);
524     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
525   }
526 
Insert(const Row & row)527   IdAndRow Insert(const Row& row) {
528     uint32_t row_number = row_count();
529     Id id = Id{row_number};
530     type_.Append(string_pool()->InternString(row.type()));
531     mutable_name()->Append(row.name);
532     mutable_parent_id()->Append(row.parent_id);
533     mutable_source_arg_set_id()->Append(row.source_arg_set_id);
534     mutable_machine_id()->Append(row.machine_id);
535     mutable_classification()->Append(row.classification);
536     mutable_dimension_arg_set_id()->Append(row.dimension_arg_set_id);
537     mutable_event_type()->Append(row.event_type);
538     mutable_counter_unit()->Append(row.counter_unit);
539     UpdateSelfOverlayAfterInsert();
540     return IdAndRow{id, row_number, RowReference(this, row_number),
541                      RowNumber(row_number)};
542   }
543 
544 
545 
id()546   const IdColumn<TrackTable::Id>& id() const {
547     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
548   }
type()549   const TypedColumn<StringPool::Id>& type() const {
550     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
551   }
name()552   const TypedColumn<StringPool::Id>& name() const {
553     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
554   }
parent_id()555   const TypedColumn<std::optional<TrackTable::Id>>& parent_id() const {
556     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
557   }
source_arg_set_id()558   const TypedColumn<std::optional<uint32_t>>& source_arg_set_id() const {
559     return static_cast<const ColumnType::source_arg_set_id&>(columns()[ColumnIndex::source_arg_set_id]);
560   }
machine_id()561   const TypedColumn<std::optional<MachineTable::Id>>& machine_id() const {
562     return static_cast<const ColumnType::machine_id&>(columns()[ColumnIndex::machine_id]);
563   }
classification()564   const TypedColumn<StringPool::Id>& classification() const {
565     return static_cast<const ColumnType::classification&>(columns()[ColumnIndex::classification]);
566   }
dimension_arg_set_id()567   const TypedColumn<std::optional<uint32_t>>& dimension_arg_set_id() const {
568     return static_cast<const ColumnType::dimension_arg_set_id&>(columns()[ColumnIndex::dimension_arg_set_id]);
569   }
event_type()570   const TypedColumn<StringPool::Id>& event_type() const {
571     return static_cast<const ColumnType::event_type&>(columns()[ColumnIndex::event_type]);
572   }
counter_unit()573   const TypedColumn<std::optional<StringPool::Id>>& counter_unit() const {
574     return static_cast<const ColumnType::counter_unit&>(columns()[ColumnIndex::counter_unit]);
575   }
576 
mutable_name()577   TypedColumn<StringPool::Id>* mutable_name() {
578     return static_cast<ColumnType::name*>(
579         GetColumn(ColumnIndex::name));
580   }
mutable_parent_id()581   TypedColumn<std::optional<TrackTable::Id>>* mutable_parent_id() {
582     return static_cast<ColumnType::parent_id*>(
583         GetColumn(ColumnIndex::parent_id));
584   }
mutable_source_arg_set_id()585   TypedColumn<std::optional<uint32_t>>* mutable_source_arg_set_id() {
586     return static_cast<ColumnType::source_arg_set_id*>(
587         GetColumn(ColumnIndex::source_arg_set_id));
588   }
mutable_machine_id()589   TypedColumn<std::optional<MachineTable::Id>>* mutable_machine_id() {
590     return static_cast<ColumnType::machine_id*>(
591         GetColumn(ColumnIndex::machine_id));
592   }
mutable_classification()593   TypedColumn<StringPool::Id>* mutable_classification() {
594     return static_cast<ColumnType::classification*>(
595         GetColumn(ColumnIndex::classification));
596   }
mutable_dimension_arg_set_id()597   TypedColumn<std::optional<uint32_t>>* mutable_dimension_arg_set_id() {
598     return static_cast<ColumnType::dimension_arg_set_id*>(
599         GetColumn(ColumnIndex::dimension_arg_set_id));
600   }
mutable_event_type()601   TypedColumn<StringPool::Id>* mutable_event_type() {
602     return static_cast<ColumnType::event_type*>(
603         GetColumn(ColumnIndex::event_type));
604   }
mutable_counter_unit()605   TypedColumn<std::optional<StringPool::Id>>* mutable_counter_unit() {
606     return static_cast<ColumnType::counter_unit*>(
607         GetColumn(ColumnIndex::counter_unit));
608   }
609 
610  private:
611 
612 
613   ColumnStorage<ColumnType::name::stored_type> name_;
614   ColumnStorage<ColumnType::parent_id::stored_type> parent_id_;
615   ColumnStorage<ColumnType::source_arg_set_id::stored_type> source_arg_set_id_;
616   ColumnStorage<ColumnType::machine_id::stored_type> machine_id_;
617   ColumnStorage<ColumnType::classification::stored_type> classification_;
618   ColumnStorage<ColumnType::dimension_arg_set_id::stored_type> dimension_arg_set_id_;
619   ColumnStorage<ColumnType::event_type::stored_type> event_type_;
620   ColumnStorage<ColumnType::counter_unit::stored_type> counter_unit_;
621 
622   RefPtr<column::StorageLayer> id_storage_layer_;
623   RefPtr<column::StorageLayer> type_storage_layer_;
624   RefPtr<column::StorageLayer> name_storage_layer_;
625   RefPtr<column::StorageLayer> parent_id_storage_layer_;
626   RefPtr<column::StorageLayer> source_arg_set_id_storage_layer_;
627   RefPtr<column::StorageLayer> machine_id_storage_layer_;
628   RefPtr<column::StorageLayer> classification_storage_layer_;
629   RefPtr<column::StorageLayer> dimension_arg_set_id_storage_layer_;
630   RefPtr<column::StorageLayer> event_type_storage_layer_;
631   RefPtr<column::StorageLayer> counter_unit_storage_layer_;
632 
633   RefPtr<column::OverlayLayer> parent_id_null_layer_;
634   RefPtr<column::OverlayLayer> source_arg_set_id_null_layer_;
635   RefPtr<column::OverlayLayer> machine_id_null_layer_;
636   RefPtr<column::OverlayLayer> dimension_arg_set_id_null_layer_;
637 };
638 
639 
640 class CpuTrackTable : public macros_internal::MacroTable {
641  public:
642   static constexpr uint32_t kColumnCount = 11;
643 
644   using Id = TrackTable::Id;
645 
646   struct ColumnIndex {
647     static constexpr uint32_t id = 0;
648     static constexpr uint32_t type = 1;
649     static constexpr uint32_t name = 2;
650     static constexpr uint32_t parent_id = 3;
651     static constexpr uint32_t source_arg_set_id = 4;
652     static constexpr uint32_t machine_id = 5;
653     static constexpr uint32_t classification = 6;
654     static constexpr uint32_t dimension_arg_set_id = 7;
655     static constexpr uint32_t event_type = 8;
656     static constexpr uint32_t counter_unit = 9;
657     static constexpr uint32_t cpu = 10;
658   };
659   struct ColumnType {
660     using id = IdColumn<CpuTrackTable::Id>;
661     using type = TypedColumn<StringPool::Id>;
662     using name = TypedColumn<StringPool::Id>;
663     using parent_id = TypedColumn<std::optional<CpuTrackTable::Id>>;
664     using source_arg_set_id = TypedColumn<std::optional<uint32_t>>;
665     using machine_id = TypedColumn<std::optional<MachineTable::Id>>;
666     using classification = TypedColumn<StringPool::Id>;
667     using dimension_arg_set_id = TypedColumn<std::optional<uint32_t>>;
668     using event_type = TypedColumn<StringPool::Id>;
669     using counter_unit = TypedColumn<std::optional<StringPool::Id>>;
670     using cpu = TypedColumn<uint32_t>;
671   };
672   struct Row : public TrackTable::Row {
673     Row(StringPool::Id in_name = {},
674         std::optional<CpuTrackTable::Id> in_parent_id = {},
675         std::optional<uint32_t> in_source_arg_set_id = {},
676         std::optional<MachineTable::Id> in_machine_id = {},
677         StringPool::Id in_classification = {},
678         std::optional<uint32_t> in_dimension_arg_set_id = {},
679         StringPool::Id in_event_type = {},
680         std::optional<StringPool::Id> in_counter_unit = {},
681         uint32_t in_cpu = {},
682         std::nullptr_t = nullptr)
RowRow683         : TrackTable::Row(in_name, in_parent_id, in_source_arg_set_id, in_machine_id, in_classification, in_dimension_arg_set_id, in_event_type, in_counter_unit),
684           cpu(in_cpu) {
685       type_ = "__intrinsic_cpu_track";
686     }
687     uint32_t cpu;
688 
689     bool operator==(const CpuTrackTable::Row& other) const {
690       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
691        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
692        ColumnType::source_arg_set_id::Equals(source_arg_set_id, other.source_arg_set_id) &&
693        ColumnType::machine_id::Equals(machine_id, other.machine_id) &&
694        ColumnType::classification::Equals(classification, other.classification) &&
695        ColumnType::dimension_arg_set_id::Equals(dimension_arg_set_id, other.dimension_arg_set_id) &&
696        ColumnType::event_type::Equals(event_type, other.event_type) &&
697        ColumnType::counter_unit::Equals(counter_unit, other.counter_unit) &&
698        ColumnType::cpu::Equals(cpu, other.cpu);
699     }
700   };
701   struct ColumnFlag {
702     static constexpr uint32_t cpu = ColumnType::cpu::default_flags();
703   };
704 
705   class RowNumber;
706   class ConstRowReference;
707   class RowReference;
708 
709   class RowNumber : public macros_internal::AbstractRowNumber<
710       CpuTrackTable, ConstRowReference, RowReference> {
711    public:
RowNumber(uint32_t row_number)712     explicit RowNumber(uint32_t row_number)
713         : AbstractRowNumber(row_number) {}
714   };
715   static_assert(std::is_trivially_destructible_v<RowNumber>,
716                 "Inheritance used without trivial destruction");
717 
718   class ConstRowReference : public macros_internal::AbstractConstRowReference<
719     CpuTrackTable, RowNumber> {
720    public:
ConstRowReference(const CpuTrackTable * table,uint32_t row_number)721     ConstRowReference(const CpuTrackTable* table, uint32_t row_number)
722         : AbstractConstRowReference(table, row_number) {}
723 
id()724     ColumnType::id::type id() const {
725       return table()->id()[row_number_];
726     }
type()727     ColumnType::type::type type() const {
728       return table()->type()[row_number_];
729     }
name()730     ColumnType::name::type name() const {
731       return table()->name()[row_number_];
732     }
parent_id()733     ColumnType::parent_id::type parent_id() const {
734       return table()->parent_id()[row_number_];
735     }
source_arg_set_id()736     ColumnType::source_arg_set_id::type source_arg_set_id() const {
737       return table()->source_arg_set_id()[row_number_];
738     }
machine_id()739     ColumnType::machine_id::type machine_id() const {
740       return table()->machine_id()[row_number_];
741     }
classification()742     ColumnType::classification::type classification() const {
743       return table()->classification()[row_number_];
744     }
dimension_arg_set_id()745     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
746       return table()->dimension_arg_set_id()[row_number_];
747     }
event_type()748     ColumnType::event_type::type event_type() const {
749       return table()->event_type()[row_number_];
750     }
counter_unit()751     ColumnType::counter_unit::type counter_unit() const {
752       return table()->counter_unit()[row_number_];
753     }
cpu()754     ColumnType::cpu::type cpu() const {
755       return table()->cpu()[row_number_];
756     }
757   };
758   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
759                 "Inheritance used without trivial destruction");
760   class RowReference : public ConstRowReference {
761    public:
RowReference(const CpuTrackTable * table,uint32_t row_number)762     RowReference(const CpuTrackTable* table, uint32_t row_number)
763         : ConstRowReference(table, row_number) {}
764 
set_name(ColumnType::name::non_optional_type v)765     void set_name(
766         ColumnType::name::non_optional_type v) {
767       return mutable_table()->mutable_name()->Set(row_number_, v);
768     }
set_parent_id(ColumnType::parent_id::non_optional_type v)769     void set_parent_id(
770         ColumnType::parent_id::non_optional_type v) {
771       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
772     }
set_source_arg_set_id(ColumnType::source_arg_set_id::non_optional_type v)773     void set_source_arg_set_id(
774         ColumnType::source_arg_set_id::non_optional_type v) {
775       return mutable_table()->mutable_source_arg_set_id()->Set(row_number_, v);
776     }
set_machine_id(ColumnType::machine_id::non_optional_type v)777     void set_machine_id(
778         ColumnType::machine_id::non_optional_type v) {
779       return mutable_table()->mutable_machine_id()->Set(row_number_, v);
780     }
set_classification(ColumnType::classification::non_optional_type v)781     void set_classification(
782         ColumnType::classification::non_optional_type v) {
783       return mutable_table()->mutable_classification()->Set(row_number_, v);
784     }
set_dimension_arg_set_id(ColumnType::dimension_arg_set_id::non_optional_type v)785     void set_dimension_arg_set_id(
786         ColumnType::dimension_arg_set_id::non_optional_type v) {
787       return mutable_table()->mutable_dimension_arg_set_id()->Set(row_number_, v);
788     }
set_event_type(ColumnType::event_type::non_optional_type v)789     void set_event_type(
790         ColumnType::event_type::non_optional_type v) {
791       return mutable_table()->mutable_event_type()->Set(row_number_, v);
792     }
set_counter_unit(ColumnType::counter_unit::non_optional_type v)793     void set_counter_unit(
794         ColumnType::counter_unit::non_optional_type v) {
795       return mutable_table()->mutable_counter_unit()->Set(row_number_, v);
796     }
set_cpu(ColumnType::cpu::non_optional_type v)797     void set_cpu(
798         ColumnType::cpu::non_optional_type v) {
799       return mutable_table()->mutable_cpu()->Set(row_number_, v);
800     }
801 
802    private:
mutable_table()803     CpuTrackTable* mutable_table() const {
804       return const_cast<CpuTrackTable*>(table());
805     }
806   };
807   static_assert(std::is_trivially_destructible_v<RowReference>,
808                 "Inheritance used without trivial destruction");
809 
810   class ConstIterator;
811   class ConstIterator : public macros_internal::AbstractConstIterator<
812     ConstIterator, CpuTrackTable, RowNumber, ConstRowReference> {
813    public:
id()814     ColumnType::id::type id() const {
815       const auto& col = table()->id();
816       return col.GetAtIdx(
817         iterator_.StorageIndexForColumn(col.index_in_table()));
818     }
type()819     ColumnType::type::type type() const {
820       const auto& col = table()->type();
821       return col.GetAtIdx(
822         iterator_.StorageIndexForColumn(col.index_in_table()));
823     }
name()824     ColumnType::name::type name() const {
825       const auto& col = table()->name();
826       return col.GetAtIdx(
827         iterator_.StorageIndexForColumn(col.index_in_table()));
828     }
parent_id()829     ColumnType::parent_id::type parent_id() const {
830       const auto& col = table()->parent_id();
831       return col.GetAtIdx(
832         iterator_.StorageIndexForColumn(col.index_in_table()));
833     }
source_arg_set_id()834     ColumnType::source_arg_set_id::type source_arg_set_id() const {
835       const auto& col = table()->source_arg_set_id();
836       return col.GetAtIdx(
837         iterator_.StorageIndexForColumn(col.index_in_table()));
838     }
machine_id()839     ColumnType::machine_id::type machine_id() const {
840       const auto& col = table()->machine_id();
841       return col.GetAtIdx(
842         iterator_.StorageIndexForColumn(col.index_in_table()));
843     }
classification()844     ColumnType::classification::type classification() const {
845       const auto& col = table()->classification();
846       return col.GetAtIdx(
847         iterator_.StorageIndexForColumn(col.index_in_table()));
848     }
dimension_arg_set_id()849     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
850       const auto& col = table()->dimension_arg_set_id();
851       return col.GetAtIdx(
852         iterator_.StorageIndexForColumn(col.index_in_table()));
853     }
event_type()854     ColumnType::event_type::type event_type() const {
855       const auto& col = table()->event_type();
856       return col.GetAtIdx(
857         iterator_.StorageIndexForColumn(col.index_in_table()));
858     }
counter_unit()859     ColumnType::counter_unit::type counter_unit() const {
860       const auto& col = table()->counter_unit();
861       return col.GetAtIdx(
862         iterator_.StorageIndexForColumn(col.index_in_table()));
863     }
cpu()864     ColumnType::cpu::type cpu() const {
865       const auto& col = table()->cpu();
866       return col.GetAtIdx(
867         iterator_.StorageIndexForColumn(col.index_in_table()));
868     }
869 
870    protected:
ConstIterator(const CpuTrackTable * table,Table::Iterator iterator)871     explicit ConstIterator(const CpuTrackTable* table,
872                            Table::Iterator iterator)
873         : AbstractConstIterator(table, std::move(iterator)) {}
874 
CurrentRowNumber()875     uint32_t CurrentRowNumber() const {
876       return iterator_.StorageIndexForLastOverlay();
877     }
878 
879    private:
880     friend class CpuTrackTable;
881     friend class macros_internal::AbstractConstIterator<
882       ConstIterator, CpuTrackTable, RowNumber, ConstRowReference>;
883   };
884   class Iterator : public ConstIterator {
885     public:
row_reference()886      RowReference row_reference() const {
887        return {const_cast<CpuTrackTable*>(table()), CurrentRowNumber()};
888      }
889 
890     private:
891      friend class CpuTrackTable;
892 
Iterator(CpuTrackTable * table,Table::Iterator iterator)893      explicit Iterator(CpuTrackTable* table, Table::Iterator iterator)
894         : ConstIterator(table, std::move(iterator)) {}
895   };
896 
897   struct IdAndRow {
898     Id id;
899     uint32_t row;
900     RowReference row_reference;
901     RowNumber row_number;
902   };
903 
GetColumns(CpuTrackTable * self,const macros_internal::MacroTable * parent)904   static std::vector<ColumnLegacy> GetColumns(
905       CpuTrackTable* self,
906       const macros_internal::MacroTable* parent) {
907     std::vector<ColumnLegacy> columns =
908         CopyColumnsFromParentOrAddRootColumns(self, parent);
909     uint32_t olay_idx = OverlayCount(parent);
910     AddColumnToVector(columns, "cpu", &self->cpu_, ColumnFlag::cpu,
911                       static_cast<uint32_t>(columns.size()), olay_idx);
912     return columns;
913   }
914 
CpuTrackTable(StringPool * pool,TrackTable * parent)915   PERFETTO_NO_INLINE explicit CpuTrackTable(StringPool* pool, TrackTable* parent)
916       : macros_internal::MacroTable(
917           pool,
918           GetColumns(this, parent),
919           parent),
920         parent_(parent), const_parent_(parent), cpu_(ColumnStorage<ColumnType::cpu::stored_type>::Create<false>())
921 ,
922         cpu_storage_layer_(
923         new column::NumericStorage<ColumnType::cpu::non_optional_stored_type>(
924           &cpu_.vector(),
925           ColumnTypeHelper<ColumnType::cpu::stored_type>::ToColumnType(),
926           false))
927          {
928     static_assert(
929         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cpu::stored_type>(
930           ColumnFlag::cpu),
931         "Column type and flag combination is not valid");
932     OnConstructionCompletedRegularConstructor(
933       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],cpu_storage_layer_},
934       {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}});
935   }
936   ~CpuTrackTable() override;
937 
Name()938   static const char* Name() { return "__intrinsic_cpu_track"; }
939 
ComputeStaticSchema()940   static Table::Schema ComputeStaticSchema() {
941     Table::Schema schema;
942     schema.columns.emplace_back(Table::Schema::Column{
943         "id", SqlValue::Type::kLong, true, true, false, false});
944     schema.columns.emplace_back(Table::Schema::Column{
945         "type", SqlValue::Type::kString, false, false, false, false});
946     schema.columns.emplace_back(Table::Schema::Column{
947         "name", ColumnType::name::SqlValueType(), false,
948         false,
949         false,
950         false});
951     schema.columns.emplace_back(Table::Schema::Column{
952         "parent_id", ColumnType::parent_id::SqlValueType(), false,
953         false,
954         false,
955         false});
956     schema.columns.emplace_back(Table::Schema::Column{
957         "source_arg_set_id", ColumnType::source_arg_set_id::SqlValueType(), false,
958         false,
959         false,
960         false});
961     schema.columns.emplace_back(Table::Schema::Column{
962         "machine_id", ColumnType::machine_id::SqlValueType(), false,
963         false,
964         false,
965         false});
966     schema.columns.emplace_back(Table::Schema::Column{
967         "classification", ColumnType::classification::SqlValueType(), false,
968         false,
969         false,
970         false});
971     schema.columns.emplace_back(Table::Schema::Column{
972         "dimension_arg_set_id", ColumnType::dimension_arg_set_id::SqlValueType(), false,
973         false,
974         false,
975         false});
976     schema.columns.emplace_back(Table::Schema::Column{
977         "event_type", ColumnType::event_type::SqlValueType(), false,
978         false,
979         false,
980         false});
981     schema.columns.emplace_back(Table::Schema::Column{
982         "counter_unit", ColumnType::counter_unit::SqlValueType(), false,
983         false,
984         false,
985         false});
986     schema.columns.emplace_back(Table::Schema::Column{
987         "cpu", ColumnType::cpu::SqlValueType(), false,
988         false,
989         false,
990         false});
991     return schema;
992   }
993 
IterateRows()994   ConstIterator IterateRows() const {
995     return ConstIterator(this, Table::IterateRows());
996   }
997 
IterateRows()998   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
999 
FilterToIterator(const Query & q)1000   ConstIterator FilterToIterator(const Query& q) const {
1001     return ConstIterator(this, QueryToIterator(q));
1002   }
1003 
FilterToIterator(const Query & q)1004   Iterator FilterToIterator(const Query& q) {
1005     return Iterator(this, QueryToIterator(q));
1006   }
1007 
ShrinkToFit()1008   void ShrinkToFit() {
1009     cpu_.ShrinkToFit();
1010   }
1011 
1012   ConstRowReference operator[](uint32_t r) const {
1013     return ConstRowReference(this, r);
1014   }
1015   RowReference operator[](uint32_t r) { return RowReference(this, r); }
1016   ConstRowReference operator[](RowNumber r) const {
1017     return ConstRowReference(this, r.row_number());
1018   }
1019   RowReference operator[](RowNumber r) {
1020     return RowReference(this, r.row_number());
1021   }
1022 
FindById(Id find_id)1023   std::optional<ConstRowReference> FindById(Id find_id) const {
1024     std::optional<uint32_t> row = id().IndexOf(find_id);
1025     return row ? std::make_optional(ConstRowReference(this, *row))
1026                : std::nullopt;
1027   }
1028 
FindById(Id find_id)1029   std::optional<RowReference> FindById(Id find_id) {
1030     std::optional<uint32_t> row = id().IndexOf(find_id);
1031     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
1032   }
1033 
Insert(const Row & row)1034   IdAndRow Insert(const Row& row) {
1035     uint32_t row_number = row_count();
1036     Id id = Id{parent_->Insert(row).id};
1037     UpdateOverlaysAfterParentInsert();
1038     mutable_cpu()->Append(row.cpu);
1039     UpdateSelfOverlayAfterInsert();
1040     return IdAndRow{id, row_number, RowReference(this, row_number),
1041                      RowNumber(row_number)};
1042   }
1043 
ExtendParent(const TrackTable & parent,ColumnStorage<ColumnType::cpu::stored_type> cpu)1044   static std::unique_ptr<CpuTrackTable> ExtendParent(
1045       const TrackTable& parent,
1046       ColumnStorage<ColumnType::cpu::stored_type> cpu) {
1047     return std::unique_ptr<CpuTrackTable>(new CpuTrackTable(
1048         parent.string_pool(), parent, RowMap(0, parent.row_count()),
1049         std::move(cpu)));
1050   }
1051 
SelectAndExtendParent(const TrackTable & parent,std::vector<TrackTable::RowNumber> parent_overlay,ColumnStorage<ColumnType::cpu::stored_type> cpu)1052   static std::unique_ptr<CpuTrackTable> SelectAndExtendParent(
1053       const TrackTable& parent,
1054       std::vector<TrackTable::RowNumber> parent_overlay,
1055       ColumnStorage<ColumnType::cpu::stored_type> cpu) {
1056     std::vector<uint32_t> prs_untyped(parent_overlay.size());
1057     for (uint32_t i = 0; i < parent_overlay.size(); ++i) {
1058       prs_untyped[i] = parent_overlay[i].row_number();
1059     }
1060     return std::unique_ptr<CpuTrackTable>(new CpuTrackTable(
1061         parent.string_pool(), parent, RowMap(std::move(prs_untyped)),
1062         std::move(cpu)));
1063   }
1064 
id()1065   const IdColumn<CpuTrackTable::Id>& id() const {
1066     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
1067   }
type()1068   const TypedColumn<StringPool::Id>& type() const {
1069     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
1070   }
name()1071   const TypedColumn<StringPool::Id>& name() const {
1072     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
1073   }
parent_id()1074   const TypedColumn<std::optional<CpuTrackTable::Id>>& parent_id() const {
1075     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
1076   }
source_arg_set_id()1077   const TypedColumn<std::optional<uint32_t>>& source_arg_set_id() const {
1078     return static_cast<const ColumnType::source_arg_set_id&>(columns()[ColumnIndex::source_arg_set_id]);
1079   }
machine_id()1080   const TypedColumn<std::optional<MachineTable::Id>>& machine_id() const {
1081     return static_cast<const ColumnType::machine_id&>(columns()[ColumnIndex::machine_id]);
1082   }
classification()1083   const TypedColumn<StringPool::Id>& classification() const {
1084     return static_cast<const ColumnType::classification&>(columns()[ColumnIndex::classification]);
1085   }
dimension_arg_set_id()1086   const TypedColumn<std::optional<uint32_t>>& dimension_arg_set_id() const {
1087     return static_cast<const ColumnType::dimension_arg_set_id&>(columns()[ColumnIndex::dimension_arg_set_id]);
1088   }
event_type()1089   const TypedColumn<StringPool::Id>& event_type() const {
1090     return static_cast<const ColumnType::event_type&>(columns()[ColumnIndex::event_type]);
1091   }
counter_unit()1092   const TypedColumn<std::optional<StringPool::Id>>& counter_unit() const {
1093     return static_cast<const ColumnType::counter_unit&>(columns()[ColumnIndex::counter_unit]);
1094   }
cpu()1095   const TypedColumn<uint32_t>& cpu() const {
1096     return static_cast<const ColumnType::cpu&>(columns()[ColumnIndex::cpu]);
1097   }
1098 
mutable_name()1099   TypedColumn<StringPool::Id>* mutable_name() {
1100     return static_cast<ColumnType::name*>(
1101         GetColumn(ColumnIndex::name));
1102   }
mutable_parent_id()1103   TypedColumn<std::optional<CpuTrackTable::Id>>* mutable_parent_id() {
1104     return static_cast<ColumnType::parent_id*>(
1105         GetColumn(ColumnIndex::parent_id));
1106   }
mutable_source_arg_set_id()1107   TypedColumn<std::optional<uint32_t>>* mutable_source_arg_set_id() {
1108     return static_cast<ColumnType::source_arg_set_id*>(
1109         GetColumn(ColumnIndex::source_arg_set_id));
1110   }
mutable_machine_id()1111   TypedColumn<std::optional<MachineTable::Id>>* mutable_machine_id() {
1112     return static_cast<ColumnType::machine_id*>(
1113         GetColumn(ColumnIndex::machine_id));
1114   }
mutable_classification()1115   TypedColumn<StringPool::Id>* mutable_classification() {
1116     return static_cast<ColumnType::classification*>(
1117         GetColumn(ColumnIndex::classification));
1118   }
mutable_dimension_arg_set_id()1119   TypedColumn<std::optional<uint32_t>>* mutable_dimension_arg_set_id() {
1120     return static_cast<ColumnType::dimension_arg_set_id*>(
1121         GetColumn(ColumnIndex::dimension_arg_set_id));
1122   }
mutable_event_type()1123   TypedColumn<StringPool::Id>* mutable_event_type() {
1124     return static_cast<ColumnType::event_type*>(
1125         GetColumn(ColumnIndex::event_type));
1126   }
mutable_counter_unit()1127   TypedColumn<std::optional<StringPool::Id>>* mutable_counter_unit() {
1128     return static_cast<ColumnType::counter_unit*>(
1129         GetColumn(ColumnIndex::counter_unit));
1130   }
mutable_cpu()1131   TypedColumn<uint32_t>* mutable_cpu() {
1132     return static_cast<ColumnType::cpu*>(
1133         GetColumn(ColumnIndex::cpu));
1134   }
1135 
1136  private:
CpuTrackTable(StringPool * pool,const TrackTable & parent,const RowMap & parent_overlay,ColumnStorage<ColumnType::cpu::stored_type> cpu)1137   CpuTrackTable(StringPool* pool,
1138             const TrackTable& parent,
1139             const RowMap& parent_overlay,
1140             ColumnStorage<ColumnType::cpu::stored_type> cpu)
1141       : macros_internal::MacroTable(
1142           pool,
1143           GetColumns(this, &parent),
1144           parent,
1145           parent_overlay),
1146           const_parent_(&parent)
1147 ,
1148         cpu_storage_layer_(
1149         new column::NumericStorage<ColumnType::cpu::non_optional_stored_type>(
1150           &cpu_.vector(),
1151           ColumnTypeHelper<ColumnType::cpu::stored_type>::ToColumnType(),
1152           false))
1153          {
1154     static_assert(
1155         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::cpu::stored_type>(
1156           ColumnFlag::cpu),
1157         "Column type and flag combination is not valid");
1158     PERFETTO_DCHECK(cpu.size() == parent_overlay.size());
1159     cpu_ = std::move(cpu);
1160 
1161     std::vector<RefPtr<column::OverlayLayer>> overlay_layers(OverlayCount(&parent) + 1);
1162     for (uint32_t i = 0; i < overlay_layers.size(); ++i) {
1163       if (overlays()[i].row_map().IsIndexVector()) {
1164         overlay_layers[i].reset(new column::ArrangementOverlay(
1165             overlays()[i].row_map().GetIfIndexVector(),
1166             column::DataLayerChain::Indices::State::kNonmonotonic));
1167       } else if (overlays()[i].row_map().IsBitVector()) {
1168         overlay_layers[i].reset(new column::SelectorOverlay(
1169             overlays()[i].row_map().GetIfBitVector()));
1170       } else if (overlays()[i].row_map().IsRange()) {
1171         overlay_layers[i].reset(new column::RangeOverlay(
1172             overlays()[i].row_map().GetIfIRange()));
1173       }
1174     }
1175 
1176     OnConstructionCompleted(
1177       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],cpu_storage_layer_}, {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}}, std::move(overlay_layers));
1178   }
1179   TrackTable* parent_ = nullptr;
1180   const TrackTable* const_parent_ = nullptr;
1181   ColumnStorage<ColumnType::cpu::stored_type> cpu_;
1182 
1183   RefPtr<column::StorageLayer> cpu_storage_layer_;
1184 
1185 
1186 };
1187 
1188 
1189 class GpuTrackTable : public macros_internal::MacroTable {
1190  public:
1191   static constexpr uint32_t kColumnCount = 13;
1192 
1193   using Id = TrackTable::Id;
1194 
1195   struct ColumnIndex {
1196     static constexpr uint32_t id = 0;
1197     static constexpr uint32_t type = 1;
1198     static constexpr uint32_t name = 2;
1199     static constexpr uint32_t parent_id = 3;
1200     static constexpr uint32_t source_arg_set_id = 4;
1201     static constexpr uint32_t machine_id = 5;
1202     static constexpr uint32_t classification = 6;
1203     static constexpr uint32_t dimension_arg_set_id = 7;
1204     static constexpr uint32_t event_type = 8;
1205     static constexpr uint32_t counter_unit = 9;
1206     static constexpr uint32_t scope = 10;
1207     static constexpr uint32_t description = 11;
1208     static constexpr uint32_t context_id = 12;
1209   };
1210   struct ColumnType {
1211     using id = IdColumn<GpuTrackTable::Id>;
1212     using type = TypedColumn<StringPool::Id>;
1213     using name = TypedColumn<StringPool::Id>;
1214     using parent_id = TypedColumn<std::optional<GpuTrackTable::Id>>;
1215     using source_arg_set_id = TypedColumn<std::optional<uint32_t>>;
1216     using machine_id = TypedColumn<std::optional<MachineTable::Id>>;
1217     using classification = TypedColumn<StringPool::Id>;
1218     using dimension_arg_set_id = TypedColumn<std::optional<uint32_t>>;
1219     using event_type = TypedColumn<StringPool::Id>;
1220     using counter_unit = TypedColumn<std::optional<StringPool::Id>>;
1221     using scope = TypedColumn<StringPool::Id>;
1222     using description = TypedColumn<StringPool::Id>;
1223     using context_id = TypedColumn<std::optional<int64_t>>;
1224   };
1225   struct Row : public TrackTable::Row {
1226     Row(StringPool::Id in_name = {},
1227         std::optional<GpuTrackTable::Id> in_parent_id = {},
1228         std::optional<uint32_t> in_source_arg_set_id = {},
1229         std::optional<MachineTable::Id> in_machine_id = {},
1230         StringPool::Id in_classification = {},
1231         std::optional<uint32_t> in_dimension_arg_set_id = {},
1232         StringPool::Id in_event_type = {},
1233         std::optional<StringPool::Id> in_counter_unit = {},
1234         StringPool::Id in_scope = {},
1235         StringPool::Id in_description = {},
1236         std::optional<int64_t> in_context_id = {},
1237         std::nullptr_t = nullptr)
RowRow1238         : TrackTable::Row(in_name, in_parent_id, in_source_arg_set_id, in_machine_id, in_classification, in_dimension_arg_set_id, in_event_type, in_counter_unit),
1239           scope(in_scope),
1240           description(in_description),
1241           context_id(in_context_id) {
1242       type_ = "gpu_track";
1243     }
1244     StringPool::Id scope;
1245     StringPool::Id description;
1246     std::optional<int64_t> context_id;
1247 
1248     bool operator==(const GpuTrackTable::Row& other) const {
1249       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
1250        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
1251        ColumnType::source_arg_set_id::Equals(source_arg_set_id, other.source_arg_set_id) &&
1252        ColumnType::machine_id::Equals(machine_id, other.machine_id) &&
1253        ColumnType::classification::Equals(classification, other.classification) &&
1254        ColumnType::dimension_arg_set_id::Equals(dimension_arg_set_id, other.dimension_arg_set_id) &&
1255        ColumnType::event_type::Equals(event_type, other.event_type) &&
1256        ColumnType::counter_unit::Equals(counter_unit, other.counter_unit) &&
1257        ColumnType::scope::Equals(scope, other.scope) &&
1258        ColumnType::description::Equals(description, other.description) &&
1259        ColumnType::context_id::Equals(context_id, other.context_id);
1260     }
1261   };
1262   struct ColumnFlag {
1263     static constexpr uint32_t scope = ColumnType::scope::default_flags();
1264     static constexpr uint32_t description = ColumnType::description::default_flags();
1265     static constexpr uint32_t context_id = ColumnType::context_id::default_flags();
1266   };
1267 
1268   class RowNumber;
1269   class ConstRowReference;
1270   class RowReference;
1271 
1272   class RowNumber : public macros_internal::AbstractRowNumber<
1273       GpuTrackTable, ConstRowReference, RowReference> {
1274    public:
RowNumber(uint32_t row_number)1275     explicit RowNumber(uint32_t row_number)
1276         : AbstractRowNumber(row_number) {}
1277   };
1278   static_assert(std::is_trivially_destructible_v<RowNumber>,
1279                 "Inheritance used without trivial destruction");
1280 
1281   class ConstRowReference : public macros_internal::AbstractConstRowReference<
1282     GpuTrackTable, RowNumber> {
1283    public:
ConstRowReference(const GpuTrackTable * table,uint32_t row_number)1284     ConstRowReference(const GpuTrackTable* table, uint32_t row_number)
1285         : AbstractConstRowReference(table, row_number) {}
1286 
id()1287     ColumnType::id::type id() const {
1288       return table()->id()[row_number_];
1289     }
type()1290     ColumnType::type::type type() const {
1291       return table()->type()[row_number_];
1292     }
name()1293     ColumnType::name::type name() const {
1294       return table()->name()[row_number_];
1295     }
parent_id()1296     ColumnType::parent_id::type parent_id() const {
1297       return table()->parent_id()[row_number_];
1298     }
source_arg_set_id()1299     ColumnType::source_arg_set_id::type source_arg_set_id() const {
1300       return table()->source_arg_set_id()[row_number_];
1301     }
machine_id()1302     ColumnType::machine_id::type machine_id() const {
1303       return table()->machine_id()[row_number_];
1304     }
classification()1305     ColumnType::classification::type classification() const {
1306       return table()->classification()[row_number_];
1307     }
dimension_arg_set_id()1308     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
1309       return table()->dimension_arg_set_id()[row_number_];
1310     }
event_type()1311     ColumnType::event_type::type event_type() const {
1312       return table()->event_type()[row_number_];
1313     }
counter_unit()1314     ColumnType::counter_unit::type counter_unit() const {
1315       return table()->counter_unit()[row_number_];
1316     }
scope()1317     ColumnType::scope::type scope() const {
1318       return table()->scope()[row_number_];
1319     }
description()1320     ColumnType::description::type description() const {
1321       return table()->description()[row_number_];
1322     }
context_id()1323     ColumnType::context_id::type context_id() const {
1324       return table()->context_id()[row_number_];
1325     }
1326   };
1327   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
1328                 "Inheritance used without trivial destruction");
1329   class RowReference : public ConstRowReference {
1330    public:
RowReference(const GpuTrackTable * table,uint32_t row_number)1331     RowReference(const GpuTrackTable* table, uint32_t row_number)
1332         : ConstRowReference(table, row_number) {}
1333 
set_name(ColumnType::name::non_optional_type v)1334     void set_name(
1335         ColumnType::name::non_optional_type v) {
1336       return mutable_table()->mutable_name()->Set(row_number_, v);
1337     }
set_parent_id(ColumnType::parent_id::non_optional_type v)1338     void set_parent_id(
1339         ColumnType::parent_id::non_optional_type v) {
1340       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
1341     }
set_source_arg_set_id(ColumnType::source_arg_set_id::non_optional_type v)1342     void set_source_arg_set_id(
1343         ColumnType::source_arg_set_id::non_optional_type v) {
1344       return mutable_table()->mutable_source_arg_set_id()->Set(row_number_, v);
1345     }
set_machine_id(ColumnType::machine_id::non_optional_type v)1346     void set_machine_id(
1347         ColumnType::machine_id::non_optional_type v) {
1348       return mutable_table()->mutable_machine_id()->Set(row_number_, v);
1349     }
set_classification(ColumnType::classification::non_optional_type v)1350     void set_classification(
1351         ColumnType::classification::non_optional_type v) {
1352       return mutable_table()->mutable_classification()->Set(row_number_, v);
1353     }
set_dimension_arg_set_id(ColumnType::dimension_arg_set_id::non_optional_type v)1354     void set_dimension_arg_set_id(
1355         ColumnType::dimension_arg_set_id::non_optional_type v) {
1356       return mutable_table()->mutable_dimension_arg_set_id()->Set(row_number_, v);
1357     }
set_event_type(ColumnType::event_type::non_optional_type v)1358     void set_event_type(
1359         ColumnType::event_type::non_optional_type v) {
1360       return mutable_table()->mutable_event_type()->Set(row_number_, v);
1361     }
set_counter_unit(ColumnType::counter_unit::non_optional_type v)1362     void set_counter_unit(
1363         ColumnType::counter_unit::non_optional_type v) {
1364       return mutable_table()->mutable_counter_unit()->Set(row_number_, v);
1365     }
set_scope(ColumnType::scope::non_optional_type v)1366     void set_scope(
1367         ColumnType::scope::non_optional_type v) {
1368       return mutable_table()->mutable_scope()->Set(row_number_, v);
1369     }
set_description(ColumnType::description::non_optional_type v)1370     void set_description(
1371         ColumnType::description::non_optional_type v) {
1372       return mutable_table()->mutable_description()->Set(row_number_, v);
1373     }
set_context_id(ColumnType::context_id::non_optional_type v)1374     void set_context_id(
1375         ColumnType::context_id::non_optional_type v) {
1376       return mutable_table()->mutable_context_id()->Set(row_number_, v);
1377     }
1378 
1379    private:
mutable_table()1380     GpuTrackTable* mutable_table() const {
1381       return const_cast<GpuTrackTable*>(table());
1382     }
1383   };
1384   static_assert(std::is_trivially_destructible_v<RowReference>,
1385                 "Inheritance used without trivial destruction");
1386 
1387   class ConstIterator;
1388   class ConstIterator : public macros_internal::AbstractConstIterator<
1389     ConstIterator, GpuTrackTable, RowNumber, ConstRowReference> {
1390    public:
id()1391     ColumnType::id::type id() const {
1392       const auto& col = table()->id();
1393       return col.GetAtIdx(
1394         iterator_.StorageIndexForColumn(col.index_in_table()));
1395     }
type()1396     ColumnType::type::type type() const {
1397       const auto& col = table()->type();
1398       return col.GetAtIdx(
1399         iterator_.StorageIndexForColumn(col.index_in_table()));
1400     }
name()1401     ColumnType::name::type name() const {
1402       const auto& col = table()->name();
1403       return col.GetAtIdx(
1404         iterator_.StorageIndexForColumn(col.index_in_table()));
1405     }
parent_id()1406     ColumnType::parent_id::type parent_id() const {
1407       const auto& col = table()->parent_id();
1408       return col.GetAtIdx(
1409         iterator_.StorageIndexForColumn(col.index_in_table()));
1410     }
source_arg_set_id()1411     ColumnType::source_arg_set_id::type source_arg_set_id() const {
1412       const auto& col = table()->source_arg_set_id();
1413       return col.GetAtIdx(
1414         iterator_.StorageIndexForColumn(col.index_in_table()));
1415     }
machine_id()1416     ColumnType::machine_id::type machine_id() const {
1417       const auto& col = table()->machine_id();
1418       return col.GetAtIdx(
1419         iterator_.StorageIndexForColumn(col.index_in_table()));
1420     }
classification()1421     ColumnType::classification::type classification() const {
1422       const auto& col = table()->classification();
1423       return col.GetAtIdx(
1424         iterator_.StorageIndexForColumn(col.index_in_table()));
1425     }
dimension_arg_set_id()1426     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
1427       const auto& col = table()->dimension_arg_set_id();
1428       return col.GetAtIdx(
1429         iterator_.StorageIndexForColumn(col.index_in_table()));
1430     }
event_type()1431     ColumnType::event_type::type event_type() const {
1432       const auto& col = table()->event_type();
1433       return col.GetAtIdx(
1434         iterator_.StorageIndexForColumn(col.index_in_table()));
1435     }
counter_unit()1436     ColumnType::counter_unit::type counter_unit() const {
1437       const auto& col = table()->counter_unit();
1438       return col.GetAtIdx(
1439         iterator_.StorageIndexForColumn(col.index_in_table()));
1440     }
scope()1441     ColumnType::scope::type scope() const {
1442       const auto& col = table()->scope();
1443       return col.GetAtIdx(
1444         iterator_.StorageIndexForColumn(col.index_in_table()));
1445     }
description()1446     ColumnType::description::type description() const {
1447       const auto& col = table()->description();
1448       return col.GetAtIdx(
1449         iterator_.StorageIndexForColumn(col.index_in_table()));
1450     }
context_id()1451     ColumnType::context_id::type context_id() const {
1452       const auto& col = table()->context_id();
1453       return col.GetAtIdx(
1454         iterator_.StorageIndexForColumn(col.index_in_table()));
1455     }
1456 
1457    protected:
ConstIterator(const GpuTrackTable * table,Table::Iterator iterator)1458     explicit ConstIterator(const GpuTrackTable* table,
1459                            Table::Iterator iterator)
1460         : AbstractConstIterator(table, std::move(iterator)) {}
1461 
CurrentRowNumber()1462     uint32_t CurrentRowNumber() const {
1463       return iterator_.StorageIndexForLastOverlay();
1464     }
1465 
1466    private:
1467     friend class GpuTrackTable;
1468     friend class macros_internal::AbstractConstIterator<
1469       ConstIterator, GpuTrackTable, RowNumber, ConstRowReference>;
1470   };
1471   class Iterator : public ConstIterator {
1472     public:
row_reference()1473      RowReference row_reference() const {
1474        return {const_cast<GpuTrackTable*>(table()), CurrentRowNumber()};
1475      }
1476 
1477     private:
1478      friend class GpuTrackTable;
1479 
Iterator(GpuTrackTable * table,Table::Iterator iterator)1480      explicit Iterator(GpuTrackTable* table, Table::Iterator iterator)
1481         : ConstIterator(table, std::move(iterator)) {}
1482   };
1483 
1484   struct IdAndRow {
1485     Id id;
1486     uint32_t row;
1487     RowReference row_reference;
1488     RowNumber row_number;
1489   };
1490 
GetColumns(GpuTrackTable * self,const macros_internal::MacroTable * parent)1491   static std::vector<ColumnLegacy> GetColumns(
1492       GpuTrackTable* self,
1493       const macros_internal::MacroTable* parent) {
1494     std::vector<ColumnLegacy> columns =
1495         CopyColumnsFromParentOrAddRootColumns(self, parent);
1496     uint32_t olay_idx = OverlayCount(parent);
1497     AddColumnToVector(columns, "scope", &self->scope_, ColumnFlag::scope,
1498                       static_cast<uint32_t>(columns.size()), olay_idx);
1499     AddColumnToVector(columns, "description", &self->description_, ColumnFlag::description,
1500                       static_cast<uint32_t>(columns.size()), olay_idx);
1501     AddColumnToVector(columns, "context_id", &self->context_id_, ColumnFlag::context_id,
1502                       static_cast<uint32_t>(columns.size()), olay_idx);
1503     return columns;
1504   }
1505 
GpuTrackTable(StringPool * pool,TrackTable * parent)1506   PERFETTO_NO_INLINE explicit GpuTrackTable(StringPool* pool, TrackTable* parent)
1507       : macros_internal::MacroTable(
1508           pool,
1509           GetColumns(this, parent),
1510           parent),
1511         parent_(parent), const_parent_(parent), scope_(ColumnStorage<ColumnType::scope::stored_type>::Create<false>()),
1512         description_(ColumnStorage<ColumnType::description::stored_type>::Create<false>()),
1513         context_id_(ColumnStorage<ColumnType::context_id::stored_type>::Create<false>())
1514 ,
1515         scope_storage_layer_(
1516           new column::StringStorage(string_pool(), &scope_.vector())),
1517         description_storage_layer_(
1518           new column::StringStorage(string_pool(), &description_.vector())),
1519         context_id_storage_layer_(
1520           new column::NumericStorage<ColumnType::context_id::non_optional_stored_type>(
1521             &context_id_.non_null_vector(),
1522             ColumnTypeHelper<ColumnType::context_id::stored_type>::ToColumnType(),
1523             false))
1524 ,
1525         context_id_null_layer_(new column::NullOverlay(context_id_.bv())) {
1526     static_assert(
1527         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::scope::stored_type>(
1528           ColumnFlag::scope),
1529         "Column type and flag combination is not valid");
1530       static_assert(
1531         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::description::stored_type>(
1532           ColumnFlag::description),
1533         "Column type and flag combination is not valid");
1534       static_assert(
1535         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::context_id::stored_type>(
1536           ColumnFlag::context_id),
1537         "Column type and flag combination is not valid");
1538     OnConstructionCompletedRegularConstructor(
1539       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],scope_storage_layer_,description_storage_layer_,context_id_storage_layer_},
1540       {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{},{},context_id_null_layer_});
1541   }
1542   ~GpuTrackTable() override;
1543 
Name()1544   static const char* Name() { return "gpu_track"; }
1545 
ComputeStaticSchema()1546   static Table::Schema ComputeStaticSchema() {
1547     Table::Schema schema;
1548     schema.columns.emplace_back(Table::Schema::Column{
1549         "id", SqlValue::Type::kLong, true, true, false, false});
1550     schema.columns.emplace_back(Table::Schema::Column{
1551         "type", SqlValue::Type::kString, false, false, false, false});
1552     schema.columns.emplace_back(Table::Schema::Column{
1553         "name", ColumnType::name::SqlValueType(), false,
1554         false,
1555         false,
1556         false});
1557     schema.columns.emplace_back(Table::Schema::Column{
1558         "parent_id", ColumnType::parent_id::SqlValueType(), false,
1559         false,
1560         false,
1561         false});
1562     schema.columns.emplace_back(Table::Schema::Column{
1563         "source_arg_set_id", ColumnType::source_arg_set_id::SqlValueType(), false,
1564         false,
1565         false,
1566         false});
1567     schema.columns.emplace_back(Table::Schema::Column{
1568         "machine_id", ColumnType::machine_id::SqlValueType(), false,
1569         false,
1570         false,
1571         false});
1572     schema.columns.emplace_back(Table::Schema::Column{
1573         "classification", ColumnType::classification::SqlValueType(), false,
1574         false,
1575         false,
1576         false});
1577     schema.columns.emplace_back(Table::Schema::Column{
1578         "dimension_arg_set_id", ColumnType::dimension_arg_set_id::SqlValueType(), false,
1579         false,
1580         false,
1581         false});
1582     schema.columns.emplace_back(Table::Schema::Column{
1583         "event_type", ColumnType::event_type::SqlValueType(), false,
1584         false,
1585         false,
1586         false});
1587     schema.columns.emplace_back(Table::Schema::Column{
1588         "counter_unit", ColumnType::counter_unit::SqlValueType(), false,
1589         false,
1590         false,
1591         false});
1592     schema.columns.emplace_back(Table::Schema::Column{
1593         "scope", ColumnType::scope::SqlValueType(), false,
1594         false,
1595         false,
1596         false});
1597     schema.columns.emplace_back(Table::Schema::Column{
1598         "description", ColumnType::description::SqlValueType(), false,
1599         false,
1600         false,
1601         false});
1602     schema.columns.emplace_back(Table::Schema::Column{
1603         "context_id", ColumnType::context_id::SqlValueType(), false,
1604         false,
1605         false,
1606         false});
1607     return schema;
1608   }
1609 
IterateRows()1610   ConstIterator IterateRows() const {
1611     return ConstIterator(this, Table::IterateRows());
1612   }
1613 
IterateRows()1614   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
1615 
FilterToIterator(const Query & q)1616   ConstIterator FilterToIterator(const Query& q) const {
1617     return ConstIterator(this, QueryToIterator(q));
1618   }
1619 
FilterToIterator(const Query & q)1620   Iterator FilterToIterator(const Query& q) {
1621     return Iterator(this, QueryToIterator(q));
1622   }
1623 
ShrinkToFit()1624   void ShrinkToFit() {
1625     scope_.ShrinkToFit();
1626     description_.ShrinkToFit();
1627     context_id_.ShrinkToFit();
1628   }
1629 
1630   ConstRowReference operator[](uint32_t r) const {
1631     return ConstRowReference(this, r);
1632   }
1633   RowReference operator[](uint32_t r) { return RowReference(this, r); }
1634   ConstRowReference operator[](RowNumber r) const {
1635     return ConstRowReference(this, r.row_number());
1636   }
1637   RowReference operator[](RowNumber r) {
1638     return RowReference(this, r.row_number());
1639   }
1640 
FindById(Id find_id)1641   std::optional<ConstRowReference> FindById(Id find_id) const {
1642     std::optional<uint32_t> row = id().IndexOf(find_id);
1643     return row ? std::make_optional(ConstRowReference(this, *row))
1644                : std::nullopt;
1645   }
1646 
FindById(Id find_id)1647   std::optional<RowReference> FindById(Id find_id) {
1648     std::optional<uint32_t> row = id().IndexOf(find_id);
1649     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
1650   }
1651 
Insert(const Row & row)1652   IdAndRow Insert(const Row& row) {
1653     uint32_t row_number = row_count();
1654     Id id = Id{parent_->Insert(row).id};
1655     UpdateOverlaysAfterParentInsert();
1656     mutable_scope()->Append(row.scope);
1657     mutable_description()->Append(row.description);
1658     mutable_context_id()->Append(row.context_id);
1659     UpdateSelfOverlayAfterInsert();
1660     return IdAndRow{id, row_number, RowReference(this, row_number),
1661                      RowNumber(row_number)};
1662   }
1663 
ExtendParent(const TrackTable & parent,ColumnStorage<ColumnType::scope::stored_type> scope,ColumnStorage<ColumnType::description::stored_type> description,ColumnStorage<ColumnType::context_id::stored_type> context_id)1664   static std::unique_ptr<GpuTrackTable> ExtendParent(
1665       const TrackTable& parent,
1666       ColumnStorage<ColumnType::scope::stored_type> scope
1667 , ColumnStorage<ColumnType::description::stored_type> description
1668 , ColumnStorage<ColumnType::context_id::stored_type> context_id) {
1669     return std::unique_ptr<GpuTrackTable>(new GpuTrackTable(
1670         parent.string_pool(), parent, RowMap(0, parent.row_count()),
1671         std::move(scope), std::move(description), std::move(context_id)));
1672   }
1673 
SelectAndExtendParent(const TrackTable & parent,std::vector<TrackTable::RowNumber> parent_overlay,ColumnStorage<ColumnType::scope::stored_type> scope,ColumnStorage<ColumnType::description::stored_type> description,ColumnStorage<ColumnType::context_id::stored_type> context_id)1674   static std::unique_ptr<GpuTrackTable> SelectAndExtendParent(
1675       const TrackTable& parent,
1676       std::vector<TrackTable::RowNumber> parent_overlay,
1677       ColumnStorage<ColumnType::scope::stored_type> scope
1678 , ColumnStorage<ColumnType::description::stored_type> description
1679 , ColumnStorage<ColumnType::context_id::stored_type> context_id) {
1680     std::vector<uint32_t> prs_untyped(parent_overlay.size());
1681     for (uint32_t i = 0; i < parent_overlay.size(); ++i) {
1682       prs_untyped[i] = parent_overlay[i].row_number();
1683     }
1684     return std::unique_ptr<GpuTrackTable>(new GpuTrackTable(
1685         parent.string_pool(), parent, RowMap(std::move(prs_untyped)),
1686         std::move(scope), std::move(description), std::move(context_id)));
1687   }
1688 
id()1689   const IdColumn<GpuTrackTable::Id>& id() const {
1690     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
1691   }
type()1692   const TypedColumn<StringPool::Id>& type() const {
1693     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
1694   }
name()1695   const TypedColumn<StringPool::Id>& name() const {
1696     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
1697   }
parent_id()1698   const TypedColumn<std::optional<GpuTrackTable::Id>>& parent_id() const {
1699     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
1700   }
source_arg_set_id()1701   const TypedColumn<std::optional<uint32_t>>& source_arg_set_id() const {
1702     return static_cast<const ColumnType::source_arg_set_id&>(columns()[ColumnIndex::source_arg_set_id]);
1703   }
machine_id()1704   const TypedColumn<std::optional<MachineTable::Id>>& machine_id() const {
1705     return static_cast<const ColumnType::machine_id&>(columns()[ColumnIndex::machine_id]);
1706   }
classification()1707   const TypedColumn<StringPool::Id>& classification() const {
1708     return static_cast<const ColumnType::classification&>(columns()[ColumnIndex::classification]);
1709   }
dimension_arg_set_id()1710   const TypedColumn<std::optional<uint32_t>>& dimension_arg_set_id() const {
1711     return static_cast<const ColumnType::dimension_arg_set_id&>(columns()[ColumnIndex::dimension_arg_set_id]);
1712   }
event_type()1713   const TypedColumn<StringPool::Id>& event_type() const {
1714     return static_cast<const ColumnType::event_type&>(columns()[ColumnIndex::event_type]);
1715   }
counter_unit()1716   const TypedColumn<std::optional<StringPool::Id>>& counter_unit() const {
1717     return static_cast<const ColumnType::counter_unit&>(columns()[ColumnIndex::counter_unit]);
1718   }
scope()1719   const TypedColumn<StringPool::Id>& scope() const {
1720     return static_cast<const ColumnType::scope&>(columns()[ColumnIndex::scope]);
1721   }
description()1722   const TypedColumn<StringPool::Id>& description() const {
1723     return static_cast<const ColumnType::description&>(columns()[ColumnIndex::description]);
1724   }
context_id()1725   const TypedColumn<std::optional<int64_t>>& context_id() const {
1726     return static_cast<const ColumnType::context_id&>(columns()[ColumnIndex::context_id]);
1727   }
1728 
mutable_name()1729   TypedColumn<StringPool::Id>* mutable_name() {
1730     return static_cast<ColumnType::name*>(
1731         GetColumn(ColumnIndex::name));
1732   }
mutable_parent_id()1733   TypedColumn<std::optional<GpuTrackTable::Id>>* mutable_parent_id() {
1734     return static_cast<ColumnType::parent_id*>(
1735         GetColumn(ColumnIndex::parent_id));
1736   }
mutable_source_arg_set_id()1737   TypedColumn<std::optional<uint32_t>>* mutable_source_arg_set_id() {
1738     return static_cast<ColumnType::source_arg_set_id*>(
1739         GetColumn(ColumnIndex::source_arg_set_id));
1740   }
mutable_machine_id()1741   TypedColumn<std::optional<MachineTable::Id>>* mutable_machine_id() {
1742     return static_cast<ColumnType::machine_id*>(
1743         GetColumn(ColumnIndex::machine_id));
1744   }
mutable_classification()1745   TypedColumn<StringPool::Id>* mutable_classification() {
1746     return static_cast<ColumnType::classification*>(
1747         GetColumn(ColumnIndex::classification));
1748   }
mutable_dimension_arg_set_id()1749   TypedColumn<std::optional<uint32_t>>* mutable_dimension_arg_set_id() {
1750     return static_cast<ColumnType::dimension_arg_set_id*>(
1751         GetColumn(ColumnIndex::dimension_arg_set_id));
1752   }
mutable_event_type()1753   TypedColumn<StringPool::Id>* mutable_event_type() {
1754     return static_cast<ColumnType::event_type*>(
1755         GetColumn(ColumnIndex::event_type));
1756   }
mutable_counter_unit()1757   TypedColumn<std::optional<StringPool::Id>>* mutable_counter_unit() {
1758     return static_cast<ColumnType::counter_unit*>(
1759         GetColumn(ColumnIndex::counter_unit));
1760   }
mutable_scope()1761   TypedColumn<StringPool::Id>* mutable_scope() {
1762     return static_cast<ColumnType::scope*>(
1763         GetColumn(ColumnIndex::scope));
1764   }
mutable_description()1765   TypedColumn<StringPool::Id>* mutable_description() {
1766     return static_cast<ColumnType::description*>(
1767         GetColumn(ColumnIndex::description));
1768   }
mutable_context_id()1769   TypedColumn<std::optional<int64_t>>* mutable_context_id() {
1770     return static_cast<ColumnType::context_id*>(
1771         GetColumn(ColumnIndex::context_id));
1772   }
1773 
1774  private:
GpuTrackTable(StringPool * pool,const TrackTable & parent,const RowMap & parent_overlay,ColumnStorage<ColumnType::scope::stored_type> scope,ColumnStorage<ColumnType::description::stored_type> description,ColumnStorage<ColumnType::context_id::stored_type> context_id)1775   GpuTrackTable(StringPool* pool,
1776             const TrackTable& parent,
1777             const RowMap& parent_overlay,
1778             ColumnStorage<ColumnType::scope::stored_type> scope
1779 , ColumnStorage<ColumnType::description::stored_type> description
1780 , ColumnStorage<ColumnType::context_id::stored_type> context_id)
1781       : macros_internal::MacroTable(
1782           pool,
1783           GetColumns(this, &parent),
1784           parent,
1785           parent_overlay),
1786           const_parent_(&parent)
1787 ,
1788         scope_storage_layer_(
1789           new column::StringStorage(string_pool(), &scope_.vector())),
1790         description_storage_layer_(
1791           new column::StringStorage(string_pool(), &description_.vector())),
1792         context_id_storage_layer_(
1793           new column::NumericStorage<ColumnType::context_id::non_optional_stored_type>(
1794             &context_id_.non_null_vector(),
1795             ColumnTypeHelper<ColumnType::context_id::stored_type>::ToColumnType(),
1796             false))
1797 ,
1798         context_id_null_layer_(new column::NullOverlay(context_id_.bv())) {
1799     static_assert(
1800         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::scope::stored_type>(
1801           ColumnFlag::scope),
1802         "Column type and flag combination is not valid");
1803       static_assert(
1804         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::description::stored_type>(
1805           ColumnFlag::description),
1806         "Column type and flag combination is not valid");
1807       static_assert(
1808         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::context_id::stored_type>(
1809           ColumnFlag::context_id),
1810         "Column type and flag combination is not valid");
1811     PERFETTO_DCHECK(scope.size() == parent_overlay.size());
1812     scope_ = std::move(scope);
1813     PERFETTO_DCHECK(description.size() == parent_overlay.size());
1814     description_ = std::move(description);
1815     PERFETTO_DCHECK(context_id.size() == parent_overlay.size());
1816     context_id_ = std::move(context_id);
1817 
1818     std::vector<RefPtr<column::OverlayLayer>> overlay_layers(OverlayCount(&parent) + 1);
1819     for (uint32_t i = 0; i < overlay_layers.size(); ++i) {
1820       if (overlays()[i].row_map().IsIndexVector()) {
1821         overlay_layers[i].reset(new column::ArrangementOverlay(
1822             overlays()[i].row_map().GetIfIndexVector(),
1823             column::DataLayerChain::Indices::State::kNonmonotonic));
1824       } else if (overlays()[i].row_map().IsBitVector()) {
1825         overlay_layers[i].reset(new column::SelectorOverlay(
1826             overlays()[i].row_map().GetIfBitVector()));
1827       } else if (overlays()[i].row_map().IsRange()) {
1828         overlay_layers[i].reset(new column::RangeOverlay(
1829             overlays()[i].row_map().GetIfIRange()));
1830       }
1831     }
1832 
1833     OnConstructionCompleted(
1834       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],scope_storage_layer_,description_storage_layer_,context_id_storage_layer_}, {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{},{},context_id_null_layer_}, std::move(overlay_layers));
1835   }
1836   TrackTable* parent_ = nullptr;
1837   const TrackTable* const_parent_ = nullptr;
1838   ColumnStorage<ColumnType::scope::stored_type> scope_;
1839   ColumnStorage<ColumnType::description::stored_type> description_;
1840   ColumnStorage<ColumnType::context_id::stored_type> context_id_;
1841 
1842   RefPtr<column::StorageLayer> scope_storage_layer_;
1843   RefPtr<column::StorageLayer> description_storage_layer_;
1844   RefPtr<column::StorageLayer> context_id_storage_layer_;
1845 
1846   RefPtr<column::OverlayLayer> context_id_null_layer_;
1847 };
1848 
1849 
1850 class ProcessTrackTable : public macros_internal::MacroTable {
1851  public:
1852   static constexpr uint32_t kColumnCount = 11;
1853 
1854   using Id = TrackTable::Id;
1855 
1856   struct ColumnIndex {
1857     static constexpr uint32_t id = 0;
1858     static constexpr uint32_t type = 1;
1859     static constexpr uint32_t name = 2;
1860     static constexpr uint32_t parent_id = 3;
1861     static constexpr uint32_t source_arg_set_id = 4;
1862     static constexpr uint32_t machine_id = 5;
1863     static constexpr uint32_t classification = 6;
1864     static constexpr uint32_t dimension_arg_set_id = 7;
1865     static constexpr uint32_t event_type = 8;
1866     static constexpr uint32_t counter_unit = 9;
1867     static constexpr uint32_t upid = 10;
1868   };
1869   struct ColumnType {
1870     using id = IdColumn<ProcessTrackTable::Id>;
1871     using type = TypedColumn<StringPool::Id>;
1872     using name = TypedColumn<StringPool::Id>;
1873     using parent_id = TypedColumn<std::optional<ProcessTrackTable::Id>>;
1874     using source_arg_set_id = TypedColumn<std::optional<uint32_t>>;
1875     using machine_id = TypedColumn<std::optional<MachineTable::Id>>;
1876     using classification = TypedColumn<StringPool::Id>;
1877     using dimension_arg_set_id = TypedColumn<std::optional<uint32_t>>;
1878     using event_type = TypedColumn<StringPool::Id>;
1879     using counter_unit = TypedColumn<std::optional<StringPool::Id>>;
1880     using upid = TypedColumn<uint32_t>;
1881   };
1882   struct Row : public TrackTable::Row {
1883     Row(StringPool::Id in_name = {},
1884         std::optional<ProcessTrackTable::Id> in_parent_id = {},
1885         std::optional<uint32_t> in_source_arg_set_id = {},
1886         std::optional<MachineTable::Id> in_machine_id = {},
1887         StringPool::Id in_classification = {},
1888         std::optional<uint32_t> in_dimension_arg_set_id = {},
1889         StringPool::Id in_event_type = {},
1890         std::optional<StringPool::Id> in_counter_unit = {},
1891         uint32_t in_upid = {},
1892         std::nullptr_t = nullptr)
RowRow1893         : TrackTable::Row(in_name, in_parent_id, in_source_arg_set_id, in_machine_id, in_classification, in_dimension_arg_set_id, in_event_type, in_counter_unit),
1894           upid(in_upid) {
1895       type_ = "process_track";
1896     }
1897     uint32_t upid;
1898 
1899     bool operator==(const ProcessTrackTable::Row& other) const {
1900       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
1901        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
1902        ColumnType::source_arg_set_id::Equals(source_arg_set_id, other.source_arg_set_id) &&
1903        ColumnType::machine_id::Equals(machine_id, other.machine_id) &&
1904        ColumnType::classification::Equals(classification, other.classification) &&
1905        ColumnType::dimension_arg_set_id::Equals(dimension_arg_set_id, other.dimension_arg_set_id) &&
1906        ColumnType::event_type::Equals(event_type, other.event_type) &&
1907        ColumnType::counter_unit::Equals(counter_unit, other.counter_unit) &&
1908        ColumnType::upid::Equals(upid, other.upid);
1909     }
1910   };
1911   struct ColumnFlag {
1912     static constexpr uint32_t upid = ColumnType::upid::default_flags();
1913   };
1914 
1915   class RowNumber;
1916   class ConstRowReference;
1917   class RowReference;
1918 
1919   class RowNumber : public macros_internal::AbstractRowNumber<
1920       ProcessTrackTable, ConstRowReference, RowReference> {
1921    public:
RowNumber(uint32_t row_number)1922     explicit RowNumber(uint32_t row_number)
1923         : AbstractRowNumber(row_number) {}
1924   };
1925   static_assert(std::is_trivially_destructible_v<RowNumber>,
1926                 "Inheritance used without trivial destruction");
1927 
1928   class ConstRowReference : public macros_internal::AbstractConstRowReference<
1929     ProcessTrackTable, RowNumber> {
1930    public:
ConstRowReference(const ProcessTrackTable * table,uint32_t row_number)1931     ConstRowReference(const ProcessTrackTable* table, uint32_t row_number)
1932         : AbstractConstRowReference(table, row_number) {}
1933 
id()1934     ColumnType::id::type id() const {
1935       return table()->id()[row_number_];
1936     }
type()1937     ColumnType::type::type type() const {
1938       return table()->type()[row_number_];
1939     }
name()1940     ColumnType::name::type name() const {
1941       return table()->name()[row_number_];
1942     }
parent_id()1943     ColumnType::parent_id::type parent_id() const {
1944       return table()->parent_id()[row_number_];
1945     }
source_arg_set_id()1946     ColumnType::source_arg_set_id::type source_arg_set_id() const {
1947       return table()->source_arg_set_id()[row_number_];
1948     }
machine_id()1949     ColumnType::machine_id::type machine_id() const {
1950       return table()->machine_id()[row_number_];
1951     }
classification()1952     ColumnType::classification::type classification() const {
1953       return table()->classification()[row_number_];
1954     }
dimension_arg_set_id()1955     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
1956       return table()->dimension_arg_set_id()[row_number_];
1957     }
event_type()1958     ColumnType::event_type::type event_type() const {
1959       return table()->event_type()[row_number_];
1960     }
counter_unit()1961     ColumnType::counter_unit::type counter_unit() const {
1962       return table()->counter_unit()[row_number_];
1963     }
upid()1964     ColumnType::upid::type upid() const {
1965       return table()->upid()[row_number_];
1966     }
1967   };
1968   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
1969                 "Inheritance used without trivial destruction");
1970   class RowReference : public ConstRowReference {
1971    public:
RowReference(const ProcessTrackTable * table,uint32_t row_number)1972     RowReference(const ProcessTrackTable* table, uint32_t row_number)
1973         : ConstRowReference(table, row_number) {}
1974 
set_name(ColumnType::name::non_optional_type v)1975     void set_name(
1976         ColumnType::name::non_optional_type v) {
1977       return mutable_table()->mutable_name()->Set(row_number_, v);
1978     }
set_parent_id(ColumnType::parent_id::non_optional_type v)1979     void set_parent_id(
1980         ColumnType::parent_id::non_optional_type v) {
1981       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
1982     }
set_source_arg_set_id(ColumnType::source_arg_set_id::non_optional_type v)1983     void set_source_arg_set_id(
1984         ColumnType::source_arg_set_id::non_optional_type v) {
1985       return mutable_table()->mutable_source_arg_set_id()->Set(row_number_, v);
1986     }
set_machine_id(ColumnType::machine_id::non_optional_type v)1987     void set_machine_id(
1988         ColumnType::machine_id::non_optional_type v) {
1989       return mutable_table()->mutable_machine_id()->Set(row_number_, v);
1990     }
set_classification(ColumnType::classification::non_optional_type v)1991     void set_classification(
1992         ColumnType::classification::non_optional_type v) {
1993       return mutable_table()->mutable_classification()->Set(row_number_, v);
1994     }
set_dimension_arg_set_id(ColumnType::dimension_arg_set_id::non_optional_type v)1995     void set_dimension_arg_set_id(
1996         ColumnType::dimension_arg_set_id::non_optional_type v) {
1997       return mutable_table()->mutable_dimension_arg_set_id()->Set(row_number_, v);
1998     }
set_event_type(ColumnType::event_type::non_optional_type v)1999     void set_event_type(
2000         ColumnType::event_type::non_optional_type v) {
2001       return mutable_table()->mutable_event_type()->Set(row_number_, v);
2002     }
set_counter_unit(ColumnType::counter_unit::non_optional_type v)2003     void set_counter_unit(
2004         ColumnType::counter_unit::non_optional_type v) {
2005       return mutable_table()->mutable_counter_unit()->Set(row_number_, v);
2006     }
set_upid(ColumnType::upid::non_optional_type v)2007     void set_upid(
2008         ColumnType::upid::non_optional_type v) {
2009       return mutable_table()->mutable_upid()->Set(row_number_, v);
2010     }
2011 
2012    private:
mutable_table()2013     ProcessTrackTable* mutable_table() const {
2014       return const_cast<ProcessTrackTable*>(table());
2015     }
2016   };
2017   static_assert(std::is_trivially_destructible_v<RowReference>,
2018                 "Inheritance used without trivial destruction");
2019 
2020   class ConstIterator;
2021   class ConstIterator : public macros_internal::AbstractConstIterator<
2022     ConstIterator, ProcessTrackTable, RowNumber, ConstRowReference> {
2023    public:
id()2024     ColumnType::id::type id() const {
2025       const auto& col = table()->id();
2026       return col.GetAtIdx(
2027         iterator_.StorageIndexForColumn(col.index_in_table()));
2028     }
type()2029     ColumnType::type::type type() const {
2030       const auto& col = table()->type();
2031       return col.GetAtIdx(
2032         iterator_.StorageIndexForColumn(col.index_in_table()));
2033     }
name()2034     ColumnType::name::type name() const {
2035       const auto& col = table()->name();
2036       return col.GetAtIdx(
2037         iterator_.StorageIndexForColumn(col.index_in_table()));
2038     }
parent_id()2039     ColumnType::parent_id::type parent_id() const {
2040       const auto& col = table()->parent_id();
2041       return col.GetAtIdx(
2042         iterator_.StorageIndexForColumn(col.index_in_table()));
2043     }
source_arg_set_id()2044     ColumnType::source_arg_set_id::type source_arg_set_id() const {
2045       const auto& col = table()->source_arg_set_id();
2046       return col.GetAtIdx(
2047         iterator_.StorageIndexForColumn(col.index_in_table()));
2048     }
machine_id()2049     ColumnType::machine_id::type machine_id() const {
2050       const auto& col = table()->machine_id();
2051       return col.GetAtIdx(
2052         iterator_.StorageIndexForColumn(col.index_in_table()));
2053     }
classification()2054     ColumnType::classification::type classification() const {
2055       const auto& col = table()->classification();
2056       return col.GetAtIdx(
2057         iterator_.StorageIndexForColumn(col.index_in_table()));
2058     }
dimension_arg_set_id()2059     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
2060       const auto& col = table()->dimension_arg_set_id();
2061       return col.GetAtIdx(
2062         iterator_.StorageIndexForColumn(col.index_in_table()));
2063     }
event_type()2064     ColumnType::event_type::type event_type() const {
2065       const auto& col = table()->event_type();
2066       return col.GetAtIdx(
2067         iterator_.StorageIndexForColumn(col.index_in_table()));
2068     }
counter_unit()2069     ColumnType::counter_unit::type counter_unit() const {
2070       const auto& col = table()->counter_unit();
2071       return col.GetAtIdx(
2072         iterator_.StorageIndexForColumn(col.index_in_table()));
2073     }
upid()2074     ColumnType::upid::type upid() const {
2075       const auto& col = table()->upid();
2076       return col.GetAtIdx(
2077         iterator_.StorageIndexForColumn(col.index_in_table()));
2078     }
2079 
2080    protected:
ConstIterator(const ProcessTrackTable * table,Table::Iterator iterator)2081     explicit ConstIterator(const ProcessTrackTable* table,
2082                            Table::Iterator iterator)
2083         : AbstractConstIterator(table, std::move(iterator)) {}
2084 
CurrentRowNumber()2085     uint32_t CurrentRowNumber() const {
2086       return iterator_.StorageIndexForLastOverlay();
2087     }
2088 
2089    private:
2090     friend class ProcessTrackTable;
2091     friend class macros_internal::AbstractConstIterator<
2092       ConstIterator, ProcessTrackTable, RowNumber, ConstRowReference>;
2093   };
2094   class Iterator : public ConstIterator {
2095     public:
row_reference()2096      RowReference row_reference() const {
2097        return {const_cast<ProcessTrackTable*>(table()), CurrentRowNumber()};
2098      }
2099 
2100     private:
2101      friend class ProcessTrackTable;
2102 
Iterator(ProcessTrackTable * table,Table::Iterator iterator)2103      explicit Iterator(ProcessTrackTable* table, Table::Iterator iterator)
2104         : ConstIterator(table, std::move(iterator)) {}
2105   };
2106 
2107   struct IdAndRow {
2108     Id id;
2109     uint32_t row;
2110     RowReference row_reference;
2111     RowNumber row_number;
2112   };
2113 
GetColumns(ProcessTrackTable * self,const macros_internal::MacroTable * parent)2114   static std::vector<ColumnLegacy> GetColumns(
2115       ProcessTrackTable* self,
2116       const macros_internal::MacroTable* parent) {
2117     std::vector<ColumnLegacy> columns =
2118         CopyColumnsFromParentOrAddRootColumns(self, parent);
2119     uint32_t olay_idx = OverlayCount(parent);
2120     AddColumnToVector(columns, "upid", &self->upid_, ColumnFlag::upid,
2121                       static_cast<uint32_t>(columns.size()), olay_idx);
2122     return columns;
2123   }
2124 
ProcessTrackTable(StringPool * pool,TrackTable * parent)2125   PERFETTO_NO_INLINE explicit ProcessTrackTable(StringPool* pool, TrackTable* parent)
2126       : macros_internal::MacroTable(
2127           pool,
2128           GetColumns(this, parent),
2129           parent),
2130         parent_(parent), const_parent_(parent), upid_(ColumnStorage<ColumnType::upid::stored_type>::Create<false>())
2131 ,
2132         upid_storage_layer_(
2133         new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
2134           &upid_.vector(),
2135           ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
2136           false))
2137          {
2138     static_assert(
2139         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
2140           ColumnFlag::upid),
2141         "Column type and flag combination is not valid");
2142     OnConstructionCompletedRegularConstructor(
2143       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],upid_storage_layer_},
2144       {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}});
2145   }
2146   ~ProcessTrackTable() override;
2147 
Name()2148   static const char* Name() { return "process_track"; }
2149 
ComputeStaticSchema()2150   static Table::Schema ComputeStaticSchema() {
2151     Table::Schema schema;
2152     schema.columns.emplace_back(Table::Schema::Column{
2153         "id", SqlValue::Type::kLong, true, true, false, false});
2154     schema.columns.emplace_back(Table::Schema::Column{
2155         "type", SqlValue::Type::kString, false, false, false, false});
2156     schema.columns.emplace_back(Table::Schema::Column{
2157         "name", ColumnType::name::SqlValueType(), false,
2158         false,
2159         false,
2160         false});
2161     schema.columns.emplace_back(Table::Schema::Column{
2162         "parent_id", ColumnType::parent_id::SqlValueType(), false,
2163         false,
2164         false,
2165         false});
2166     schema.columns.emplace_back(Table::Schema::Column{
2167         "source_arg_set_id", ColumnType::source_arg_set_id::SqlValueType(), false,
2168         false,
2169         false,
2170         false});
2171     schema.columns.emplace_back(Table::Schema::Column{
2172         "machine_id", ColumnType::machine_id::SqlValueType(), false,
2173         false,
2174         false,
2175         false});
2176     schema.columns.emplace_back(Table::Schema::Column{
2177         "classification", ColumnType::classification::SqlValueType(), false,
2178         false,
2179         false,
2180         false});
2181     schema.columns.emplace_back(Table::Schema::Column{
2182         "dimension_arg_set_id", ColumnType::dimension_arg_set_id::SqlValueType(), false,
2183         false,
2184         false,
2185         false});
2186     schema.columns.emplace_back(Table::Schema::Column{
2187         "event_type", ColumnType::event_type::SqlValueType(), false,
2188         false,
2189         false,
2190         false});
2191     schema.columns.emplace_back(Table::Schema::Column{
2192         "counter_unit", ColumnType::counter_unit::SqlValueType(), false,
2193         false,
2194         false,
2195         false});
2196     schema.columns.emplace_back(Table::Schema::Column{
2197         "upid", ColumnType::upid::SqlValueType(), false,
2198         false,
2199         false,
2200         false});
2201     return schema;
2202   }
2203 
IterateRows()2204   ConstIterator IterateRows() const {
2205     return ConstIterator(this, Table::IterateRows());
2206   }
2207 
IterateRows()2208   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
2209 
FilterToIterator(const Query & q)2210   ConstIterator FilterToIterator(const Query& q) const {
2211     return ConstIterator(this, QueryToIterator(q));
2212   }
2213 
FilterToIterator(const Query & q)2214   Iterator FilterToIterator(const Query& q) {
2215     return Iterator(this, QueryToIterator(q));
2216   }
2217 
ShrinkToFit()2218   void ShrinkToFit() {
2219     upid_.ShrinkToFit();
2220   }
2221 
2222   ConstRowReference operator[](uint32_t r) const {
2223     return ConstRowReference(this, r);
2224   }
2225   RowReference operator[](uint32_t r) { return RowReference(this, r); }
2226   ConstRowReference operator[](RowNumber r) const {
2227     return ConstRowReference(this, r.row_number());
2228   }
2229   RowReference operator[](RowNumber r) {
2230     return RowReference(this, r.row_number());
2231   }
2232 
FindById(Id find_id)2233   std::optional<ConstRowReference> FindById(Id find_id) const {
2234     std::optional<uint32_t> row = id().IndexOf(find_id);
2235     return row ? std::make_optional(ConstRowReference(this, *row))
2236                : std::nullopt;
2237   }
2238 
FindById(Id find_id)2239   std::optional<RowReference> FindById(Id find_id) {
2240     std::optional<uint32_t> row = id().IndexOf(find_id);
2241     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
2242   }
2243 
Insert(const Row & row)2244   IdAndRow Insert(const Row& row) {
2245     uint32_t row_number = row_count();
2246     Id id = Id{parent_->Insert(row).id};
2247     UpdateOverlaysAfterParentInsert();
2248     mutable_upid()->Append(row.upid);
2249     UpdateSelfOverlayAfterInsert();
2250     return IdAndRow{id, row_number, RowReference(this, row_number),
2251                      RowNumber(row_number)};
2252   }
2253 
ExtendParent(const TrackTable & parent,ColumnStorage<ColumnType::upid::stored_type> upid)2254   static std::unique_ptr<ProcessTrackTable> ExtendParent(
2255       const TrackTable& parent,
2256       ColumnStorage<ColumnType::upid::stored_type> upid) {
2257     return std::unique_ptr<ProcessTrackTable>(new ProcessTrackTable(
2258         parent.string_pool(), parent, RowMap(0, parent.row_count()),
2259         std::move(upid)));
2260   }
2261 
SelectAndExtendParent(const TrackTable & parent,std::vector<TrackTable::RowNumber> parent_overlay,ColumnStorage<ColumnType::upid::stored_type> upid)2262   static std::unique_ptr<ProcessTrackTable> SelectAndExtendParent(
2263       const TrackTable& parent,
2264       std::vector<TrackTable::RowNumber> parent_overlay,
2265       ColumnStorage<ColumnType::upid::stored_type> upid) {
2266     std::vector<uint32_t> prs_untyped(parent_overlay.size());
2267     for (uint32_t i = 0; i < parent_overlay.size(); ++i) {
2268       prs_untyped[i] = parent_overlay[i].row_number();
2269     }
2270     return std::unique_ptr<ProcessTrackTable>(new ProcessTrackTable(
2271         parent.string_pool(), parent, RowMap(std::move(prs_untyped)),
2272         std::move(upid)));
2273   }
2274 
id()2275   const IdColumn<ProcessTrackTable::Id>& id() const {
2276     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
2277   }
type()2278   const TypedColumn<StringPool::Id>& type() const {
2279     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
2280   }
name()2281   const TypedColumn<StringPool::Id>& name() const {
2282     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
2283   }
parent_id()2284   const TypedColumn<std::optional<ProcessTrackTable::Id>>& parent_id() const {
2285     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
2286   }
source_arg_set_id()2287   const TypedColumn<std::optional<uint32_t>>& source_arg_set_id() const {
2288     return static_cast<const ColumnType::source_arg_set_id&>(columns()[ColumnIndex::source_arg_set_id]);
2289   }
machine_id()2290   const TypedColumn<std::optional<MachineTable::Id>>& machine_id() const {
2291     return static_cast<const ColumnType::machine_id&>(columns()[ColumnIndex::machine_id]);
2292   }
classification()2293   const TypedColumn<StringPool::Id>& classification() const {
2294     return static_cast<const ColumnType::classification&>(columns()[ColumnIndex::classification]);
2295   }
dimension_arg_set_id()2296   const TypedColumn<std::optional<uint32_t>>& dimension_arg_set_id() const {
2297     return static_cast<const ColumnType::dimension_arg_set_id&>(columns()[ColumnIndex::dimension_arg_set_id]);
2298   }
event_type()2299   const TypedColumn<StringPool::Id>& event_type() const {
2300     return static_cast<const ColumnType::event_type&>(columns()[ColumnIndex::event_type]);
2301   }
counter_unit()2302   const TypedColumn<std::optional<StringPool::Id>>& counter_unit() const {
2303     return static_cast<const ColumnType::counter_unit&>(columns()[ColumnIndex::counter_unit]);
2304   }
upid()2305   const TypedColumn<uint32_t>& upid() const {
2306     return static_cast<const ColumnType::upid&>(columns()[ColumnIndex::upid]);
2307   }
2308 
mutable_name()2309   TypedColumn<StringPool::Id>* mutable_name() {
2310     return static_cast<ColumnType::name*>(
2311         GetColumn(ColumnIndex::name));
2312   }
mutable_parent_id()2313   TypedColumn<std::optional<ProcessTrackTable::Id>>* mutable_parent_id() {
2314     return static_cast<ColumnType::parent_id*>(
2315         GetColumn(ColumnIndex::parent_id));
2316   }
mutable_source_arg_set_id()2317   TypedColumn<std::optional<uint32_t>>* mutable_source_arg_set_id() {
2318     return static_cast<ColumnType::source_arg_set_id*>(
2319         GetColumn(ColumnIndex::source_arg_set_id));
2320   }
mutable_machine_id()2321   TypedColumn<std::optional<MachineTable::Id>>* mutable_machine_id() {
2322     return static_cast<ColumnType::machine_id*>(
2323         GetColumn(ColumnIndex::machine_id));
2324   }
mutable_classification()2325   TypedColumn<StringPool::Id>* mutable_classification() {
2326     return static_cast<ColumnType::classification*>(
2327         GetColumn(ColumnIndex::classification));
2328   }
mutable_dimension_arg_set_id()2329   TypedColumn<std::optional<uint32_t>>* mutable_dimension_arg_set_id() {
2330     return static_cast<ColumnType::dimension_arg_set_id*>(
2331         GetColumn(ColumnIndex::dimension_arg_set_id));
2332   }
mutable_event_type()2333   TypedColumn<StringPool::Id>* mutable_event_type() {
2334     return static_cast<ColumnType::event_type*>(
2335         GetColumn(ColumnIndex::event_type));
2336   }
mutable_counter_unit()2337   TypedColumn<std::optional<StringPool::Id>>* mutable_counter_unit() {
2338     return static_cast<ColumnType::counter_unit*>(
2339         GetColumn(ColumnIndex::counter_unit));
2340   }
mutable_upid()2341   TypedColumn<uint32_t>* mutable_upid() {
2342     return static_cast<ColumnType::upid*>(
2343         GetColumn(ColumnIndex::upid));
2344   }
2345 
2346  private:
ProcessTrackTable(StringPool * pool,const TrackTable & parent,const RowMap & parent_overlay,ColumnStorage<ColumnType::upid::stored_type> upid)2347   ProcessTrackTable(StringPool* pool,
2348             const TrackTable& parent,
2349             const RowMap& parent_overlay,
2350             ColumnStorage<ColumnType::upid::stored_type> upid)
2351       : macros_internal::MacroTable(
2352           pool,
2353           GetColumns(this, &parent),
2354           parent,
2355           parent_overlay),
2356           const_parent_(&parent)
2357 ,
2358         upid_storage_layer_(
2359         new column::NumericStorage<ColumnType::upid::non_optional_stored_type>(
2360           &upid_.vector(),
2361           ColumnTypeHelper<ColumnType::upid::stored_type>::ToColumnType(),
2362           false))
2363          {
2364     static_assert(
2365         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::upid::stored_type>(
2366           ColumnFlag::upid),
2367         "Column type and flag combination is not valid");
2368     PERFETTO_DCHECK(upid.size() == parent_overlay.size());
2369     upid_ = std::move(upid);
2370 
2371     std::vector<RefPtr<column::OverlayLayer>> overlay_layers(OverlayCount(&parent) + 1);
2372     for (uint32_t i = 0; i < overlay_layers.size(); ++i) {
2373       if (overlays()[i].row_map().IsIndexVector()) {
2374         overlay_layers[i].reset(new column::ArrangementOverlay(
2375             overlays()[i].row_map().GetIfIndexVector(),
2376             column::DataLayerChain::Indices::State::kNonmonotonic));
2377       } else if (overlays()[i].row_map().IsBitVector()) {
2378         overlay_layers[i].reset(new column::SelectorOverlay(
2379             overlays()[i].row_map().GetIfBitVector()));
2380       } else if (overlays()[i].row_map().IsRange()) {
2381         overlay_layers[i].reset(new column::RangeOverlay(
2382             overlays()[i].row_map().GetIfIRange()));
2383       }
2384     }
2385 
2386     OnConstructionCompleted(
2387       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],upid_storage_layer_}, {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}}, std::move(overlay_layers));
2388   }
2389   TrackTable* parent_ = nullptr;
2390   const TrackTable* const_parent_ = nullptr;
2391   ColumnStorage<ColumnType::upid::stored_type> upid_;
2392 
2393   RefPtr<column::StorageLayer> upid_storage_layer_;
2394 
2395 
2396 };
2397 
2398 
2399 class ThreadTrackTable : public macros_internal::MacroTable {
2400  public:
2401   static constexpr uint32_t kColumnCount = 11;
2402 
2403   using Id = TrackTable::Id;
2404 
2405   struct ColumnIndex {
2406     static constexpr uint32_t id = 0;
2407     static constexpr uint32_t type = 1;
2408     static constexpr uint32_t name = 2;
2409     static constexpr uint32_t parent_id = 3;
2410     static constexpr uint32_t source_arg_set_id = 4;
2411     static constexpr uint32_t machine_id = 5;
2412     static constexpr uint32_t classification = 6;
2413     static constexpr uint32_t dimension_arg_set_id = 7;
2414     static constexpr uint32_t event_type = 8;
2415     static constexpr uint32_t counter_unit = 9;
2416     static constexpr uint32_t utid = 10;
2417   };
2418   struct ColumnType {
2419     using id = IdColumn<ThreadTrackTable::Id>;
2420     using type = TypedColumn<StringPool::Id>;
2421     using name = TypedColumn<StringPool::Id>;
2422     using parent_id = TypedColumn<std::optional<ThreadTrackTable::Id>>;
2423     using source_arg_set_id = TypedColumn<std::optional<uint32_t>>;
2424     using machine_id = TypedColumn<std::optional<MachineTable::Id>>;
2425     using classification = TypedColumn<StringPool::Id>;
2426     using dimension_arg_set_id = TypedColumn<std::optional<uint32_t>>;
2427     using event_type = TypedColumn<StringPool::Id>;
2428     using counter_unit = TypedColumn<std::optional<StringPool::Id>>;
2429     using utid = TypedColumn<uint32_t>;
2430   };
2431   struct Row : public TrackTable::Row {
2432     Row(StringPool::Id in_name = {},
2433         std::optional<ThreadTrackTable::Id> in_parent_id = {},
2434         std::optional<uint32_t> in_source_arg_set_id = {},
2435         std::optional<MachineTable::Id> in_machine_id = {},
2436         StringPool::Id in_classification = {},
2437         std::optional<uint32_t> in_dimension_arg_set_id = {},
2438         StringPool::Id in_event_type = {},
2439         std::optional<StringPool::Id> in_counter_unit = {},
2440         uint32_t in_utid = {},
2441         std::nullptr_t = nullptr)
RowRow2442         : TrackTable::Row(in_name, in_parent_id, in_source_arg_set_id, in_machine_id, in_classification, in_dimension_arg_set_id, in_event_type, in_counter_unit),
2443           utid(in_utid) {
2444       type_ = "thread_track";
2445     }
2446     uint32_t utid;
2447 
2448     bool operator==(const ThreadTrackTable::Row& other) const {
2449       return type() == other.type() && ColumnType::name::Equals(name, other.name) &&
2450        ColumnType::parent_id::Equals(parent_id, other.parent_id) &&
2451        ColumnType::source_arg_set_id::Equals(source_arg_set_id, other.source_arg_set_id) &&
2452        ColumnType::machine_id::Equals(machine_id, other.machine_id) &&
2453        ColumnType::classification::Equals(classification, other.classification) &&
2454        ColumnType::dimension_arg_set_id::Equals(dimension_arg_set_id, other.dimension_arg_set_id) &&
2455        ColumnType::event_type::Equals(event_type, other.event_type) &&
2456        ColumnType::counter_unit::Equals(counter_unit, other.counter_unit) &&
2457        ColumnType::utid::Equals(utid, other.utid);
2458     }
2459   };
2460   struct ColumnFlag {
2461     static constexpr uint32_t utid = ColumnType::utid::default_flags();
2462   };
2463 
2464   class RowNumber;
2465   class ConstRowReference;
2466   class RowReference;
2467 
2468   class RowNumber : public macros_internal::AbstractRowNumber<
2469       ThreadTrackTable, ConstRowReference, RowReference> {
2470    public:
RowNumber(uint32_t row_number)2471     explicit RowNumber(uint32_t row_number)
2472         : AbstractRowNumber(row_number) {}
2473   };
2474   static_assert(std::is_trivially_destructible_v<RowNumber>,
2475                 "Inheritance used without trivial destruction");
2476 
2477   class ConstRowReference : public macros_internal::AbstractConstRowReference<
2478     ThreadTrackTable, RowNumber> {
2479    public:
ConstRowReference(const ThreadTrackTable * table,uint32_t row_number)2480     ConstRowReference(const ThreadTrackTable* table, uint32_t row_number)
2481         : AbstractConstRowReference(table, row_number) {}
2482 
id()2483     ColumnType::id::type id() const {
2484       return table()->id()[row_number_];
2485     }
type()2486     ColumnType::type::type type() const {
2487       return table()->type()[row_number_];
2488     }
name()2489     ColumnType::name::type name() const {
2490       return table()->name()[row_number_];
2491     }
parent_id()2492     ColumnType::parent_id::type parent_id() const {
2493       return table()->parent_id()[row_number_];
2494     }
source_arg_set_id()2495     ColumnType::source_arg_set_id::type source_arg_set_id() const {
2496       return table()->source_arg_set_id()[row_number_];
2497     }
machine_id()2498     ColumnType::machine_id::type machine_id() const {
2499       return table()->machine_id()[row_number_];
2500     }
classification()2501     ColumnType::classification::type classification() const {
2502       return table()->classification()[row_number_];
2503     }
dimension_arg_set_id()2504     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
2505       return table()->dimension_arg_set_id()[row_number_];
2506     }
event_type()2507     ColumnType::event_type::type event_type() const {
2508       return table()->event_type()[row_number_];
2509     }
counter_unit()2510     ColumnType::counter_unit::type counter_unit() const {
2511       return table()->counter_unit()[row_number_];
2512     }
utid()2513     ColumnType::utid::type utid() const {
2514       return table()->utid()[row_number_];
2515     }
2516   };
2517   static_assert(std::is_trivially_destructible_v<ConstRowReference>,
2518                 "Inheritance used without trivial destruction");
2519   class RowReference : public ConstRowReference {
2520    public:
RowReference(const ThreadTrackTable * table,uint32_t row_number)2521     RowReference(const ThreadTrackTable* table, uint32_t row_number)
2522         : ConstRowReference(table, row_number) {}
2523 
set_name(ColumnType::name::non_optional_type v)2524     void set_name(
2525         ColumnType::name::non_optional_type v) {
2526       return mutable_table()->mutable_name()->Set(row_number_, v);
2527     }
set_parent_id(ColumnType::parent_id::non_optional_type v)2528     void set_parent_id(
2529         ColumnType::parent_id::non_optional_type v) {
2530       return mutable_table()->mutable_parent_id()->Set(row_number_, v);
2531     }
set_source_arg_set_id(ColumnType::source_arg_set_id::non_optional_type v)2532     void set_source_arg_set_id(
2533         ColumnType::source_arg_set_id::non_optional_type v) {
2534       return mutable_table()->mutable_source_arg_set_id()->Set(row_number_, v);
2535     }
set_machine_id(ColumnType::machine_id::non_optional_type v)2536     void set_machine_id(
2537         ColumnType::machine_id::non_optional_type v) {
2538       return mutable_table()->mutable_machine_id()->Set(row_number_, v);
2539     }
set_classification(ColumnType::classification::non_optional_type v)2540     void set_classification(
2541         ColumnType::classification::non_optional_type v) {
2542       return mutable_table()->mutable_classification()->Set(row_number_, v);
2543     }
set_dimension_arg_set_id(ColumnType::dimension_arg_set_id::non_optional_type v)2544     void set_dimension_arg_set_id(
2545         ColumnType::dimension_arg_set_id::non_optional_type v) {
2546       return mutable_table()->mutable_dimension_arg_set_id()->Set(row_number_, v);
2547     }
set_event_type(ColumnType::event_type::non_optional_type v)2548     void set_event_type(
2549         ColumnType::event_type::non_optional_type v) {
2550       return mutable_table()->mutable_event_type()->Set(row_number_, v);
2551     }
set_counter_unit(ColumnType::counter_unit::non_optional_type v)2552     void set_counter_unit(
2553         ColumnType::counter_unit::non_optional_type v) {
2554       return mutable_table()->mutable_counter_unit()->Set(row_number_, v);
2555     }
set_utid(ColumnType::utid::non_optional_type v)2556     void set_utid(
2557         ColumnType::utid::non_optional_type v) {
2558       return mutable_table()->mutable_utid()->Set(row_number_, v);
2559     }
2560 
2561    private:
mutable_table()2562     ThreadTrackTable* mutable_table() const {
2563       return const_cast<ThreadTrackTable*>(table());
2564     }
2565   };
2566   static_assert(std::is_trivially_destructible_v<RowReference>,
2567                 "Inheritance used without trivial destruction");
2568 
2569   class ConstIterator;
2570   class ConstIterator : public macros_internal::AbstractConstIterator<
2571     ConstIterator, ThreadTrackTable, RowNumber, ConstRowReference> {
2572    public:
id()2573     ColumnType::id::type id() const {
2574       const auto& col = table()->id();
2575       return col.GetAtIdx(
2576         iterator_.StorageIndexForColumn(col.index_in_table()));
2577     }
type()2578     ColumnType::type::type type() const {
2579       const auto& col = table()->type();
2580       return col.GetAtIdx(
2581         iterator_.StorageIndexForColumn(col.index_in_table()));
2582     }
name()2583     ColumnType::name::type name() const {
2584       const auto& col = table()->name();
2585       return col.GetAtIdx(
2586         iterator_.StorageIndexForColumn(col.index_in_table()));
2587     }
parent_id()2588     ColumnType::parent_id::type parent_id() const {
2589       const auto& col = table()->parent_id();
2590       return col.GetAtIdx(
2591         iterator_.StorageIndexForColumn(col.index_in_table()));
2592     }
source_arg_set_id()2593     ColumnType::source_arg_set_id::type source_arg_set_id() const {
2594       const auto& col = table()->source_arg_set_id();
2595       return col.GetAtIdx(
2596         iterator_.StorageIndexForColumn(col.index_in_table()));
2597     }
machine_id()2598     ColumnType::machine_id::type machine_id() const {
2599       const auto& col = table()->machine_id();
2600       return col.GetAtIdx(
2601         iterator_.StorageIndexForColumn(col.index_in_table()));
2602     }
classification()2603     ColumnType::classification::type classification() const {
2604       const auto& col = table()->classification();
2605       return col.GetAtIdx(
2606         iterator_.StorageIndexForColumn(col.index_in_table()));
2607     }
dimension_arg_set_id()2608     ColumnType::dimension_arg_set_id::type dimension_arg_set_id() const {
2609       const auto& col = table()->dimension_arg_set_id();
2610       return col.GetAtIdx(
2611         iterator_.StorageIndexForColumn(col.index_in_table()));
2612     }
event_type()2613     ColumnType::event_type::type event_type() const {
2614       const auto& col = table()->event_type();
2615       return col.GetAtIdx(
2616         iterator_.StorageIndexForColumn(col.index_in_table()));
2617     }
counter_unit()2618     ColumnType::counter_unit::type counter_unit() const {
2619       const auto& col = table()->counter_unit();
2620       return col.GetAtIdx(
2621         iterator_.StorageIndexForColumn(col.index_in_table()));
2622     }
utid()2623     ColumnType::utid::type utid() const {
2624       const auto& col = table()->utid();
2625       return col.GetAtIdx(
2626         iterator_.StorageIndexForColumn(col.index_in_table()));
2627     }
2628 
2629    protected:
ConstIterator(const ThreadTrackTable * table,Table::Iterator iterator)2630     explicit ConstIterator(const ThreadTrackTable* table,
2631                            Table::Iterator iterator)
2632         : AbstractConstIterator(table, std::move(iterator)) {}
2633 
CurrentRowNumber()2634     uint32_t CurrentRowNumber() const {
2635       return iterator_.StorageIndexForLastOverlay();
2636     }
2637 
2638    private:
2639     friend class ThreadTrackTable;
2640     friend class macros_internal::AbstractConstIterator<
2641       ConstIterator, ThreadTrackTable, RowNumber, ConstRowReference>;
2642   };
2643   class Iterator : public ConstIterator {
2644     public:
row_reference()2645      RowReference row_reference() const {
2646        return {const_cast<ThreadTrackTable*>(table()), CurrentRowNumber()};
2647      }
2648 
2649     private:
2650      friend class ThreadTrackTable;
2651 
Iterator(ThreadTrackTable * table,Table::Iterator iterator)2652      explicit Iterator(ThreadTrackTable* table, Table::Iterator iterator)
2653         : ConstIterator(table, std::move(iterator)) {}
2654   };
2655 
2656   struct IdAndRow {
2657     Id id;
2658     uint32_t row;
2659     RowReference row_reference;
2660     RowNumber row_number;
2661   };
2662 
GetColumns(ThreadTrackTable * self,const macros_internal::MacroTable * parent)2663   static std::vector<ColumnLegacy> GetColumns(
2664       ThreadTrackTable* self,
2665       const macros_internal::MacroTable* parent) {
2666     std::vector<ColumnLegacy> columns =
2667         CopyColumnsFromParentOrAddRootColumns(self, parent);
2668     uint32_t olay_idx = OverlayCount(parent);
2669     AddColumnToVector(columns, "utid", &self->utid_, ColumnFlag::utid,
2670                       static_cast<uint32_t>(columns.size()), olay_idx);
2671     return columns;
2672   }
2673 
ThreadTrackTable(StringPool * pool,TrackTable * parent)2674   PERFETTO_NO_INLINE explicit ThreadTrackTable(StringPool* pool, TrackTable* parent)
2675       : macros_internal::MacroTable(
2676           pool,
2677           GetColumns(this, parent),
2678           parent),
2679         parent_(parent), const_parent_(parent), utid_(ColumnStorage<ColumnType::utid::stored_type>::Create<false>())
2680 ,
2681         utid_storage_layer_(
2682         new column::NumericStorage<ColumnType::utid::non_optional_stored_type>(
2683           &utid_.vector(),
2684           ColumnTypeHelper<ColumnType::utid::stored_type>::ToColumnType(),
2685           false))
2686          {
2687     static_assert(
2688         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::utid::stored_type>(
2689           ColumnFlag::utid),
2690         "Column type and flag combination is not valid");
2691     OnConstructionCompletedRegularConstructor(
2692       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],utid_storage_layer_},
2693       {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}});
2694   }
2695   ~ThreadTrackTable() override;
2696 
Name()2697   static const char* Name() { return "thread_track"; }
2698 
ComputeStaticSchema()2699   static Table::Schema ComputeStaticSchema() {
2700     Table::Schema schema;
2701     schema.columns.emplace_back(Table::Schema::Column{
2702         "id", SqlValue::Type::kLong, true, true, false, false});
2703     schema.columns.emplace_back(Table::Schema::Column{
2704         "type", SqlValue::Type::kString, false, false, false, false});
2705     schema.columns.emplace_back(Table::Schema::Column{
2706         "name", ColumnType::name::SqlValueType(), false,
2707         false,
2708         false,
2709         false});
2710     schema.columns.emplace_back(Table::Schema::Column{
2711         "parent_id", ColumnType::parent_id::SqlValueType(), false,
2712         false,
2713         false,
2714         false});
2715     schema.columns.emplace_back(Table::Schema::Column{
2716         "source_arg_set_id", ColumnType::source_arg_set_id::SqlValueType(), false,
2717         false,
2718         false,
2719         false});
2720     schema.columns.emplace_back(Table::Schema::Column{
2721         "machine_id", ColumnType::machine_id::SqlValueType(), false,
2722         false,
2723         false,
2724         false});
2725     schema.columns.emplace_back(Table::Schema::Column{
2726         "classification", ColumnType::classification::SqlValueType(), false,
2727         false,
2728         false,
2729         false});
2730     schema.columns.emplace_back(Table::Schema::Column{
2731         "dimension_arg_set_id", ColumnType::dimension_arg_set_id::SqlValueType(), false,
2732         false,
2733         false,
2734         false});
2735     schema.columns.emplace_back(Table::Schema::Column{
2736         "event_type", ColumnType::event_type::SqlValueType(), false,
2737         false,
2738         false,
2739         false});
2740     schema.columns.emplace_back(Table::Schema::Column{
2741         "counter_unit", ColumnType::counter_unit::SqlValueType(), false,
2742         false,
2743         false,
2744         false});
2745     schema.columns.emplace_back(Table::Schema::Column{
2746         "utid", ColumnType::utid::SqlValueType(), false,
2747         false,
2748         false,
2749         false});
2750     return schema;
2751   }
2752 
IterateRows()2753   ConstIterator IterateRows() const {
2754     return ConstIterator(this, Table::IterateRows());
2755   }
2756 
IterateRows()2757   Iterator IterateRows() { return Iterator(this, Table::IterateRows()); }
2758 
FilterToIterator(const Query & q)2759   ConstIterator FilterToIterator(const Query& q) const {
2760     return ConstIterator(this, QueryToIterator(q));
2761   }
2762 
FilterToIterator(const Query & q)2763   Iterator FilterToIterator(const Query& q) {
2764     return Iterator(this, QueryToIterator(q));
2765   }
2766 
ShrinkToFit()2767   void ShrinkToFit() {
2768     utid_.ShrinkToFit();
2769   }
2770 
2771   ConstRowReference operator[](uint32_t r) const {
2772     return ConstRowReference(this, r);
2773   }
2774   RowReference operator[](uint32_t r) { return RowReference(this, r); }
2775   ConstRowReference operator[](RowNumber r) const {
2776     return ConstRowReference(this, r.row_number());
2777   }
2778   RowReference operator[](RowNumber r) {
2779     return RowReference(this, r.row_number());
2780   }
2781 
FindById(Id find_id)2782   std::optional<ConstRowReference> FindById(Id find_id) const {
2783     std::optional<uint32_t> row = id().IndexOf(find_id);
2784     return row ? std::make_optional(ConstRowReference(this, *row))
2785                : std::nullopt;
2786   }
2787 
FindById(Id find_id)2788   std::optional<RowReference> FindById(Id find_id) {
2789     std::optional<uint32_t> row = id().IndexOf(find_id);
2790     return row ? std::make_optional(RowReference(this, *row)) : std::nullopt;
2791   }
2792 
Insert(const Row & row)2793   IdAndRow Insert(const Row& row) {
2794     uint32_t row_number = row_count();
2795     Id id = Id{parent_->Insert(row).id};
2796     UpdateOverlaysAfterParentInsert();
2797     mutable_utid()->Append(row.utid);
2798     UpdateSelfOverlayAfterInsert();
2799     return IdAndRow{id, row_number, RowReference(this, row_number),
2800                      RowNumber(row_number)};
2801   }
2802 
ExtendParent(const TrackTable & parent,ColumnStorage<ColumnType::utid::stored_type> utid)2803   static std::unique_ptr<ThreadTrackTable> ExtendParent(
2804       const TrackTable& parent,
2805       ColumnStorage<ColumnType::utid::stored_type> utid) {
2806     return std::unique_ptr<ThreadTrackTable>(new ThreadTrackTable(
2807         parent.string_pool(), parent, RowMap(0, parent.row_count()),
2808         std::move(utid)));
2809   }
2810 
SelectAndExtendParent(const TrackTable & parent,std::vector<TrackTable::RowNumber> parent_overlay,ColumnStorage<ColumnType::utid::stored_type> utid)2811   static std::unique_ptr<ThreadTrackTable> SelectAndExtendParent(
2812       const TrackTable& parent,
2813       std::vector<TrackTable::RowNumber> parent_overlay,
2814       ColumnStorage<ColumnType::utid::stored_type> utid) {
2815     std::vector<uint32_t> prs_untyped(parent_overlay.size());
2816     for (uint32_t i = 0; i < parent_overlay.size(); ++i) {
2817       prs_untyped[i] = parent_overlay[i].row_number();
2818     }
2819     return std::unique_ptr<ThreadTrackTable>(new ThreadTrackTable(
2820         parent.string_pool(), parent, RowMap(std::move(prs_untyped)),
2821         std::move(utid)));
2822   }
2823 
id()2824   const IdColumn<ThreadTrackTable::Id>& id() const {
2825     return static_cast<const ColumnType::id&>(columns()[ColumnIndex::id]);
2826   }
type()2827   const TypedColumn<StringPool::Id>& type() const {
2828     return static_cast<const ColumnType::type&>(columns()[ColumnIndex::type]);
2829   }
name()2830   const TypedColumn<StringPool::Id>& name() const {
2831     return static_cast<const ColumnType::name&>(columns()[ColumnIndex::name]);
2832   }
parent_id()2833   const TypedColumn<std::optional<ThreadTrackTable::Id>>& parent_id() const {
2834     return static_cast<const ColumnType::parent_id&>(columns()[ColumnIndex::parent_id]);
2835   }
source_arg_set_id()2836   const TypedColumn<std::optional<uint32_t>>& source_arg_set_id() const {
2837     return static_cast<const ColumnType::source_arg_set_id&>(columns()[ColumnIndex::source_arg_set_id]);
2838   }
machine_id()2839   const TypedColumn<std::optional<MachineTable::Id>>& machine_id() const {
2840     return static_cast<const ColumnType::machine_id&>(columns()[ColumnIndex::machine_id]);
2841   }
classification()2842   const TypedColumn<StringPool::Id>& classification() const {
2843     return static_cast<const ColumnType::classification&>(columns()[ColumnIndex::classification]);
2844   }
dimension_arg_set_id()2845   const TypedColumn<std::optional<uint32_t>>& dimension_arg_set_id() const {
2846     return static_cast<const ColumnType::dimension_arg_set_id&>(columns()[ColumnIndex::dimension_arg_set_id]);
2847   }
event_type()2848   const TypedColumn<StringPool::Id>& event_type() const {
2849     return static_cast<const ColumnType::event_type&>(columns()[ColumnIndex::event_type]);
2850   }
counter_unit()2851   const TypedColumn<std::optional<StringPool::Id>>& counter_unit() const {
2852     return static_cast<const ColumnType::counter_unit&>(columns()[ColumnIndex::counter_unit]);
2853   }
utid()2854   const TypedColumn<uint32_t>& utid() const {
2855     return static_cast<const ColumnType::utid&>(columns()[ColumnIndex::utid]);
2856   }
2857 
mutable_name()2858   TypedColumn<StringPool::Id>* mutable_name() {
2859     return static_cast<ColumnType::name*>(
2860         GetColumn(ColumnIndex::name));
2861   }
mutable_parent_id()2862   TypedColumn<std::optional<ThreadTrackTable::Id>>* mutable_parent_id() {
2863     return static_cast<ColumnType::parent_id*>(
2864         GetColumn(ColumnIndex::parent_id));
2865   }
mutable_source_arg_set_id()2866   TypedColumn<std::optional<uint32_t>>* mutable_source_arg_set_id() {
2867     return static_cast<ColumnType::source_arg_set_id*>(
2868         GetColumn(ColumnIndex::source_arg_set_id));
2869   }
mutable_machine_id()2870   TypedColumn<std::optional<MachineTable::Id>>* mutable_machine_id() {
2871     return static_cast<ColumnType::machine_id*>(
2872         GetColumn(ColumnIndex::machine_id));
2873   }
mutable_classification()2874   TypedColumn<StringPool::Id>* mutable_classification() {
2875     return static_cast<ColumnType::classification*>(
2876         GetColumn(ColumnIndex::classification));
2877   }
mutable_dimension_arg_set_id()2878   TypedColumn<std::optional<uint32_t>>* mutable_dimension_arg_set_id() {
2879     return static_cast<ColumnType::dimension_arg_set_id*>(
2880         GetColumn(ColumnIndex::dimension_arg_set_id));
2881   }
mutable_event_type()2882   TypedColumn<StringPool::Id>* mutable_event_type() {
2883     return static_cast<ColumnType::event_type*>(
2884         GetColumn(ColumnIndex::event_type));
2885   }
mutable_counter_unit()2886   TypedColumn<std::optional<StringPool::Id>>* mutable_counter_unit() {
2887     return static_cast<ColumnType::counter_unit*>(
2888         GetColumn(ColumnIndex::counter_unit));
2889   }
mutable_utid()2890   TypedColumn<uint32_t>* mutable_utid() {
2891     return static_cast<ColumnType::utid*>(
2892         GetColumn(ColumnIndex::utid));
2893   }
2894 
2895  private:
ThreadTrackTable(StringPool * pool,const TrackTable & parent,const RowMap & parent_overlay,ColumnStorage<ColumnType::utid::stored_type> utid)2896   ThreadTrackTable(StringPool* pool,
2897             const TrackTable& parent,
2898             const RowMap& parent_overlay,
2899             ColumnStorage<ColumnType::utid::stored_type> utid)
2900       : macros_internal::MacroTable(
2901           pool,
2902           GetColumns(this, &parent),
2903           parent,
2904           parent_overlay),
2905           const_parent_(&parent)
2906 ,
2907         utid_storage_layer_(
2908         new column::NumericStorage<ColumnType::utid::non_optional_stored_type>(
2909           &utid_.vector(),
2910           ColumnTypeHelper<ColumnType::utid::stored_type>::ToColumnType(),
2911           false))
2912          {
2913     static_assert(
2914         ColumnLegacy::IsFlagsAndTypeValid<ColumnType::utid::stored_type>(
2915           ColumnFlag::utid),
2916         "Column type and flag combination is not valid");
2917     PERFETTO_DCHECK(utid.size() == parent_overlay.size());
2918     utid_ = std::move(utid);
2919 
2920     std::vector<RefPtr<column::OverlayLayer>> overlay_layers(OverlayCount(&parent) + 1);
2921     for (uint32_t i = 0; i < overlay_layers.size(); ++i) {
2922       if (overlays()[i].row_map().IsIndexVector()) {
2923         overlay_layers[i].reset(new column::ArrangementOverlay(
2924             overlays()[i].row_map().GetIfIndexVector(),
2925             column::DataLayerChain::Indices::State::kNonmonotonic));
2926       } else if (overlays()[i].row_map().IsBitVector()) {
2927         overlay_layers[i].reset(new column::SelectorOverlay(
2928             overlays()[i].row_map().GetIfBitVector()));
2929       } else if (overlays()[i].row_map().IsRange()) {
2930         overlay_layers[i].reset(new column::RangeOverlay(
2931             overlays()[i].row_map().GetIfIRange()));
2932       }
2933     }
2934 
2935     OnConstructionCompleted(
2936       {const_parent_->storage_layers()[ColumnIndex::id],const_parent_->storage_layers()[ColumnIndex::type],const_parent_->storage_layers()[ColumnIndex::name],const_parent_->storage_layers()[ColumnIndex::parent_id],const_parent_->storage_layers()[ColumnIndex::source_arg_set_id],const_parent_->storage_layers()[ColumnIndex::machine_id],const_parent_->storage_layers()[ColumnIndex::classification],const_parent_->storage_layers()[ColumnIndex::dimension_arg_set_id],const_parent_->storage_layers()[ColumnIndex::event_type],const_parent_->storage_layers()[ColumnIndex::counter_unit],utid_storage_layer_}, {{},{},{},const_parent_->null_layers()[ColumnIndex::parent_id],const_parent_->null_layers()[ColumnIndex::source_arg_set_id],const_parent_->null_layers()[ColumnIndex::machine_id],{},const_parent_->null_layers()[ColumnIndex::dimension_arg_set_id],{},{},{}}, std::move(overlay_layers));
2937   }
2938   TrackTable* parent_ = nullptr;
2939   const TrackTable* const_parent_ = nullptr;
2940   ColumnStorage<ColumnType::utid::stored_type> utid_;
2941 
2942   RefPtr<column::StorageLayer> utid_storage_layer_;
2943 
2944 
2945 };
2946 
2947 }  // namespace perfetto
2948 
2949 #endif  // SRC_TRACE_PROCESSOR_TABLES_TRACK_TABLES_PY_H_
2950