pstats is a profiling tool for Python.
Questions tagged [pstats]
13 questions
29
votes
3 answers
How can I analyze a file created with pstats.dump_stats(filename) off line?
I have essentially done the following:
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
# ... my code did something ...
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr,…

Love and peace - Joe Codeswell
- 2,835
- 3
- 39
- 50
5
votes
0 answers
Ignoring function calls from cProfile log
I know that it is possible to get the frequency of function calls for a particular module using the pstats.print_stats('python_script.py:'), however I would like to print a report of the frequencies of all invoked functions in a profiled program…

erik
- 3,810
- 6
- 32
- 63
5
votes
1 answer
Error when attempting to write cProfile information to file
I am attempting to load a cProfile profile, do some sorting and finessing, then output the results to a file. Based on the documentation, I thought I could simply pass a file object and the print_stats function would redirect to that stream.
Here…

erik
- 3,810
- 6
- 32
- 63
4
votes
1 answer
Programmatically accessing cProfile data
I need to capture some python profiling data and generate a report.
While most of this component runs Python 3.5, to support a couple of legacy modules, we still have part of the system that runs 2.7.
In this instance, 3.5 invokes 2.7 via…

Basic
- 26,321
- 24
- 115
- 201
3
votes
1 answer
Python cProfile - decorated functions obscuring profile visualization
I have a base class with a @classmethod which acts as a decorator for a large number of methods in many descendant classes.
class BaseClass():
@classmethod
def some_decorator(cls, method):
@wraps(method)
def…

Eric Ihli
- 1,722
- 18
- 30
3
votes
1 answer
Making use of pstats and cProfile in Python. How to make array work faster?
This is my first optimization of the code and I am excited about it. Read some articles but I still have some questions.
1) First of all, what does take so much time in my code below? I think it is array over here:…

Sergey
- 67
- 5
2
votes
1 answer
Why is pstats.print_callers() ignores the restriction argument?
I'm trying to profile my python script using cProfile and displaying the results with pstats. In particular, I'm trying to use the pstats function p.sort_stats('time').print_callers(20) to print only the top 20 functions by time, as decribed in the…

Elegant Code
- 678
- 6
- 18
2
votes
1 answer
Python script long execuation function
Hello i got a problem that a function in my script takes long to execute. So i am trying to optimize the code and i am currently using cProfile and Pstats for that.
When i execute a function it takes around 0.7 seconds to 1+ seconds to finish. The…

Patrick
- 23
- 3
2
votes
0 answers
Flask profling error: the profiler is not available because profile or pstat is not installed
I'm attempting to run a profiling process on my website, per the discussion here, but have run into this error. Here's the full stack trace:
C:\Users\Alex\Anaconda3\envs\mysite\python.exe C:/Users/Alex/Desktop/mysite/profile.py
Traceback (most…

Aleksey Bilogur
- 3,686
- 3
- 30
- 57
2
votes
1 answer
Profiling only user defined functions pstats
I'm trying to use Stats() from the pstats module as such:
p = Profile()
p.runcall(wrangle_file,input_filename="test.csv",output_file="solution.csv",metrics=True)
stats = Stats(p)
stats.strip_dirs()
stats.sort_stats('cumulative')
…

lorenzocastillo
- 985
- 3
- 13
- 24
2
votes
0 answers
Python: Pstats seems to ignore time spend in fortran routine
I want to profile a python code which calls fortran routines.
I use for this PSTATS, but as shows in the example below, PSTATS does'nt take into account the time spend in fortran routines.
Fortran module (mod_fortran.f90):
module…

Ngrigri
- 73
- 1
- 4
1
vote
1 answer
How to use "dump_pstats" properly to retrieve the sorted data of the "cProfile" into "txt" file?
As the title indicate I have this issue of retrieving those information from dump_stats properly. Without further ado here is my simple code.
Code
import cProfile
import pstats
def fun_to_profile():
... code to be profilled ...
profiler =…

Lambda
- 33
- 6
1
vote
0 answers
Python PyProf2CallTree Error
i'm trying to run PyProf2CallTree from inside my script with the following command on Windows:
os.system("python pyprof2calltree.py -i inputfile.pstats -o outputfile.kgrind")
And This is the error im receiving:

KnakworstKoning
- 361
- 3
- 6
- 18