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:

Inheritance diagram of 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

UndefinedEvent

class pySPACE.tools.gprof2dot.UndefinedEvent(event)[source]

Bases: exceptions.Exception

Raised when attempting to get an event which is undefined.

Class Components Summary

__str__()
__init__(event)[source]
__str__()[source]
__weakref__

list of weak references to the object (if defined)

Event

class pySPACE.tools.gprof2dot.Event(name, null, aggregator, formatter=<type 'str'>)[source]

Bases: object

Describe 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()
__init__(name, null, aggregator, formatter=<type 'str'>)[source]
__eq__(other)[source]
__hash__()[source]
null()[source]
aggregate(val1, val2)[source]

Aggregate two event values.

format(val)[source]

Format an event value.

__weakref__

list of weak references to the object (if defined)

Object

class pySPACE.tools.gprof2dot.Object(events=None)[source]

Bases: object

Base class for all objects in profile which can store events.

Class Components Summary

__contains__(event)
__eq__(other)
__getitem__(event)
__hash__()
__setitem__(event, value)
__init__(events=None)[source]
__hash__()[source]
__eq__(other)[source]
__contains__(event)[source]
__getitem__(event)[source]
__setitem__(event, value)[source]
__weakref__

list of weak references to the object (if defined)

Call

class pySPACE.tools.gprof2dot.Call(callee_id)[source]

Bases: pySPACE.tools.gprof2dot.Object

A call between functions.

There should be at most one call object for every pair of functions.

__init__(callee_id)[source]

Function

class pySPACE.tools.gprof2dot.Function(id, name, path=None)[source]

Bases: pySPACE.tools.gprof2dot.Object

A function.

Class Components Summary

__repr__()
add_call(call)
get_call(callee_id)
__init__(id, name, path=None)[source]
add_call(call)[source]
get_call(callee_id)[source]
__repr__()[source]

Cycle

class pySPACE.tools.gprof2dot.Cycle[source]

Bases: pySPACE.tools.gprof2dot.Object

A cycle made from recursive function calls.

Class Components Summary

add_function(function)
__init__()[source]
add_function(function)[source]

Profile

class pySPACE.tools.gprof2dot.Profile[source]

Bases: pySPACE.tools.gprof2dot.Object

The 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.
__init__()[source]
add_function(function)[source]
add_cycle(cycle)[source]
validate()[source]

Validate the edges.

find_cycles()[source]

Find cycles using Tarjan’s strongly connected components algorithm.

_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

call_ratios(event)[source]
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

_integrate_function(function, outevent, inevent)[source]
_integrate_call(call, outevent, inevent)[source]
_integrate_cycle(cycle, outevent, inevent)[source]
_rank_cycle_function(cycle, function, rank, ranks)[source]
_call_ratios_cycle(cycle, function, ranks, call_ratios, visited)[source]
_integrate_cycle_function(cycle, function, partial_ratio, partials, ranks, call_ratios, outevent, inevent)[source]
aggregate(event)[source]

Aggregate an event for the whole profile.

ratio(outevent, inevent)[source]
prune(node_thres, edge_thres, restrict_string)[source]

Prune the profile

dump()[source]
_dump_events(events)[source]

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__()
__init__(attrs=None)[source]
__getattr__(name)[source]
__setattr__(name, value)[source]
__str__()[source]
__repr__()[source]

ParseError

class pySPACE.tools.gprof2dot.ParseError(msg, line)[source]

Bases: exceptions.Exception

Raised when parsing to signal mismatches.

Class Components Summary

__str__()
__init__(msg, line)[source]
__str__()[source]
__weakref__

list of weak references to the object (if defined)

Parser

class pySPACE.tools.gprof2dot.Parser[source]

Parser interface.

Class Components Summary

parse()
__init__()[source]
parse()[source]

LineParser

class pySPACE.tools.gprof2dot.LineParser(file)[source]

Bases: pySPACE.tools.gprof2dot.Parser

Base class for parsers that read line-based formats.

Class Components Summary

consume()
eof()
lookahead()
readline()
__init__(file)[source]
readline()[source]
lookahead()[source]
consume()[source]
eof()[source]

XmlToken

class pySPACE.tools.gprof2dot.XmlToken(type, name_or_data, attrs=None, line=None, column=None)[source]
__init__(type, name_or_data, attrs=None, line=None, column=None)[source]
__str__()[source]

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()
__init__(fp, skip_ws=True)[source]
handle_element_start(name, attributes)[source]
handle_element_end(name)[source]
handle_character_data(data)[source]
finish_character_data()[source]
next()[source]
pos()[source]

