tp: migrate all table functions to use Python based tables
This CL removes the last usage of macros for actual tables from the
codebase. This allows removing all table macro code in a follow-up CL:
we need to keep around the slice table for C++ views but this too will
be migrated once C++ views themselves have been migrated.
Change-Id: I28a5a834bfaa380fa2ba478fce9fdfba43c92d54
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index d0eb99f..5317914 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -819,10 +819,9 @@
module.cmd = ' '.join([
f'$(location {bp_binary_module_name})',
'--gen-dir=$(genDir)',
+ '--relative-input-dir=external/perfetto',
'--inputs',
'$(in)',
- '--outputs',
- '$(out)',
])
module.out.update(target.outputs)
module.genrule_headers.add(module.name)
diff --git a/tools/gen_bazel b/tools/gen_bazel
index a514fe3..3121aa8 100755
--- a/tools/gen_bazel
+++ b/tools/gen_bazel
@@ -582,6 +582,9 @@
label = BazelLabel(get_bazel_label_name(target.name), 'perfetto_cc_tp_tables')
label.comment = target.name
label.srcs += (gn_utils.label_to_path(x) for x in target.sources)
+ label.deps += sorted(':' + get_bazel_label_name(x.name)
+ for x in target.transitive_deps
+ if x.name not in default_python_targets)
label.outs += target.outputs
return [label]
diff --git a/tools/gen_tp_table_docs.py b/tools/gen_tp_table_docs.py
index 8b8565a..97e183e 100755
--- a/tools/gen_tp_table_docs.py
+++ b/tools/gen_tp_table_docs.py
@@ -59,7 +59,9 @@
raise Exception('Unknown column documentation type '
f'{table.table.class_name}::{col.column.name}')
- parsed_type = table.parse_type(col.column.type)
+ parsed_type = util.parse_type_with_cols(table.table,
+ [c.column for c in table.columns],
+ col.column.type)
docs_type = parsed_type.cpp_type
if docs_type == 'StringPool::Id':
docs_type = 'string'
@@ -88,11 +90,20 @@
parser = argparse.ArgumentParser()
parser.add_argument('--out', required=True)
parser.add_argument('inputs', nargs='*')
+ parser.add_argument('--relative-input-dir')
args = parser.parse_args()
- tables = util.parse_tables_from_files(args.inputs)
+ def get_relin_path(in_path: str):
+ if not args.relative_input_dir:
+ return in_path
+ return os.path.relpath(in_path, args.relative_input_dir)
+
+ modules = [
+ os.path.splitext(get_relin_path(i).replace('/', '.'))[0]
+ for i in args.inputs
+ ]
table_docs = []
- for parsed in tables:
+ for parsed in util.parse_tables_from_modules(modules):
table = parsed.table
doc = table.tabledoc
assert doc
diff --git a/tools/gen_tp_table_headers.py b/tools/gen_tp_table_headers.py
index 1ce0963..d06c637 100755
--- a/tools/gen_tp_table_headers.py
+++ b/tools/gen_tp_table_headers.py
@@ -28,63 +28,71 @@
#pylint: disable=wrong-import-position
from python.generators.trace_processor_table.serialize import serialize_header
+from python.generators.trace_processor_table.util import find_table_deps
from python.generators.trace_processor_table.util import ParsedTable
-from python.generators.trace_processor_table.util import parse_tables_from_files
+from python.generators.trace_processor_table.util import parse_tables_from_modules
#pylint: enable=wrong-import-position
+# Suffix which replaces the .py extension for all input modules.
+OUT_HEADER_SUFFIX = '_py.h'
+
@dataclass
class Header:
"""Represents a Python module which will be converted to a header."""
- out_path: str
- relout_path: str
tables: List[ParsedTable]
def main():
"""Main function."""
parser = argparse.ArgumentParser()
- parser.add_argument('--gen-dir', required=True)
parser.add_argument('--inputs', required=True, nargs='*')
- parser.add_argument('--outputs', required=True, nargs='*')
+ parser.add_argument('--gen-dir', required=True)
parser.add_argument('--header-prefix')
+ parser.add_argument('--relative-input-dir')
args = parser.parse_args()
- if len(args.inputs) != len(args.outputs):
- raise Exception('Number of inputs must match number of outputs')
-
header_prefix = args.header_prefix if args.header_prefix else ''
- in_to_out = dict(zip(args.inputs, args.outputs))
+
+ def get_relin_path(in_path: str):
+ if not args.relative_input_dir:
+ return in_path
+ return os.path.relpath(in_path, args.relative_input_dir)
+
+ def get_relout_path(in_path: str):
+ path = os.path.splitext(in_path)[0]
+ return os.path.join(header_prefix, path + OUT_HEADER_SUFFIX)
+
+ def get_out_path(in_path: str):
+ return os.path.join(args.gen_dir, get_relout_path(in_path))
+
+ modules = [
+ os.path.splitext(get_relin_path(i).replace('/', '.'))[0]
+ for i in args.inputs
+ ]
headers: Dict[str, Header] = {}
- for table in parse_tables_from_files(args.inputs):
- out_path = in_to_out[table.input_path]
- relout_path = os.path.join(header_prefix,
- os.path.relpath(out_path, args.gen_dir))
-
- header = headers.get(table.input_path, Header(out_path, relout_path, []))
+ for table in parse_tables_from_modules(modules):
+ input_path = os.path.relpath(table.table.python_module, ROOT_DIR)
+ header = headers.get(input_path, Header([]))
header.tables.append(table)
- headers[table.input_path] = header
+ headers[input_path] = header
- # Build a mapping from table class name to the output path of the header
- # which will be generated for it. This is used to include one header into
- # another for Id dependencies.
- table_class_name_to_relout: Dict[str, str] = {}
- for header in headers.values():
- for table in header.tables:
- table_class_name_to_relout[table.table.class_name] = header.relout_path
+ for in_path, header in headers.items():
+ out_path = get_out_path(in_path)
+ relout_path = get_relout_path(in_path)
- for header in headers.values():
# Find all headers depended on by this table. These will be #include-ed when
# generating the header file below so ensure we remove ourself.
header_relout_deps: Set[str] = set()
for table in header.tables:
- header_relout_deps = header_relout_deps.union(
- [table_class_name_to_relout[c] for c in table.find_table_deps()])
- header_relout_deps.discard(header.relout_path)
+ header_relout_deps = header_relout_deps.union([
+ get_relout_path(os.path.relpath(c.python_module, ROOT_DIR))
+ for c in find_table_deps(table.table)
+ ])
+ header_relout_deps.discard(relout_path)
- with open(header.out_path, 'w', encoding='utf8') as out:
- ifdef_guard = re.sub(r'[^a-zA-Z0-9_-]', '_',
- header.relout_path).upper() + '_'
+ with open(out_path, 'w', encoding='utf8') as out:
+ ifdef_guard = re.sub(r'[^a-zA-Z0-9_-]', '_', relout_path).upper() + '_'
out.write(
serialize_header(ifdef_guard, header.tables,
sorted(header_relout_deps)))