Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPU] Add script for benchmark average counters aggregation #25652

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Aggregate average counters

Aggregate csv data produced by
``` shell
benchmark_app --report_type average_counters
```

Simple example:
``` shell
aggregate-average-counters.py benchmark_average_counters_report.csv
```

See `help` for more options
``` shell
aggregate-average-counters.py --help
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas>=2.0
argparse
Loading