I am trying to perform some high-level profiling of a rather complex Python program. However, when using cProfile, almost all time is measured in:
{method 'enable' of '_lsProf.Profiler' objects}
It happens if I profile the whole program python -m cProfile ...
as well as when I perform profiling within the Python code (with profile.enable()/.disable()/.create_stats...
)
Any pointers to what I could be doing wrong?
The syntax is cProfile. run(statement, filename=None, sort=-1) . You can pass python code or a function name that you want to profile as a string to the statement argument. If you want to save the output in a file, it can be passed to the filename argument.
Analysis of the profiler data is done using the Stats class. This class constructor creates an instance of a “statistics object” from a filename (or list of filenames) or from a Profile instance.
In Python's standard library, we have the timeit module that allows us to do some simple profiling. The output of timeit is to find the best performance among multiple runs (default to be 5).
It's because somewhere in your code you have something like
import cProfile
pr = cProfile.Profile()
pr.enable()
That's for manually saving the results or printing them, if you are calling the profiler like you said with python -m cProfile -o program.prof my_program.py
you don't need to use cProfile inside the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With