|
| 1 | +from sea_runtool import TaskCombiner |
| 2 | + |
| 3 | +################################### |
| 4 | +# TODO: add OS events (sched/vsync) |
| 5 | +class BestTraceFormat(TaskCombiner): |
| 6 | + """Writer for Best Trace Format. |
| 7 | +
|
| 8 | + Specs for BTF v2.1.3: https://wiki.eclipse.org/images/e/e6/TA_BTF_Specification_2.1.3_Eclipse_Auto_IWG.pdf |
| 9 | + """ |
| 10 | + |
| 11 | + def __init__(self, args, tree): |
| 12 | + """Open the .btf file and write its header.""" |
| 13 | + TaskCombiner.__init__(self, tree) |
| 14 | + self.args = args |
| 15 | + self.file = open(self.get_targets()[-1], "w+b") |
| 16 | + self.file.write('#version 2.1.3\n') |
| 17 | + self.file.write('#creator GDP-SEA\n') |
| 18 | + self.file.write('#creationDate 2014-02-19T11:39:20Z\n') |
| 19 | + self.file.write('#timeScale ns\n') |
| 20 | + |
| 21 | + def get_targets(self): |
| 22 | + return [self.args.output + ".btf"] |
| 23 | + |
| 24 | + def complete_task(self, type, b, e): |
| 25 | + """ |
| 26 | + type -- task type : {"task", "frame", "counter"} |
| 27 | + b -- { 'thread_name': '0x6296', 'domain': 'gles.trace.ergs', 'str': 'glPopMatrix', 'time': 1443097648250368731, 'tid': 25238, 'pid': 25238} |
| 28 | + e -- { 'tid': 25238, 'thread_name': '0x6296', 'domain': 'gles.trace.ergs', 'pid': 25238, 'time': 1443097648250548143} |
| 29 | + """ |
| 30 | + # <Time>,<Source>,<SourceInstance >,<TargetType>,<Target>,<TargetInstance>,<Event>,<Note> |
| 31 | + if 'str' in b and type == "task": |
| 32 | + self.file.write("%d,%s,0,R,%s,-1,start\n" % (b['time'], b['str'], b['str'])) |
| 33 | + self.file.write("%d,%s,0,R,%s,-1,terminate\n" % (e['time'], b['str'], b['str'])) |
| 34 | + |
| 35 | + def finish(self): |
| 36 | + """ Close the .btf file""" |
| 37 | + self.file.close() |
| 38 | + |
| 39 | + @staticmethod |
| 40 | + def join_traces(traces, output): |
| 41 | + with open(output + ".btf", 'wb') as outfile: |
| 42 | + for file in traces: |
| 43 | + with open(file, 'rb') as infile: |
| 44 | + for line in infile: |
| 45 | + outfile.write(line) |
| 46 | + return output + ".btf" |
| 47 | + |
| 48 | +EXPORTER_DESCRIPTORS = [{ |
| 49 | + 'format': 'btf', |
| 50 | + 'available': True, |
| 51 | + 'exporter': BestTraceFormat |
| 52 | +}] |
0 commit comments