what does "execfile" mean within profiler output and why does it not have a attached line number

Discussion in 'Python' started by Rahul, Apr 5, 2009.

  1. Rahul

    Rahul Guest

    "profile" tells me that most of my runtime was spent in just one part (1.28
    sec cumulatively out of 1.29 secs. But what is "execfile"? I don't see this
    as a function call with my python code. Also what's the 0 in the snippet:
    ":0(execfile)"? Isn't there supposed to be a line-number?

    Looking up "execfile" in the python manual leads me to "exec": "This
    statement supports dynamic execution of Python code."

    But that seems pretty generic; how can I now try figuring out which part of
    my python file is the bottleneck?

    Sorry, I'm a newbiee to profiling.


    ######################################################################
    51651 function calls (37762 primitive calls) in 1.290 CPU seconds
    ncalls tottime percall cumtime percall filename:lineno(function)
    [snip]
    1 0.010 0.010 1.280 1.280 :0(execfile)
    [snip]
    ##########################################################




    --
    Rahul
    Rahul, Apr 5, 2009
    #1
    1. Advertising

  2. Rahul

    John Machin Guest

    Re: what does "execfile" mean within profiler output and why does itnot have a attached line number

    On Apr 5, 9:56 am, Rahul <> wrote:
    > "profile" tells me that most of my runtime was spent in just one part (1.28
    > sec cumulatively out of 1.29 secs. But what is "execfile"? I don't see this
    > as a function call with my python code. Also what's the 0 in the snippet:  
    > ":0(execfile)"? Isn't there supposed to be a line-number?
    >
    > Looking up "execfile" in the python manual leads me to "exec": "This
    > statement supports dynamic execution of Python code."
    >
    > But that seems pretty generic; how can I now try figuring out which part of
    > my python file is the bottleneck?
    >
    > Sorry, I'm a newbiee to profiling.
    >
    > ######################################################################
    >        51651 function calls (37762 primitive calls) in 1.290 CPU seconds
    >  ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    > [snip]
    >     1    0.010    0.010    1.280    1.280 :0(execfile)
    > [snip]
    > ##########################################################


    That means no more than "the profiler executed all of your code
    once, it took 0.01 seconds inside the execfile itself, 0.01 seconds
    per execution, total time spent by the execfile *and* what it called
    was 1.28 seconds ("cum" == "cumulative"), again 1.28 secs per
    execution"

    So ignore that and look at the figures for the app functions/methods.
    John Machin, Apr 5, 2009
    #2
    1. Advertising

  3. Rahul

    Robert Kern Guest

    Re: what does "execfile" mean within profiler output and why doesit not have a attached line number

    On 2009-04-04 18:56, Rahul wrote:
    > "profile" tells me that most of my runtime was spent in just one part (1.28
    > sec cumulatively out of 1.29 secs. But what is "execfile"? I don't see this
    > as a function call with my python code. Also what's the 0 in the snippet:
    > ":0(execfile)"? Isn't there supposed to be a line-number?


    It's a builtin function, so it has no filename or line number.

    execfile is a function that reads a Python file and executes its code. This is
    almost certainly the execfile call from profile.py itself that is running your
    code. Ignore it.

    > Looking up "execfile" in the python manual leads me to "exec": "This
    > statement supports dynamic execution of Python code."
    >
    > But that seems pretty generic; how can I now try figuring out which part of
    > my python file is the bottleneck?


    To quickly find your hotspots, start by sorting by 'time' (that would be
    displayed as the 'tottime' column in the human-readable output). That tells you
    how much time is spent in each function itself, excluding the time it spends
    calling out to other functions. For example, per the docs under "Instant User’s
    Manual" (which you might want to spend a little more time with):

    p.sort_stats('time').print_stats(10)

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Apr 5, 2009
    #3
  4. Rahul

    Rahul Guest

    Re: what does "execfile" mean within profiler output and why does it not have a attached line number

    Robert Kern <> wrote in
    news::

    > To quickly find your hotspots, start by sorting by 'time' (that would
    > be displayed as the 'tottime' column in the human-readable output).
    > That tells you how much time is spent in each function itself,
    > excluding the time it spends calling out to other functions. For
    > example, per the docs under "Instant Userƒ Ts Manual" (which you might
    > want to spend a little more time with):
    >
    > p.sort_stats('time').print_stats(10)
    >
    >


    Thanks Robert. I was executing the profiler on the commandline like so:

    python -m profile ~/bin/visualize.py *.nc

    Is there any way to pass further options of the form sort etc. via this
    invocation. The manual did not specify usage of this form.

    --
    Rahul
    Rahul, Apr 7, 2009
    #4
  5. Rahul

    Robert Kern Guest

    Re: what does "execfile" mean within profiler output and why doesit not have a attached line number

    On 2009-04-06 19:09, Rahul wrote:
    > Robert Kern<> wrote in
    > news::
    >
    >> To quickly find your hotspots, start by sorting by 'time' (that would
    >> be displayed as the 'tottime' column in the human-readable output).
    >> That tells you how much time is spent in each function itself,
    >> excluding the time it spends calling out to other functions. For
    >> example, per the docs under "Instant User� Ts Manual" (which you might
    >> want to spend a little more time with):
    >>
    >> p.sort_stats('time').print_stats(10)

    >
    > Thanks Robert. I was executing the profiler on the commandline like so:
    >
    > python -m profile ~/bin/visualize.py *.nc
    >
    > Is there any way to pass further options of the form sort etc. via this
    > invocation. The manual did not specify usage of this form.


    $ python -m profile --help
    Usage: profile.py [-o output_file_path] [-s sort] scriptfile [arg] ...

    Options:
    -h, --help show this help message and exit
    -o OUTFILE, --outfile=OUTFILE
    Save stats to <outfile>
    -s SORT, --sort=SORT Sort order when printing to stdout, based on
    pstats.Stats class

    Additionally, you can run pstats on the outfile for an interactive viewer:

    $ python -m pstats visualize.prof

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
    Robert Kern, Apr 7, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo
    Replies:
    10
    Views:
    1,307
    Matt Humphrey
    Oct 18, 2004
  2. Brian Blais

    execfile error exception line number?

    Brian Blais, Feb 23, 2006, in forum: Python
    Replies:
    1
    Views:
    355
    =?iso-8859-1?B?QW5kcuk=?=
    Feb 24, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,856
    Smokey Grindel
    Dec 2, 2006
  4. TP
    Replies:
    4
    Views:
    298
    Tim Chase
    Nov 4, 2008
  5. potatosoftware
    Replies:
    0
    Views:
    661
    potatosoftware
    Nov 4, 2009
Loading...

Share This Page