[Python] saving cProfile results to readable external file

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am using cProfile try to profile my codes:

    pr = cProfile.Profile()
    pr.enable()
    my_func() # the code I want to profile
    pr.disable()
    pr.print_stats()


    However, the results are too long and cannot be fully displayed in the Spyder terminal (the function calls which take the longest time to run cannot be seen...). I also tried saving the results using

    cProfile.run('my_func()','profile_results')


    but the output file is not in human readable format (tried with and without .txt suffix).

    So my question is how can I save the profiling results to an external file which is human readable (like in a .txt format with all the words properly displayed)?

    Continue reading...

Compartilhe esta Página