Questions tagged [cprofile]

cProfile is a built-in Python module that describes the run time performance of a program, providing a variety of statistics.

cProfile is a built-in module suitable for profiling Python programs. It's designed as a faster drop-in replacement for the profile implementation. cProfile is implemented as C-Extension which provides less overhead than the pure Python implementation of profile, but it may not be available in all Python implementations.

It can be used in a Python file:

import cProfile
cProfile.run('insert_your_code_to_profile_here')

But also from the command-line, to profile a script:

python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py)

Sources:

230 questions
1
vote
1 answer

How i can profile a python script consisting of multiple modules and classes?

I want to profile my python code. My code includes several modules where each module is a class with several functions. I am using eclipse PyDev as IDE. I have read a few QA about timeit and cprofile but using these profilers are a bit hard when you…
alenrooni
  • 127
  • 1
  • 1
  • 7
1
vote
1 answer

How do I open python profile data with kCacheGrind?

I am having trouble examining profile data with qcachegrind on mac.I am using django-extensions to generate the profile data. I am able to open a normal profile log using cProfile in the code with pyprof2calltree, but i cannot open the output…
vasion
  • 1,237
  • 3
  • 18
  • 29
1
vote
0 answers

How to get cProfile results from a callback function in Python

I am trying to determine which parts of my python code are running the slowest, so that I have a better understanding on what I need to fix. I recently discovered cProfile and gprof2dot which have been extremely helpful. My problem is that I'm not…
Brent
  • 719
  • 2
  • 9
  • 18
1
vote
1 answer

Python Profiling - Rollup function calls that are outside my code

I am trying to profile our django unittests (if the tests are faster, we'll run 'em more often). I've ran it through python's built in cProfile profiler, producing a pstats file. However the signal to noise ration is bad. There are too many…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
1
vote
1 answer

cProfile reports almost all time spent in :1()

I'm profiling some code, and cProfile reports that almost all the time is spent in :1(). What does that mean? Here's the output of cProfile: 10182 function calls in 191.365 seconds Ordered by: standard name ncalls tottime percall …
user1454156
  • 133
  • 3
0
votes
2 answers

How to fix 'ModuleNotFoundError: No module named transformer.modules' while profiling a Python script with cProfile?

Trying to profile a python script using cProfile. It has subfiles being called encoder.py and decoder.py in the directory "modules" in "transformer". When I profile it, error shows module error, trasformer is not a module. Though I am not…
0
votes
0 answers

How come the tottime is *greater* than cumtime, when using cProfile?

I'm using cprofile and snakeviz to analyze some python code. I'm getting weird results like this: Two questions: Given that the cumtime is supposed to include the runtime of the routine and all subroutines, and the tottime is only the runtime of…
Just Me
  • 413
  • 3
  • 9
0
votes
0 answers

Can I turn off profiling in a portion of python code when invoking cProfile as a script?

I want to profile my code, but exclude startup. Python docs describe how to run cProfile as a script: python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py) They also describe how to turn profiling on and off using the python…
dfrankow
  • 20,191
  • 41
  • 152
  • 214
0
votes
1 answer

What does {method 'poll' of 'select.poll'...} mean in cprofile output?

I have a flask app that I'm trying to profile (I'm new to this). When I ran it, I had this result: 3327 function calls (3247 primitive calls) in 7.350 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall…
Mike Mann
  • 528
  • 4
  • 18
0
votes
0 answers

Profile() context vs runctx

When I run my_str = "res = f(content1, content2, reso)" cProfile.runctx(my_str, globals(), locals()) I get: 3 function calls in 0.038 seconds Ordered by: standard name ncalls tottime percall cumtime percall…
Ivan
  • 1,352
  • 2
  • 13
  • 31
0
votes
1 answer

cProfile measure module with -- arguments

I want to profile a module that takes arguments with -- . cProfile then thinks that these are arguments for themselves. How can I work around this? py -3.9 -m cProfile -m my_module -o statistics --my-argument Usage: cProfile.py [-o…
Fire Cube
  • 15
  • 4
0
votes
0 answers

Problem running python cProfile in VSCode debug console

I'm trying to setup a good VSCode python environment for debugging including profiling using cProfile in a REPL manner, and I really like the debug widow. In the VSCode debugger I am able to run/debug the following script: import…
0
votes
0 answers

python exe program created using pyinstaller how do I profile the whole program using commandline -m cProfile

usually i do python -m cProfile myapp.py to run profiling. i used pyinstaller my.spec --dist mydir --noconfirm and created mydir/myapp an executable program now i would like to run cProfile myapp and see the pstats. how do I do that on this…
amu
  • 1
  • 1
0
votes
0 answers

cprofile .prof file structure

I would like to use snakeviz (https://jiffyclub.github.io/snakeviz/) or tuna to profile a non-python program (weird, isn't it?). This program dumps a log file with time spent on each routine. I would like to parse this file and create from-scrath a…
Nic
  • 3,365
  • 3
  • 20
  • 31
0
votes
0 answers

Read cProfile snapshot data

I have a few cProfile output files that were generated by adding -m cProfile -o out.pstat to the regular python command I run. Now I need to compare these files with attention to some significant differences between function calls. I can open these…
Djent
  • 2,877
  • 10
  • 41
  • 66