Created
March 24, 2021 14:22
-
-
Save FindHao/a6f476d06de07935880c3739ec2f090e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import argparse | |
def work(filename, str_pattern): | |
with open(filename, 'r') as fin: | |
content = fin.readlines() | |
if len(content) < 1: | |
print("wrong report") | |
exit(1) | |
time_unit_raw = content[0].split(",")[1] | |
reg = re.compile(r"\((.*)\)") | |
result = reg.findall(time_unit_raw) | |
if result: | |
time_unit = result[0] | |
else: | |
time_unit = '' | |
for line in content[1:]: | |
lines = line.split(',') | |
if len(lines) < 7: | |
print("Wrong line: ", line) | |
else: | |
kernelname = lines[6] | |
if kernelname.find(str_pattern) >= 0: | |
print(lines[1], time_unit, " ,".join(lines[6:])) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-i', '--report-path', metavar='The path of nsys reports.', | |
required=True, dest='report_path', action='store') | |
parser.add_argument('-p', '--pattern', | |
metavar='kernel name', | |
required=True, dest='kernel_name', action='store') | |
args = parser.parse_args() | |
work(args.report_path, args.kernel_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment