From 27f4f38880e8cce55ce722b87c604b655ae6989a Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Tue, 17 Mar 2020 12:20:25 -0400 Subject: [PATCH] Update parse_trace.py [ROCm/roctracer commit: 90912231e784f9033186998d9ebfebf027898c93] --- projects/roctracer/script/parse_trace.py | 49 ++++++++++++++++-------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/projects/roctracer/script/parse_trace.py b/projects/roctracer/script/parse_trace.py index c1f3de0b66..7c8a72c8e9 100644 --- a/projects/roctracer/script/parse_trace.py +++ b/projects/roctracer/script/parse_trace.py @@ -1,20 +1,47 @@ #!/usr/bin/python +#Copyright (c) 2015-present Advanced Micro Devices, Inc. All rights reserved. +# +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in +#all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +#THE SOFTWARE. + import os, sys, re import argparse events_count = {} events_order = {} -def parse_trace(tracefile,cnt,order): +#Parses roctracer trace file for regression purpose +#and generates events count per event (when cnt is on) or events order per tid (when order is on) +def gen_events_info(tracefile,cnt,order): + res='' with open(tracefile) as f: for line in f: event_pattern = re.compile(r'<(\w+)\s+id\(\d+\)\s+.*tid\((\d+)\)>') + # event_pattern extracts event(grp1) and tid (grp2) from a line like this: + # m = event_pattern.match(line) if m: event = m.group(1) tid = m.group(2) event_pattern2 = re.compile(r'\d+:\d+\s+\d+:(\d+)\s+(\w+)') + # event_pattern2 extracts tid (grp1) and event (grp2) from a line like this: + # 1822810364769411:1822810364771941 116477:116477 hsa_agent_get_info(, 17, 0x7ffeac015fec) = 0 m2 = event_pattern2.match(line) if m2: event = m2.group(2) @@ -29,21 +56,11 @@ def parse_trace(tracefile,cnt,order): events_order[tid].append(event) else: events_order[tid] = [event] - if cnt: + if cnt==1: for event,count in events_count.items(): - print event + ": count " + str(count) - if order: + res = res + event + ": count " + str(count) + if order==1: for tid in sorted (events_order.keys()) : - print str(events_order[tid]) - -parser = argparse.ArgumentParser(description='parse_trace.py: reads roctracer trace file and parses it.') -parser.add_argument('-or', action='store_true',help='Generates ordered events') -parser.add_argument('-cn', action='store_true',help='Generates events count') -requiredNamed = parser.add_argument_group('Required arguments') -requiredNamed.add_argument('-in', metavar='file', help='Trace file', required=True) - -args = vars(parser.parse_args()) - -if __name__ == '__main__': - parse_trace(args['in'],args['cn'],args['or']) + res = res + str(events_order[tid]) + return res