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
10
votes
3 answers

Python cprofile filename:lineno get full path

I use cprofile to get high offenders, however the filename:lineno is only listing the filename, but having the filepath listed would be more usefull to quickly open that path. Especially if there might be same module nams in different hierarchies.…
user1767754
  • 23,311
  • 18
  • 141
  • 164
10
votes
4 answers

App Engine: Is time.sleep() counting towards my quotas?

Hey. I'm working on an App Engine app that involves queries to the Google Maps API for geocoding. Google Maps doesn't like too much requests so I put a 1 second delay between each request with time.sleep(1). I noticed that my quotas are running low…
kovshenin
  • 31,813
  • 4
  • 35
  • 46
10
votes
1 answer

Profiling Python code that uses multiprocessing?

I have a simple producer consumer pattern set up in part of my gui code. I'm attempting to profile just the specific consumer section to see if there's any chance for optimization. However, when attempting to run the code with python -m cProfile -o…
Zack Yoshyaro
  • 2,056
  • 6
  • 24
  • 46
9
votes
3 answers

Increasing the depth of cProfiler in Python to report more functions?

I'm trying to profile a function that calls other functions. I call the profiler as follows: from mymodule import foo def start(): # ... foo() import cProfile as profile profile.run('start()', output_file) p = pstats.Stats(output_file) print…
user248237
9
votes
1 answer

How can I use python's cProfile to profile a django app while running on gunicorn

How can I profile a Django application while running on gunicorn using python cProfile. I can profile in development mode: python -m cProfile -o sample.profile manage.py runserver But what should I do when it is running in production server using…
Ramin Mir.
  • 784
  • 1
  • 7
  • 18
9
votes
3 answers

What tools should I use to profile Python code on window 7

I want to profile python code on Widnows 7. I would like to use something a little more user friendly than the raw dump of cProfile. In that search I found the GUI RunSnakeRun, but I cannot find a way to download RunSnakeRun on Windows. Is it…
lemiant
  • 4,205
  • 4
  • 31
  • 38
8
votes
1 answer

How to save output of cProfile.Profile() to a *.prof file in Python Script

Hi I know the usage of command line method to profile a python script as given below. python -m cProfile -o program.prof my_program.py However I'm profiling specific piece of code in Python using cProfile module as given below. import cProfile,…
Muhammad Abdullah
  • 876
  • 2
  • 8
  • 26
8
votes
2 answers

Python cProfile - most of time spent in method 'enable' of '_lsprof.Profiler'

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…
Simon Heinzle
  • 1,095
  • 1
  • 9
  • 17
8
votes
1 answer

Error when profiling an otherwise perfectly working multiprocessing python script with cProfile

I've written a small python script that uses multiprocessing (See https://stackoverflow.com/a/41875711/1878788). It works when I test it: $ ./forkiter.py 0 1 2 3 4 sum of x+1: 15 sum of 2*x: 20 sum of x*x: 30 But when I try to profile it with…
bli
  • 7,549
  • 7
  • 48
  • 94
8
votes
1 answer

Python cProfile: how to filter out specific calls from the profiling data?

I've started profiling a script which has many sleep(n) statements. All in all, I get over 99% of the run time spent sleeping. Nevertheless, it occasionally runs into performance problems during the time that it does real work but the relevant,…
GJ.
  • 5,226
  • 13
  • 59
  • 82
8
votes
1 answer

Trying to install cProfile with pip and I'm getting an error

So I've looked around everywhere for help on how to install cProfile and I've found nothing. When this usually happens I turn to pip and run the usual: 'pip install [module name]' but I'm getting the error: No matching distribution found for…
user5305217
7
votes
0 answers

Python type annotation slows down the code

I am optimizing my code for performance, and when I use cProfile to check my code, a good deal of runtime is due to type annotation! Removing type annotation indeed improves the performance. You can see the output of cProfiler for the annotated and…
7
votes
1 answer

cProfiling a module with relative imports

I have these files in mymodule mymodule ├── config.py ├── __init__.py └── lib.py With this simple content: # config.py NAME = "Julius Cesar" # lib.py from .config import NAME def get_name(): return NAME I can run it (and nothing happens)…
blueFast
  • 41,341
  • 63
  • 198
  • 344
7
votes
1 answer

profiling numpy with cProfile not giving useful results

This code: import numpy as np import cProfile shp = (1000,1000) a = np.ones(shp) o = np.zeros(shp) def main(): np.divide(a,1,o) for i in xrange(20): np.multiply(a,2,o) np.add(a,1,o) cProfile.run('main()') prints only: …
Paul
  • 42,322
  • 15
  • 106
  • 123
7
votes
3 answers

Fortran extension to Python via f2py: How to profile?

I'm using an extension to Python (2.7.2) written in Fortran (gfortran 4.4.7) compiled via f2py (Ver. 2). I can profile the Python part with cProfile, but the result does not give any information about the Fortran functions. Instead the time is…
NichtJens
  • 1,709
  • 19
  • 27
1 2
3
15 16