Based on this post: https://qxf2.com/blog/saving-cprofile-stats-to-a-csv-file/
if __name__ == "__main__":
pr = cProfile.Profile()
pr.enable()
main()
pr.disable()
csv = prof_to_csv(pr)
with open("prof.csv", 'w+') as f:
f.write(csv)