gprof2dot¶
Module: tools.gprof2dot¶
Generate a dot graph from the output of several profilers.
Original script by Jose Fonseca at http://code.google.com/p/jrfonseca/wiki/Gprof2Dot
Usage: python gprof2dot.py -f pstats profiling_file -r pySPACE | dot -Tpng -o output.png
where profiling_file is the file that is generated by the cProfile module.
The option ‘-r’, ‘–restrict’ is there to eliminate functions in the profiling, that do not contain this string in their pathname [default: None]. This option was added by Hendrik Woehrle and Mario Michael Krell. Furthermore some minor documentation changes were applied.
For profiling pySPACE look at the documentation of pySPACE, especially launch.py and use the –profile option.
Original LGPL 3+ licencing text:
Copyright 2008-2009 Jose Fonseca
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Inheritance diagram for pySPACE.tools.gprof2dot:
Class Summary¶
UndefinedEvent(event) |
Raised when attempting to get an event which is undefined. |
Event(name, null, aggregator[, formatter]) |
Describe a kind of event, and its basic operations. |
Object([events]) |
Base class for all objects in profile which can store events. |
Call(callee_id) |
A call between functions. |
Function(id, name[, path]) |
A function. |
Cycle() |
A cycle made from recursive function calls. |
Profile() |
The whole profile. |
Struct([attrs]) |
Masquerade a dictionary with a structure-like behavior. |
ParseError(msg, line) |
Raised when parsing to signal mismatches. |
Parser() |
Parser interface. |
LineParser(file) |
Base class for parsers that read line-based formats. |
XmlToken(type, name_or_data[, attrs, line, ...]) |
|
XmlTokenizer(fp[, skip_ws]) |
Expat based XML tokenizer. |
XmlTokenMismatch(expected, found) |
|
XmlParser(fp) |
Base XML document parser. |
GprofParser(fp) |
Parser for GNU gprof output. |
CallgrindParser(infile) |
Parser for valgrind’s callgrind tool. |
OprofileParser(infile) |
Parser for oprofile callgraph output. |
HProfParser(infile) |
Parser for java hprof output |
SysprofParser(stream) |
|
SharkParser(infile) |
Parser for MacOSX Shark output. |
XPerfParser(stream) |
Parser for CSVs generted by XPerf, from Microsoft Windows Performance Tools. |
SleepyParser(filename) |
Parser for GNU gprof output. |
AQtimeTable(name, fields) |
|
AQtimeParser(stream) |
|
PstatsParser(\*filename) |
Parse Python profiling statistics saved with te pstats module. |
Theme([bgcolor, mincolor, maxcolor, ...]) |
|
DotWriter(fp) |
Writer for the DOT language. |
Main |
Main program. |
Function Summary¶
times(x) |
|
percentage(p) |
|
add(a, b) |
|
equal(a, b) |
|
fail(a, b) |
|
ratio(numerator, denominator) |
Classes¶
Event¶
-
class
pySPACE.tools.gprof2dot.Event(name, null, aggregator, formatter=<type 'str'>)[source]¶ Bases:
objectDescribe a kind of event, and its basic operations.
Class Components Summary
__eq__(other)__hash__()aggregate(val1, val2)Aggregate two event values. format(val)Format an event value. null()-
__weakref__¶ list of weak references to the object (if defined)
-
Object¶
-
class
pySPACE.tools.gprof2dot.Object(events=None)[source]¶ Bases:
objectBase class for all objects in profile which can store events.
Class Components Summary
__contains__(event)__eq__(other)__getitem__(event)__hash__()__setitem__(event, value)-
__weakref__¶ list of weak references to the object (if defined)
-
Call¶
-
class
pySPACE.tools.gprof2dot.Call(callee_id)[source]¶ Bases:
pySPACE.tools.gprof2dot.ObjectA call between functions.
There should be at most one call object for every pair of functions.
Function¶
Cycle¶
-
class
pySPACE.tools.gprof2dot.Cycle[source]¶ Bases:
pySPACE.tools.gprof2dot.ObjectA cycle made from recursive function calls.
Class Components Summary
add_function(function)
Profile¶
-
class
pySPACE.tools.gprof2dot.Profile[source]¶ Bases:
pySPACE.tools.gprof2dot.ObjectThe whole profile.
Class Components Summary
_call_ratios_cycle(cycle, function, ranks, ...)_dump_events(events)_integrate_call(call, outevent, inevent)_integrate_cycle(cycle, outevent, inevent)_integrate_cycle_function(cycle, function, ...)_integrate_function(function, outevent, inevent)_rank_cycle_function(cycle, function, rank, ...)_tarjan(function, order, stack, orders, ...)Tarjan’s strongly connected components algorithm. add_cycle(cycle)add_function(function)aggregate(event)Aggregate an event for the whole profile. call_ratios(event)dump()find_cycles()Find cycles using Tarjan’s strongly connected components algorithm. integrate(outevent, inevent)Propagate function time ratio allong the function calls. prune(node_thres, edge_thres, restrict_string)Prune the profile ratio(outevent, inevent)validate()Validate the edges. -
_tarjan(function, order, stack, orders, lowlinks, visited)[source]¶ Tarjan’s strongly connected components algorithm.
See also: - http://en.wikipedia.org/wiki/Tarjan’s_strongly_connected_components_algorithm
-
integrate(outevent, inevent)[source]¶ Propagate function time ratio allong the function calls.
Must be called after finding the cycles.
See also: - http://citeseer.ist.psu.edu/graham82gprof.html
-
Struct¶
-
class
pySPACE.tools.gprof2dot.Struct(attrs=None)[source]¶ Masquerade a dictionary with a structure-like behavior.
Class Components Summary
__getattr__(name)__repr__()__setattr__(name, value)__str__()
LineParser¶
XmlTokenizer¶
-
class
pySPACE.tools.gprof2dot.XmlTokenizer(fp, skip_ws=True)[source]¶ Expat based XML tokenizer.
Class Components Summary
finish_character_data()handle_character_data(data)handle_element_end(name)handle_element_start(name, attributes)next()pos()
XmlParser¶
-
class
pySPACE.tools.gprof2dot.XmlParser(fp)[source]¶ Bases:
pySPACE.tools.gprof2dot.ParserBase XML document parser.
Class Components Summary
character_data([strip])consume()element_end(name)element_start(name)match_element_end(name)match_element_start(name)
GprofParser¶
-
class
pySPACE.tools.gprof2dot.GprofParser(fp)[source]¶ Bases:
pySPACE.tools.gprof2dot.ParserParser for GNU gprof output.
See also
- Chapter “Interpreting gprof’s Output” from the GNU gprof manual http://sourceware.org/binutils/docs-2.18/gprof/Call-Graph.html#Call-Graph
- File “cg_print.c” from the GNU gprof source code http://sourceware.org/cgi-bin/cvsweb.cgi/~checkout~/src/gprof/cg_print.c?rev=1.12&cvsroot=src
Class Components Summary
_cg_child_re_cg_cycle_header_re_cg_cycle_member_re_cg_header_re_cg_ignore_re_cg_parent_re_cg_primary_re_cg_sep_re_float_re_int_reparse()parse_cg()Parse the call graph. parse_cg_entry(lines)parse_cycle_entry(lines)parse_function_entry(lines)readline()translate(mo)Extract a structure from a match object, while translating the types in the process. -
_int_re= <_sre.SRE_Pattern object>¶
-
_float_re= <_sre.SRE_Pattern object>¶
-
translate(mo)[source]¶ Extract a structure from a match object, while translating the types in the process.
-
_cg_header_re= <_sre.SRE_Pattern object>¶
-
_cg_ignore_re= <_sre.SRE_Pattern object>¶
-
_cg_primary_re= <_sre.SRE_Pattern object>¶
-
_cg_parent_re= <_sre.SRE_Pattern object>¶
-
_cg_child_re= <_sre.SRE_Pattern object>¶
-
_cg_cycle_header_re= <_sre.SRE_Pattern object>¶
-
_cg_cycle_member_re= <_sre.SRE_Pattern object>¶
-
_cg_sep_re= <_sre.SRE_Pattern object>¶
CallgrindParser¶
-
class
pySPACE.tools.gprof2dot.CallgrindParser(infile)[source]¶ Bases:
pySPACE.tools.gprof2dot.LineParserParser for valgrind’s callgrind tool.
See also: - http://valgrind.org/docs/manual/cl-format.html
Class Components Summary
_CallgrindParser__subpos_re_call_re_cost_re_detail_keys_key_re_position_map_position_re_position_table_mapget_callee()get_function()make_function(module, filename, name)parse()parse_association_spec()parse_body_line()parse_comment()parse_cost_line([calls])parse_cost_line_def()parse_cost_summary()parse_description()parse_empty()parse_event_specification()parse_header_line()parse_key(key)parse_keys(keys)parse_part()parse_part_detail()parse_position_spec()-
_call_re= <_sre.SRE_Pattern object>¶
-
_detail_keys= set(['part', 'cmd', 'pid', 'thread'])¶
-
_cost_re= <_sre.SRE_Pattern object>¶
-
_position_re= <_sre.SRE_Pattern object>¶
-
_position_table_map= {'cfn': 'fn', 'cfl': 'fl', 'cfi': 'fl', 'cfe': 'fl', 'fe': 'fl', 'fi': 'fl', 'fl': 'fl', 'fn': 'fn', 'jfi': 'fl', 'ob': 'ob', 'cob': 'ob'}¶
-
_position_map= {'cfn': 'cfn', 'cfl': 'cfl', 'cfi': 'cfl', 'cfe': 'cfl', 'fe': 'fl', 'fi': 'fl', 'fl': 'fl', 'fn': 'fn', 'jfi': 'jfi', 'ob': 'ob', 'cob': 'cob'}¶
-
_key_re= <_sre.SRE_Pattern object>¶
-
_CallgrindParser__subpos_re= '(0x[0-9a-fA-F]+|\\d+|\\+\\d+|-\\d+|\\*)'¶
-
OprofileParser¶
-
class
pySPACE.tools.gprof2dot.OprofileParser(infile)[source]¶ Bases:
pySPACE.tools.gprof2dot.LineParserParser for oprofile callgraph output.
See also: - http://oprofile.sourceforge.net/doc/opreport.html#opreport-callgraph
Class Components Summary
_fields_readd_entry(callers, function, callees)match_header()match_primary()match_secondary()match_separator()parse()parse_entry()parse_header()parse_subentries()parse_subentry()skip_separator()update_subentries_dict(totals, partials)-
_fields_re= {'%': '(\\S+)', 'image name': '(?P<image>\\S+(?:\\s\\(tgid:[^)]*\\))?)', 'app name': '(?P<application>\\S+)', 'linenr info': '(?P<source>\\(no location information\\)|\\S+:\\d+)', 'samples': '(\\d+)', 'symbol name': '(?P<symbol>\\(no symbols\\)|.+?)'}¶
-
HProfParser¶
-
class
pySPACE.tools.gprof2dot.HProfParser(infile)[source]¶ Bases:
pySPACE.tools.gprof2dot.LineParserParser for java hprof output
See also: - http://java.sun.com/developer/technicalArticles/Programming/HPROF.html
Class Components Summary
parse()parse_samples()parse_trace()parse_traces()trace_id_retrace_re-
trace_re= <_sre.SRE_Pattern object>¶
-
trace_id_re= <_sre.SRE_Pattern object>¶
-
SharkParser¶
-
class
pySPACE.tools.gprof2dot.SharkParser(infile)[source]¶ Bases:
pySPACE.tools.gprof2dot.LineParserParser for MacOSX Shark output.
Author: tom@dbservice.com
Class Components Summary
add_callee(function, callee)add_entry(function)parse()
XPerfParser¶
-
class
pySPACE.tools.gprof2dot.XPerfParser(stream)[source]¶ Bases:
pySPACE.tools.gprof2dot.ParserParser for CSVs generted by XPerf, from Microsoft Windows Performance Tools.
Class Components Summary
get_function(process, symbol)parse()parse_header(row)parse_row(row)
SleepyParser¶
-
class
pySPACE.tools.gprof2dot.SleepyParser(filename)[source]¶ Bases:
pySPACE.tools.gprof2dot.ParserParser for GNU gprof output.
See also: - http://www.codersnotes.com/sleepy/ - http://sleepygraph.sourceforge.net/
Class Components Summary
_symbol_reparse()parse_callstacks()parse_symbols()-
_symbol_re= <_sre.SRE_Pattern object>¶
-
AQtimeParser¶
Theme¶
-
class
pySPACE.tools.gprof2dot.Theme(bgcolor=(0.0, 0.0, 1.0), mincolor=(0.0, 0.0, 0.0), maxcolor=(0.0, 0.0, 1.0), fontname='Arial', minfontsize=10.0, maxfontsize=10.0, minpenwidth=0.5, maxpenwidth=4.0, gamma=2.2, skew=1.0)[source]¶ -
__init__(bgcolor=(0.0, 0.0, 1.0), mincolor=(0.0, 0.0, 0.0), maxcolor=(0.0, 0.0, 1.0), fontname='Arial', minfontsize=10.0, maxfontsize=10.0, minpenwidth=0.5, maxpenwidth=4.0, gamma=2.2, skew=1.0)[source]¶
-
hsl_to_rgb(h, s, l)[source]¶ Convert a color from HSL color-model to RGB.
See also: - http://www.w3.org/TR/css3-color/#hsl-color
-
DotWriter¶
-
class
pySPACE.tools.gprof2dot.DotWriter(fp)[source]¶ Writer for the DOT language.
See also
- “The DOT Language” specification http://www.graphviz.org/doc/info/lang.html
Class Components Summary
attr(what, \*\*attrs)attr_list(attrs)begin_graph()coloredge(src, dst, \*\*attrs)end_graph()escape(s)graph(profile, theme)id(id)node(node, \*\*attrs)write(s)
Main¶
-
class
pySPACE.tools.gprof2dot.Main[source]¶ Main program.
Class Components Summary
_angles_re_const_re_parenthesis_recompress_function_name(name)Compress function name according to the user preferences. main()Main program. strip_function_name(name)Remove extraneous information from C++ demangled function names. themeswrap_function_name(name)Split the function name on multiple lines. write_graph()-
themes= {'color': <pySPACE.tools.gprof2dot.Theme instance>, 'pink': <pySPACE.tools.gprof2dot.Theme instance>, 'bw': <pySPACE.tools.gprof2dot.Theme instance>, 'gray': <pySPACE.tools.gprof2dot.Theme instance>}¶
-
_parenthesis_re= <_sre.SRE_Pattern object>¶
-
_angles_re= <_sre.SRE_Pattern object>¶
-
_const_re= <_sre.SRE_Pattern object>¶
-