forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate-average-counters.py
executable file
·52 lines (43 loc) · 1.79 KB
/
aggregate-average-counters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import pandas as pd
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--format', '-f', choices=['no', 'csv', 'md'], default='no', required=False, help="print data using format")
parser.add_argument('--group_by', '-g', choices=['layerName', 'layerType', 'execType'], default=['layerType'], required=False, help="group data by column", nargs='+')
parser.add_argument('benchmark_average_counters_file', type=str, action='store')
return parser.parse_args();
def get_dataframe(path):
with open(path, 'r', newline='') as csvfile:
return pd.read_csv(path, delimiter=';', header=0, index_col=0)
def aggregate(df, group_by):
# remove existing total
df = df.drop(index='Total')
aggregated = df.groupby(group_by, as_index=False)['cpuTime (ms)'].agg(['count','sum'])
# sort by sum
result = aggregated.sort_values(by=['sum'], ascending=False)
# add percentage
result['%'] = (result['sum'] / result['sum'].sum()) * 100
# round percentage
result = result.round({'%': 2})
# add total
result.loc['Total'] = result.sum(numeric_only=True)
for group in group_by:
result.at['Total', group] = 'Total'
# ensure count as int (no trailing .0)
result['count'] = result['count'].astype('int')
# rename columns
result = result.rename(columns={"count": "Count", "sum":"Sum (ms)"})
return result
def print_df(df, format):
if format == 'csv':
print(df.to_csv(index=False))
elif format == 'md':
print(df.to_markdown(index=False))
else:
print(df.to_string(index=False))
if __name__ == "__main__":
args = parse_args();
df = get_dataframe(args.benchmark_average_counters_file);
df = aggregate(df, args.group_by)
print_df(df, args.format)