Is it possible to let torch profiler return an organized table format rather than a raw string?

E.g. sometimes the function names are very long and it’s painful to view the raw string in a console, even with adjusting the max_name_column_width ags in .table().

How can I get a more organized format, e.g. like a pandas dataframe, or even just a raw csv with full content so that I can load it with pd.read_csv or other utils? The current raw string results seem hard to further process if the view is bad.

I found an informal way:


import pandas as pd

# ...
# get a prof (torch.profiler.profile)
# ...

prof_results = prof.key_averages()
df = pd.DataFrame(map(vars, profile_results))
# now df.key gives the function names.
# though df has many raw contents e.g. time usage is an int without unit, it still helps to inspect the prof results and is more convenient than a raw string output

Are there any better approaches?

The torch profiler is quite a disaster imo, so no, not as far as I have seen. My solution was to modify a fork of pytorch where I added functionality to return the data as a dataframe, similar to what you have done. There could be a solution buried somewhere in the source code, but for me it was faster to simply add the feature.