blob: a5f937be330b7530ea8e9849f4ba8e8daf16df35 [file] [log] [blame]
Hector Dearmanfcbafda2018-01-18 11:13:57 +00001# Copyright (C) 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import argparse
16import os
17import subprocess
18import sys
19
Primiano Tucci098f0952019-09-03 10:21:20 +010020ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Hector Dearmanfcbafda2018-01-18 11:13:57 +000021
22
23def main():
24 parser = argparse.ArgumentParser()
25 parser.add_argument(
26 'encode_or_decode',
27 choices=['encode', 'decode'],
Primiano Tucci834fdc72019-10-04 11:33:44 +010028 help='encode into binary format or decode to text.')
29 parser.add_argument(
30 '--proto_name',
31 default='TraceConfig',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000032 help='name of proto to encode/decode (default: TraceConfig).')
Primiano Tucci834fdc72019-10-04 11:33:44 +010033 parser.add_argument(
34 '--protoc', default='protoc', help='Path to the protoc executable')
35 parser.add_argument(
36 '--input',
37 default='-',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000038 help='input file, or "-" for stdin (default: "-")')
Primiano Tucci834fdc72019-10-04 11:33:44 +010039 parser.add_argument(
40 '--output',
41 default='-',
Hector Dearmanfcbafda2018-01-18 11:13:57 +000042 help='output file, or "-" for stdout (default: "-")')
43 args = parser.parse_args()
44
Primiano Tucci098f0952019-09-03 10:21:20 +010045 cmd = [
46 args.protoc,
47 '--%s=perfetto.protos.%s' % (args.encode_or_decode, args.proto_name),
48 '--proto_path=%s' % ROOT_DIR,
49 os.path.join(ROOT_DIR, 'protos/perfetto/config/trace_config.proto'),
50 os.path.join(ROOT_DIR, 'protos/perfetto/trace/trace.proto'),
51 ]
52 in_file = sys.stdin if args.input == '-' else open(args.input, 'rb')
53 out_file = sys.stdout if args.output == '-' else open(args.output, 'wb')
54 subprocess.check_call(cmd, stdin=in_file, stdout=out_file, stderr=sys.stderr)
Hector Dearmanfcbafda2018-01-18 11:13:57 +000055 return 0
56
57
58if __name__ == '__main__':
59 sys.exit(main())