blob: 68610094a8aca77f7a0496ac391026c87f262de4 [file] [log] [blame]
Hector Dearmanfcbafda2018-01-18 11:13:57 +00001#!/usr/bin/env python
2# Copyright (C) 2018 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
16import argparse
17import os
18import subprocess
19import sys
20
Primiano Tucci098f0952019-09-03 10:21:20 +010021ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Hector Dearmanfcbafda2018-01-18 11:13:57 +000022
23
24def main():
25 parser = argparse.ArgumentParser()
26 parser.add_argument(
27 'encode_or_decode',
28 choices=['encode', 'decode'],
Primiano Tucci834fdc72019-10-04 11:33:44 +010029 help='encode into binary format or decode to text.')
30 parser.add_argument(
31 '--proto_name',
32 default='TraceConfig',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000033 help='name of proto to encode/decode (default: TraceConfig).')
Primiano Tucci834fdc72019-10-04 11:33:44 +010034 parser.add_argument(
35 '--protoc', default='protoc', help='Path to the protoc executable')
36 parser.add_argument(
37 '--input',
38 default='-',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000039 help='input file, or "-" for stdin (default: "-")')
Primiano Tucci834fdc72019-10-04 11:33:44 +010040 parser.add_argument(
41 '--output',
42 default='-',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000043 help='output file, or "-" for stdout (default: "-")')
44 args = parser.parse_args()
45
Primiano Tucci098f0952019-09-03 10:21:20 +010046 cmd = [
47 args.protoc,
48 '--%s=perfetto.protos.%s' % (args.encode_or_decode, args.proto_name),
49 '--proto_path=%s' % ROOT_DIR,
50 os.path.join(ROOT_DIR, 'protos/perfetto/config/trace_config.proto'),
51 os.path.join(ROOT_DIR, 'protos/perfetto/trace/trace.proto'),
52 ]
53 in_file = sys.stdin if args.input == '-' else open(args.input, 'rb')
54 out_file = sys.stdout if args.output == '-' else open(args.output, 'wb')
55 subprocess.check_call(cmd, stdin=in_file, stdout=out_file, stderr=sys.stderr)
Hector Dearmanfcbafda2018-01-18 11:13:57 +000056 return 0
57
58
59if __name__ == '__main__':
60 sys.exit(main())