XmlTokenMismatch

class pySPACE.tools.gprof2dot.XmlTokenMismatch(expected, found)[source]

Bases: exceptions.Exception

__init__(expected, found)[source]
__str__()[source]
__weakref__

list of weak references to the object (if defined)

XmlParser

class pySPACE.tools.gprof2dot.XmlParser(fp)[source]

Bases: pySPACE.tools.gprof2dot.Parser

Base XML document parser.

Class Components Summary

character_data([strip])
consume()
element_end(name)
element_start(name)
match_element_end(name)
match_element_start(name)
__init__(fp)[source]
consume()[source]
match_element_start(name)[source]
match_element_end(name)[source]
element_start(name)[source]
element_end(name)[source]
character_data(strip=True)[source]

GprofParser

class pySPACE.tools.gprof2dot.GprofParser(fp)[source]

Bases: pySPACE.tools.gprof2dot.Parser

Parser for GNU gprof output.

See also

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_re
parse()
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.
__init__(fp)[source]
readline()[source]
_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>
parse_function_entry(lines)[source]
parse_cycle_entry(lines)[source]
parse_cg_entry(lines)[source]
parse_cg()[source]

Parse the call graph.

parse()[source]

CallgrindParser

class pySPACE.tools.gprof2dot.CallgrindParser(infile)[source]

Bases: pySPACE.tools.gprof2dot.LineParser

Parser 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_map
get_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>
__init__(infile)[source]
parse()[source]
parse_part()[source]
parse_header_line()[source]
_detail_keys = set(['part', 'cmd', 'pid', 'thread'])
parse_part_detail()[source]
parse_description()[source]
parse_event_specification()[source]
parse_cost_line_def()[source]
parse_cost_summary()[source]
parse_body_line()[source]
_cost_re = <_sre.SRE_Pattern object>
parse_cost_line(calls=None)[source]
parse_association_spec()[source]
_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'}
parse_position_spec()[source]
parse_empty()[source]
parse_comment()[source]
_key_re = <_sre.SRE_Pattern object>
parse_key(key)[source]
parse_keys(keys)[source]
make_function(module, filename, name)[source]
get_function()[source]
get_callee()[source]
_CallgrindParser__subpos_re = '(0x[0-9a-fA-F]+|\\d+|\\+\\d+|-\\d+|\\*)'

OprofileParser

class pySPACE.tools.gprof2dot.OprofileParser(infile)[source]

Bases: pySPACE.tools.gprof2dot.LineParser

Parser for oprofile callgraph output.

See also: - http://oprofile.sourceforge.net/doc/opreport.html#opreport-callgraph

Class Components Summary

_fields_re
add_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\\)|.+?)'}
__init__(infile)[source]
add_entry(callers, function, callees)[source]
update_subentries_dict(totals, partials)[source]
parse()[source]
parse_header()[source]
parse_entry()[source]
parse_subentries()[source]
parse_subentry()[source]
skip_separator()[source]
match_header()[source]
match_separator()[source]
match_primary()[source]
match_secondary()[source]

HProfParser

class pySPACE.tools.gprof2dot.HProfParser(infile)[source]

Bases: pySPACE.tools.gprof2dot.LineParser

Parser 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_re
trace_re
trace_re = <_sre.SRE_Pattern object>
trace_id_re = <_sre.SRE_Pattern object>
__init__(infile)[source]
parse()[source]
parse_traces()[source]
parse_trace()[source]
parse_samples()[source]

SysprofParser

class pySPACE.tools.gprof2dot.SysprofParser(stream)[source]

Bases: pySPACE.tools.gprof2dot.XmlParser

__init__(stream)[source]
parse()[source]
parse_items(name)[source]
parse_item(name)[source]
parse_values()[source]
parse_value(tag)[source]
build_profile(objects, nodes)[source]

SharkParser

class pySPACE.tools.gprof2dot.SharkParser(infile)[source]

Bases: pySPACE.tools.gprof2dot.LineParser

Parser for MacOSX Shark output.

Author: tom@dbservice.com

Class Components Summary

add_callee(function, callee)
add_entry(function)
parse()
__init__(infile)[source]
add_entry(function)[source]
add_callee(function, callee)[source]
parse()[source]

