blob: 6c7fa85d0d363c2a8588201c36a6d13acfe9b870 [file] [log] [blame]
Lalit Maganti5eacf422020-06-30 13:51:23 +01001#!/usr/bin/env python3
2# Copyright (C) 2020 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
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20import argparse
21import os
22import sys
23
Anna Mayznerf60f53d2023-01-13 15:46:00 +000024ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25sys.path.append(ROOT_DIR)
26
27from python.generators.diff_tests.utils import serialize_textproto_trace, serialize_python_trace
Lalit Maganti5eacf422020-06-30 13:51:23 +010028
29
30def main():
31 parser = argparse.ArgumentParser()
32 parser.add_argument(
Hector Dearmanb1989b02022-07-05 20:11:07 +010033 '--out', type=str, help='out directory to search for trace descriptor')
Lalit Magantidf500092020-07-16 23:56:24 +010034 parser.add_argument(
35 '--descriptor', type=str, help='path to the trace descriptor')
Lalit Maganti5eacf422020-06-30 13:51:23 +010036 parser.add_argument('trace_path', type=str, help='path of trace to serialize')
37 args = parser.parse_args()
38
Lalit Magantidf500092020-07-16 23:56:24 +010039 if args.out and not args.descriptor:
40 trace_protos_path = os.path.join(args.out, 'gen', 'protos', 'perfetto',
41 'trace')
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000042 chrome_extension_descriptor_path = os.path.join(
43 args.out, 'gen', 'protos', 'third_party', 'chromium',
44 'chrome_track_event.descriptor')
Lalit Magantidf500092020-07-16 23:56:24 +010045 trace_descriptor_path = os.path.join(trace_protos_path, 'trace.descriptor')
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000046 test_extensions_descriptor_path = os.path.join(
47 trace_protos_path, 'test_extensions.descriptor')
48 extension_descriptors = [
49 chrome_extension_descriptor_path, test_extensions_descriptor_path
50 ]
Lalit Magantidf500092020-07-16 23:56:24 +010051 elif args.descriptor and not args.out:
52 trace_descriptor_path = args.descriptor
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000053 extension_descriptors = []
Lalit Magantidf500092020-07-16 23:56:24 +010054 else:
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000055 raise RuntimeError(
56 'Exactly one of --out and --descriptor should be provided')
Lalit Maganti5eacf422020-06-30 13:51:23 +010057
58 trace_path = args.trace_path
59
60 if trace_path.endswith('.py'):
Anna Mayznerf60f53d2023-01-13 15:46:00 +000061 serialize_python_trace(ROOT_DIR, trace_descriptor_path, trace_path,
62 sys.stdout.buffer)
Lalit Maganti5eacf422020-06-30 13:51:23 +010063 elif trace_path.endswith('.textproto'):
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000064 serialize_textproto_trace(trace_descriptor_path, extension_descriptors,
65 trace_path, sys.stdout.buffer)
Lalit Maganti5eacf422020-06-30 13:51:23 +010066 else:
67 raise RuntimeError('Invalid extension for unserialized trace file')
68
69 return 0
70
71
72if __name__ == '__main__':
73 sys.exit(main())