blob: 5bb908049920be4daa941767569092e991a6a759 [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
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000024from proto_utils import serialize_python_trace, serialize_textproto_trace
Lalit Maganti5eacf422020-06-30 13:51:23 +010025
26
27def main():
28 parser = argparse.ArgumentParser()
29 parser.add_argument(
30 '--out',
31 type=str,
Lalit Maganti5eacf422020-06-30 13:51:23 +010032 help='out directory to search for trace descriptor')
Lalit Magantidf500092020-07-16 23:56:24 +010033 parser.add_argument(
34 '--descriptor', type=str, help='path to the trace descriptor')
Lalit Maganti5eacf422020-06-30 13:51:23 +010035 parser.add_argument('trace_path', type=str, help='path of trace to serialize')
36 args = parser.parse_args()
37
Lalit Magantidf500092020-07-16 23:56:24 +010038 if args.out and not args.descriptor:
39 trace_protos_path = os.path.join(args.out, 'gen', 'protos', 'perfetto',
40 'trace')
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000041 chrome_extension_descriptor_path = os.path.join(
42 args.out, 'gen', 'protos', 'third_party', 'chromium',
43 'chrome_track_event.descriptor')
Lalit Magantidf500092020-07-16 23:56:24 +010044 trace_descriptor_path = os.path.join(trace_protos_path, 'trace.descriptor')
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000045 test_extensions_descriptor_path = os.path.join(
46 trace_protos_path, 'test_extensions.descriptor')
47 extension_descriptors = [
48 chrome_extension_descriptor_path, test_extensions_descriptor_path
49 ]
Lalit Magantidf500092020-07-16 23:56:24 +010050 elif args.descriptor and not args.out:
51 trace_descriptor_path = args.descriptor
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000052 extension_descriptors = []
Lalit Magantidf500092020-07-16 23:56:24 +010053 else:
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000054 raise RuntimeError(
55 'Exactly one of --out and --descriptor should be provided')
Lalit Maganti5eacf422020-06-30 13:51:23 +010056
57 trace_path = args.trace_path
58
59 if trace_path.endswith('.py'):
60 serialize_python_trace(trace_descriptor_path, trace_path, sys.stdout.buffer)
61 elif trace_path.endswith('.textproto'):
Andrew Shulaev94d1bf22021-01-15 15:30:42 +000062 serialize_textproto_trace(trace_descriptor_path, extension_descriptors,
63 trace_path, sys.stdout.buffer)
Lalit Maganti5eacf422020-06-30 13:51:23 +010064 else:
65 raise RuntimeError('Invalid extension for unserialized trace file')
66
67 return 0
68
69
70if __name__ == '__main__':
71 sys.exit(main())