XPerfParser

class pySPACE.tools.gprof2dot.XPerfParser(stream)[source]

Bases: pySPACE.tools.gprof2dot.Parser

Parser for CSVs generted by XPerf, from Microsoft Windows Performance Tools.

Class Components Summary

get_function(process, symbol)
parse()
parse_header(row)
parse_row(row)
__init__(stream)[source]
parse()[source]
parse_header(row)[source]
parse_row(row)[source]
get_function(process, symbol)[source]

SleepyParser

class pySPACE.tools.gprof2dot.SleepyParser(filename)[source]

Bases: pySPACE.tools.gprof2dot.Parser

Parser for GNU gprof output.

See also: - http://www.codersnotes.com/sleepy/ - http://sleepygraph.sourceforge.net/

Class Components Summary

_symbol_re
parse()
parse_callstacks()
parse_symbols()
__init__(filename)[source]
_symbol_re = <_sre.SRE_Pattern object>
parse_symbols()[source]
parse_callstacks()[source]
parse()[source]

AQtimeTable

class pySPACE.tools.gprof2dot.AQtimeTable(name, fields)[source]
__init__(name, fields)[source]
__len__()[source]
__iter__()[source]
add_row(values, children=())[source]

AQtimeParser

class pySPACE.tools.gprof2dot.AQtimeParser(stream)[source]

Bases: pySPACE.tools.gprof2dot.XmlParser

__init__(stream)[source]
parse()[source]
parse_headers()[source]
parse_table_header()[source]
parse_table_field()[source]
parse_results()[source]
parse_data()[source]
parse_row(field_types)[source]
parse_field(field_types)[source]
parse_children()[source]
build_profile(results)[source]
build_function(fields)[source]
build_call(fields)[source]
build_id(fields)[source]
build_name(fields)[source]

PstatsParser

class pySPACE.tools.gprof2dot.PstatsParser(*filename)[source]

Parse Python profiling statistics saved with te pstats module.

Class Components Summary

get_function(key)
get_function_name
parse()
__init__(*filename)[source]
get_function_name()[source]
get_function(key)[source]
parse()[source]

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]
graph_bgcolor()[source]
graph_fontname()[source]
graph_fontsize()[source]
node_bgcolor(weight)[source]
node_fgcolor(weight)[source]
node_fontsize(weight)[source]
edge_color(weight)[source]
edge_fontsize(weight)[source]
edge_penwidth(weight)[source]
edge_arrowsize(weight)[source]
fontsize(weight)[source]
color(weight)[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

_hue_to_rgb(m1, m2, h)[source]

DotWriter

class pySPACE.tools.gprof2dot.DotWriter(fp)[source]

Writer for the DOT language.

See also

Class Components Summary

attr(what, \*\*attrs)
attr_list(attrs)
begin_graph()
color
edge(src, dst, \*\*attrs)
end_graph()
escape(s)
graph(profile, theme)
id(id)
node(node, \*\*attrs)
write(s)
__init__(fp)[source]
graph(profile, theme)[source]
begin_graph()[source]
end_graph()[source]
attr(what, **attrs)[source]
node(node, **attrs)[source]
edge(src, dst, **attrs)[source]
attr_list(attrs)[source]
id(id)[source]
color()[source]
escape(s)[source]
write(s)[source]

Main

class pySPACE.tools.gprof2dot.Main[source]

Main program.

Class Components Summary

_angles_re
_const_re
_parenthesis_re
compress_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.
themes
wrap_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>}
main()[source]

Main program.

_parenthesis_re = <_sre.SRE_Pattern object>
_angles_re = <_sre.SRE_Pattern object>
_const_re = <_sre.SRE_Pattern object>
strip_function_name(name)[source]

Remove extraneous information from C++ demangled function names.

wrap_function_name(name)[source]

Split the function name on multiple lines.

compress_function_name(name)[source]

Compress function name according to the user preferences.

write_graph()[source]

Functions

times()

pySPACE.tools.gprof2dot.times(x)[source]

percentage()

pySPACE.tools.gprof2dot.percentage(p)[source]

add()

pySPACE.tools.gprof2dot.add(a, b)[source]

equal()

pySPACE.tools.gprof2dot.equal(a, b)[source]

fail()

pySPACE.tools.gprof2dot.fail(a, b)[source]

ratio()

pySPACE.tools.gprof2dot.ratio(numerator, denominator)[source]