Note that the profiler samples 100x per second by default. In particular, you cannot profile anything shorter than 10ms. You can adjust the rate with the CPUPROFILE_FREQUENCY evironment variable if you want to change it.
EXAMPLES:
sage: from sage.misc.gperftools import Profiler, run_100ms
sage: prof = Profiler()
sage: prof.start() # optional - gperftools
sage: run_100ms()
sage: prof.stop() # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
REFERENCE:
Uses the Google performance analysis tools. Note that they are not included in Sage, you have to install them yourself on your system.
AUTHORS:
Bases: sage.structure.sage_object.SageObject
Interface to the gperftools profiler
INPUT:
EXAMPLES:
sage: from sage.misc.gperftools import Profiler
sage: Profiler()
Profiler logging to ...
Return the file name
OUTPUT:
String.
EXAMPLES:
sage: from sage.misc.gperftools import Profiler
sage: prof = Profiler()
sage: prof.filename()
'.../tmp_....perf'
Save report to disk.
INPUT:
EXAMPLES:
sage: from sage.misc.gperftools import Profiler, run_100ms
sage: prof = Profiler()
sage: prof.start() # optional - gperftools
sage: run_100ms() # optional - gperftools
sage: prof.stop() # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
sage: f = tmp_filename(ext='.txt') # optional - gperftools
sage: prof.save(f, verbose=False) # optional - gperftools
Start profiling
EXAMPLES:
sage: from sage.misc.gperftools import Profiler, run_100ms
sage: prof = Profiler()
sage: prof.start() # optional - gperftools
sage: run_100ms()
sage: prof.stop() # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
Stop the CPU profiler
EXAMPLES:
sage: from sage.misc.gperftools import Profiler, run_100ms
sage: prof = Profiler()
sage: prof.start() # optional - gperftools
sage: run_100ms()
sage: prof.stop() # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
Print text report
OUTPUT:
Nothing. A textual report is printed to stdout.
EXAMPLES:
sage: from sage.misc.gperftools import Profiler
sage: prof = Profiler()
sage: prof.start() # optional - gperftools
sage: # do something
sage: prof.stop() # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
sage: prof.top() # optional - gperftools
Using local file ...
Using local file ...
Profile single statement.
EXAMPLES:
sage: import sage.misc.gperftools as gperf
sage: ev = lambda ex:eval(ex, globals(), locals())
sage: gperf.crun('gperf.run_100ms()', evaluator=ev) # optional - gperftools
PROFILE: interrupts/evictions/bytes = ...
Using local file ...
Using local file ...
Used for doctesting.
A function that performs some computation for more than (but not that much more than) 100ms.
EXAMPLES:
sage: from sage.misc.gperftools import run_100ms
sage: run_100ms()