Howdy,

On Tue, May 27, 2008 at 5:42 PM, mhampton <[EMAIL PROTECTED]> wrote:
>
> I've made a trac ticket, #3317, to help organize some sort of
> solution(s) to this problem.

Great!

>> Parsing this could be the start of a useful summary of functionality
>> used for a given computation: at least knowing what components were
>> used for the most time consuming parts and the most frequently called
>> functions (not necessarily the same thing, so both are important)
>> would be a decent starting point.

I should clarify what I mean by 'parsing'.  The result of the profile
run is an object with a fair amount of info, and that's the object one
would analyze to summarize this information.  Here's just a brief
summary for reference.  Consider running some trivial code that prints
this:

In [11]: run scopes.py
foo in bar: 1
foo_perm in bar: 1
foo in bar: 2
foo_perm in bar: 1

You then run it with -p, and -r to request the profile object to be
returned (stdout gets a bit messed up by the profiler, but never
mind):

In [12]: run -pr scopes.py
foo in bar: 1
             foo_perm in bar: 1
                               foo in bar: 2
                                            foo_perm in bar: 1
         6 function calls in 0.000 CPU seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 {execfile}
        2    0.000    0.000    0.000    0.000 scopes.py:5(bar)
        1    0.000    0.000    0.000    0.000 scopes.py:3(<module>)
        1    0.000    0.000    0.000    0.000 <string>:1(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of
'_lsprof.Profiler' objects}
Out[12]: <pstats.Stats instance at 0xc21d88>

Now, just capture that profile info object and play with it:

In [13]: prof = _

In [14]: prof.<TAB HERE>
prof.add                    prof.load_stats             prof.sort_arg_dict
prof.all_callees            prof.max_name_len
prof.sort_arg_dict_default
prof.calc_callees           prof.prim_calls             prof.sort_stats
prof.dump_stats             prof.print_call_heading     prof.sort_type
prof.eval_print_amount      prof.print_call_line        prof.stats
prof.fcn_list               prof.print_callees          prof.stream
prof.files                  prof.print_callers          prof.strip_dirs
prof.get_print_list         prof.print_line             prof.top_level
prof.get_sort_arg_defs      prof.print_stats            prof.total_calls
prof.get_top_level_stats    prof.print_title            prof.total_tt
prof.init                   prof.revers

The pstats module

http://docs.python.org/lib/module-profile.html

has a bunch of utilities to manipulate these objects as well.

HTH,

f

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to