Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make cProfile print only significant functions?

I get about 300 entries from my cProfile output and had to scroll up a long time every time I use it.

Is there a way to make cProfile print only like, top 10 lines or something?

like image 431
Zuoanqh Avatar asked Sep 17 '25 04:09

Zuoanqh


1 Answers

You can sort by say 'cumulative' and show top N lines using print_stats(4). Without sorting on something watching the top N lines may not be of use.

From Python profiler official docs

import pstats
p = pstats.Stats('restats')
p.sort_stats('cumulative').print_stats(10)
like image 58
quiet_penguin Avatar answered Sep 19 '25 05:09

quiet_penguin