1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACE_PROCESSOR_TABLES_MACROS_H_ 18 #define SRC_TRACE_PROCESSOR_TABLES_MACROS_H_ 19 20 #include "src/trace_processor/tables/macros_internal.h" 21 22 namespace perfetto { 23 namespace trace_processor { 24 25 // Usage of the below macros 26 // These macros have two different invocation patterns depending on whether you 27 // are defining a root table or a derived table (see below for definitions and 28 // examples). If you're not sure which one you need, you probably want a derived 29 // table. 30 // 31 // Root tables 32 // Root tables act as the ultimate parent of a heirarcy of tables. All rows of 33 // child tables will be some subset of rows in the parent. Real world examples 34 // of root tables include EventTable and TrackTable. 35 // 36 // All root tables implicitly contain an 'id' column which contains the row 37 // index for each row in the table. 38 // 39 // Suppose we want to define EventTable with columns 'ts' and 'arg_set_id'. 40 // 41 // Then we would invoke the macro as follows: 42 // #define PERFETTO_TP_EVENT_TABLE_DEF(NAME, PARENT, C) 43 // NAME(EventTable, "event") 44 // PERFETTO_TP_ROOT_TABLE(PARENT, C) 45 // C(int64_t, ts, Column::kSorted) 46 // C(uint32_t, arg_set_id) 47 // PERFETTO_TP_TABLE(PERFETTO_TP_EVENT_TABLE_DEF); 48 // 49 // Note the call to PERFETTO_TP_ROOT_TABLE; this macro (defined below) should 50 // be called by root tables passing the PARENT and C and allows for correct type 51 // checking of root tables. 52 // 53 // Derived tables 54 // Suppose we want to derive a table called SliceTable which inherits all 55 // columns from EventTable (with EventTable's definition macro being 56 // PERFETTO_TP_EVENT_TABLE_DEF) and columns 'dur' and 'depth'. 57 // 58 // Then, we would invoke the macro as follows: 59 // #define PERFETTO_TP_SLICE_TABLE_DEF(NAME, PARENT, C) 60 // NAME(SliceTable, "slice") 61 // PARENT(PERFETTO_TP_EVENT_TABLE_DEF, C) 62 // C(int64_t, dur) 63 // C(uint8_t, depth) 64 // PERFETTO_TP_TABLE(PERFETTO_TP_SLICE_TABLE_DEF); 65 66 // Macro definition using when defining a new root table. 67 // 68 // This macro should be called by passing PARENT and C in root tables; this 69 // allows for correct type-checking of columns. 70 // 71 // See the top of the file for how this should be used. 72 #define PERFETTO_TP_ROOT_TABLE(PARENT, C) \ 73 PARENT(PERFETTO_TP_ROOT_TABLE_PARENT_DEF, C) 74 75 // The macro used to define storage backed tables. 76 // See the top of the file for how this should be used. 77 // 78 // This macro takes one argument: the full definition of the table; the 79 // definition is a function macro taking three arguments: 80 // 1. NAME, a function macro taking two argument: the name of the new class 81 // being defined and the name of the table when exposed to SQLite. 82 // 2. PARENT, a function macro taking two arguments: a) the definition of 83 // the parent table if this table 84 // is a root table b) C, the third parameter of the macro definition (see 85 // below). For root tables, PARENT and C are passsed to 86 // PERFETTO_TP_ROOT_TABLE instead of PARENT called directly. 87 // 3. C, a function macro taking two or three parameters: 88 // a) the type of a column 89 // b) the name of a column 90 // c) (optional) the flags of the column (see Column::Flag 91 // for details). 92 // This macro should be invoked as many times as there are columns in the 93 // table with the information about them. 94 #define PERFETTO_TP_TABLE(DEF) \ 95 PERFETTO_TP_TABLE_INTERNAL( \ 96 PERFETTO_TP_TABLE_NAME(DEF), PERFETTO_TP_TABLE_CLASS(DEF), \ 97 PERFETTO_TP_TABLE_CLASS(PERFETTO_TP_PARENT_DEF(DEF)), DEF) 98 99 } // namespace trace_processor 100 } // namespace perfetto 101 102 #endif // SRC_TRACE_PROCESSOR_TABLES_MACROS_H_ 103