• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This script parses the logcat lines produced by the Tuning Fork DebugBackend
2#  which are base64 encoded serializations of TuningForkLogEvent protos.
3# Usage:
4#  adb logcat -d | python parselogcat.py
5
6import sys
7import re
8
9# To generate python files from the proto files:
10# export TF_PROTO_DIR=../../src/tuningfork/proto/
11# protoc --python_out=. -I$TF_PROTO_DIR $TF_PROTO_DIR/tuningfork.proto
12# protoc --python_out=. -I$TF_PROTO_DIR $TF_PROTO_DIR/tuningfork_clearcut_log.proto
13# export TF_DEV_PROTO_DIR=<somewhere>
14# protoc --python_out=. -I$TF_DEV_PROTO_DIR $TF_DEV_PROTO_DIR/dev_tuningfork.proto
15
16# 'pip install protobuf' if you get a 'No module named protobuf' error
17
18import tuningfork_clearcut_log_pb2 as tcl
19import dev_tuningfork_pb2 as tf
20
21# Example logcat line:
22#11-30 15:32:22.892 13781 16553 I TuningFork.Clearcut: (TCL1/1)GgAqHAgAEgAaFgAAAAAAAAAAAAAAAAAAAAAAAAAAAEg=
23tflogcat_regex = r"(\S+ \S+).*TuningFork.*\(TCL(.+)/(.+)\)(.*)"
24
25def flatten(s):
26  return ', '.join(s.strip().split('\n'))
27
28def prettyPrint(tclevent):
29  fp =tf.FidelityParams()
30  fp.ParseFromString(tclevent.fidelityparams)
31  print "fidelityparams: ", flatten(str(fp))
32  for h in tclevent.histograms:
33    print "histograms {"
34    print "  instrument_id: ", h.instrument_id
35    a = tf.Annotation()
36    a.ParseFromString(h.annotation)
37    print "  annotation: ", flatten(str(a))
38    for c in h.counts:
39      print "  counts: ", c
40    print "}"
41
42ser = ""
43def getTCLEvent(i, n, ser_in):
44  global ser
45  if i==1:
46    ser = ""
47  ser += ser_in
48  if i<>n:
49    return
50  l = tcl.TuningForkLogEvent()
51  l.ParseFromString(ser.decode("base64"))
52  return l
53
54def readStdin():
55  for logcat_lines in sys.stdin.readlines():
56    m = re.match(tflogcat_regex, logcat_lines)
57    if m:
58      subparts = m.groups()
59      tstamp = subparts[0]
60      tclevent = getTCLEvent(int(subparts[1]),int(subparts[2]),subparts[3])
61      if tclevent:
62        prettyPrint(tclevent)
63
64def main():
65  readStdin()
66
67if __name__ == "__main__":
68  main()
69