Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's profile module: <string>:1(?)

Tags:

I am using Python's (v2.4) profile module to profile a numpy script, and the following entry appears to account for the bulk of the execution time:

ncalls  tottime  percall  cumtime  percall filename:lineno(function)  256/1    0.000    0.000    7.710    7.710 <string>:1(?) 

Unfortunately, its appearance makes it hard to Google.

How do I go about figuring out what this is exactly?

edit The profiler is run from the shell as follows: python -m profile -s cumulative script.py

like image 950
NPE Avatar asked May 11 '11 12:05

NPE


People also ask

How do you code a python profile?

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.

What is Python profiling?

Profiling is a technique to figure out how time is spent in a program. With these statistics, we can find the “hot spot” of a program and think about ways of improvement. Sometimes, a hot spot in an unexpected location may hint at a bug in the program as well.

How do you use line profiler in Python?

The line_profiler test cases (found on GitHub) have an example of how to generate profile data from within a Python script. You have to wrap the function that you want to profile and then call the wrapper passing any desired function arguments. Also, you can add additional functions to be profiled as well.

Which tool will Analyse the data collected by the Python profiler?

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.


1 Answers

Ignore this line. It is an artifact of how the profiler is implemented. It is not telling you anything useful. Look at the "tottime" value for it: 0.000. "tottime" is the amount of time spent executing "<string>:1(?)" excluding time spent executing children of it. So, no time is spent here. "cumtime" and "percall" are large because they include time spent in children. See http://docs.python.org/library/profile.html#cProfile.run for more details.

like image 164
Jean-Paul Calderone Avatar answered Sep 22 '22 15:09

Jean-Paul Calderone