gprof2dot


Namegprof2dot JSON
Version 2024.6.6 PyPI version JSON
download
home_pagehttps://github.com/jrfonseca/gprof2dot
SummaryGenerate a dot graph from the output of several profilers.
upload_time2024-06-06 05:48:49
maintainerNone
docs_urlNone
authorJose Fonseca
requires_python>=3.8
licenseLGPL
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # About _gprof2dot_

This is a Python script to convert the output from many profilers into a [dot graph](https://www.graphviz.org/doc/info/lang.html).

It can:

  * read output from:
    * [Linux perf](https://perf.wiki.kernel.org/)
    * [Valgrind's callgrind tool](https://valgrind.org/docs/manual/cl-manual.html)
    * [OProfile](https://oprofile.sourceforge.net/)
    * [Sysprof](http://www.sysprof.com/)
    * [Xperf](https://learn.microsoft.com/en-us/windows-hardware/test/wpt/)
    * [VTune](https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler.html)
    * [Very Sleepy](https://www.codersnotes.com/sleepy/)
    * [Python profilers](https://docs.python.org/3/library/profile.html#profile-stats)
    * [Java's HPROF](https://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html)
    * prof, [gprof](https://sourceware.org/binutils/docs/gprof/)
    * [DTrace](https://en.wikipedia.org/wiki/DTrace)
    * stackcollapse from [FlameGraph](https://github.com/brendangregg/FlameGraph)
  * prune nodes and edges below a certain threshold;
  * use an heuristic to propagate time inside mutually recursive functions;
  * use color efficiently to draw attention to hot-spots;
  * work on any platform where Python and Graphviz is available, i.e, virtually anywhere.

**If you want an interactive viewer for the graphs generated by _gprof2dot_, check [xdot.py](https://github.com/jrfonseca/xdot.py).**


# Status

_gprof2dot_ currently fulfills my needs, and I have little or no time for its
maintenance.  So I'm afraid that any requested features are unlikely to be
implemented, and I might be slow processing issue reports or pull requests.

[![Build Status](https://github.com/jrfonseca/gprof2dot/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/jrfonseca/gprof2dot/actions/workflows/build.yml)
[![codecov](https://codecov.io/gh/jrfonseca/gprof2dot/branch/master/graph/badge.svg?token=pBvnAuazx0)](https://codecov.io/gh/jrfonseca/gprof2dot)


# Example

This is the result from the [example data](https://linuxgazette.net/100/misc/vinayak/overall-profile.txt) in the [Linux Gazette article](https://linuxgazette.net/100/vinayak.html) with the default settings:

![Sample](./sample.svg)

# Requirements

  * [Python](https://www.python.org/download/): known to work with version >=3.8; it will most likely _not_ work with earlier releases.
  * [Graphviz](https://www.graphviz.org/Download.php): tested with version 2.26.3, but should work fine with other versions.

## Windows users

  * Download and install [Python for Windows](https://www.python.org/download/)
  * Download and install [Graphviz for Windows](https://www.graphviz.org/Download_windows.php)

## Linux users

On Debian/Ubuntu run:

    apt-get install python3 graphviz

On RedHat/Fedora run

    yum install python3 graphviz


# Download

  * [PyPI](https://pypi.python.org/pypi/gprof2dot/)

        pip install gprof2dot

  * [Standalone script](https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py)

  * [Git repository](https://github.com/jrfonseca/gprof2dot)


# Documentation

## Usage

```
Usage: 
	gprof2dot.py [options] [file] ...

Options:
  -h, --help            show this help message and exit
  -o FILE, --output=FILE
                        output filename [stdout]
  -n PERCENTAGE, --node-thres=PERCENTAGE
                        eliminate nodes below this threshold [default: 0.5]
  -e PERCENTAGE, --edge-thres=PERCENTAGE
                        eliminate edges below this threshold [default: 0.1]
  -f FORMAT, --format=FORMAT
                        profile format: axe, callgrind, collapse, dtrace,
                        hprof, json, oprofile, perf, prof, pstats, sleepy,
                        sysprof or xperf [default: prof]
  --total=TOTALMETHOD   preferred method of calculating total time: callratios
                        or callstacks (currently affects only perf format)
                        [default: callratios]
  -c THEME, --colormap=THEME
                        color map: bw, color, gray, pink or print [default:
                        color]
  -s, --strip           strip function parameters, template parameters, and
                        const modifiers from demangled C++ function names
  --color-nodes-by-selftime
                        color nodes by self time, rather than by total time
                        (sum of self and descendants)
  -w, --wrap            wrap function names
  --show-samples        show function samples
  --node-label=MEASURE  measurements to on show the node (can be specified
                        multiple times): self-time, self-time-percentage,
                        total-time or total-time-percentage [default: total-
                        time-percentage, self-time-percentage]
  --list-functions=LIST_FUNCTIONS
                        list functions available for selection in -z or -l,
                        requires selector argument ( use '+' to select all).
                        Recall that the selector argument is used with
                        Unix/Bash globbing/pattern matching, and that entries
                        are formatted '<pkg>:<linenum>:<function>'. When
                        argument starts with '%', a dump of all available
                        information is performed for selected entries,  after
                        removal of leading '%'.
  -z ROOT, --root=ROOT  prune call graph to show only descendants of specified
                        root function
  -l LEAF, --leaf=LEAF  prune call graph to show only ancestors of specified
                        leaf function
  --depth=DEPTH         prune call graph to show only descendants or ancestors
                        until specified depth
  --skew=THEME_SKEW     skew the colorization curve.  Values < 1.0 give more
                        variety to lower percentages.  Values > 1.0 give less
                        variety to lower percentages
  -p FILTER_PATHS, --path=FILTER_PATHS
                        Filter all modules not in a specified path
```

## Examples

### Linux perf

    perf record -g -- /path/to/your/executable
    perf script | c++filt | gprof2dot.py -f perf | dot -Tpng -o output.png

### oprofile

    opcontrol --callgraph=16
    opcontrol --start
    /path/to/your/executable arg1 arg2
    opcontrol --stop
    opcontrol --dump
    opreport -cgf | gprof2dot.py -f oprofile | dot -Tpng -o output.png

### xperf

If you're not familiar with xperf then read [this excellent article](https://blogs.msdn.com/b/pigscanfly/archive/2009/08/06/stack-walking-in-xperf.aspx) first. Then do:

  * Start xperf as

        xperf -on Latency -stackwalk profile

  * Run your application.

  * Save the data.
`
        xperf -d output.etl

  * Start the visualizer:

        xperf output.etl

  * In _Trace_ menu, select _Load Symbols_. _Configure Symbol Paths_ if necessary.

  * Select an area of interest on the _CPU sampling graph_, right-click, and select _Summary Table_.

  * In the _Columns_ menu, make sure the _Stack_ column is enabled and visible.

  * Right click on a row, choose _Export Full Table_, and save to _output.csv_.

  * Then invoke gprof2dot as

        gprof2dot.py -f xperf output.csv | dot -Tpng -o output.png

### VTune Amplifier XE

  * Collect profile data as (also can be done from GUI):

        amplxe-cl -collect hotspots -result-dir output -- your-app

  * Visualize profile data as:

        amplxe-cl -report gprof-cc -result-dir output -format text -report-output output.txt
        gprof2dot.py -f axe output.txt | dot -Tpng -o output.png

See also [Kirill Rogozhin's blog post](http://web.archive.org/web/20130506045856/http://software.intel.com:80/en-us/blogs/2013/04/05/making-visualized-call-graph-from-intel-vtune-amplifier-xe-results).

### gprof

    /path/to/your/executable arg1 arg2
    gprof path/to/your/executable | gprof2dot.py | dot -Tpng -o output.png

### python profile

    python -m profile -o output.pstats path/to/your/script arg1 arg2
    gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png

### python cProfile (formerly known as lsprof)

    python -m cProfile -o output.pstats path/to/your/script arg1 arg2
    gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png

### Java HPROF

    java -agentlib:hprof=cpu=samples ...
    gprof2dot.py -f hprof java.hprof.txt | dot -Tpng -o output.png

See [Russell Power's blog post](http://web.archive.org/web/20220122110828/http://rjp.io/2012/07/03/java-profiling/) for details.

### DTrace

    dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks
    gprof2dot.py -f dtrace out.user_stacks | dot -Tpng -o output.png

    # Notice: sometimes, the dtrace outputs format may be latin-1, and gprof2dot will fail to parse it.
    # To solve this problem, you should use iconv to convert to UTF-8 explicitly.
    # TODO: add an encoding flag to tell gprof2dot how to decode the profile file.
    iconv -f ISO-8859-1 -t UTF-8 out.user_stacks | gprof2dot.py -f dtrace

### stackcollapse

Brendan Gregg's FlameGraph tool takes as its input a text file containing one
line per sample. This format can be generated from various other inputs using
the `stackcollapse` scripts in the [FlameGraph
repository](https://github.com/brendangregg/FlameGraph). It can also be
generated by tools such as [py-spy](https://github.com/benfred/py-spy).

Example usage:

  * Perf

        perf record -g -- /path/to/your/executable
        perf script | FlameGraph/stackcollapse-perf.pl > out.collapse
        gprof2dot.py -f collapse out.collapse | dot -Tpng -o output.png

  * Py-spy

        py-spy record -p <pidfile> -f raw -o out.collapse
        gprof2dot.py -f collapse out.collapse | dot -Tpng -o output.png

## Output

A node in the output graph represents a function and has the following layout:

    +------------------------------+
    |        function name         |
    | total time % ( self time % ) |
    |         total calls          |
    +------------------------------+

where:

  * _total time %_ is the percentage of the running time spent in this function and all its children;
  * _self time %_ is the percentage of the running time spent in this function alone;
  * _total calls_ is the total number of times this function was called (including recursive calls).

An edge represents the calls between two functions and has the following layout:

               total time %
                  calls
    parent --------------------> children

Where:

  * _total time %_ is the percentage of the running time transferred from the children to this parent (if available);
  * _calls_ is the number of calls the parent function called the children.

Note that in recursive cycles, the _total time %_ in the node is the same for the whole functions in the cycle, and there is no _total time %_ figure in the edges inside the cycle, since such figure would make no sense.

The color of the nodes and edges varies according to the _total time %_ value. In the default _temperature-like_ color-map, functions where most time is spent (hot-spots) are marked as saturated red, and functions where little time is spent are marked as dark blue. Note that functions where negligible or no time is spent do not appear in the graph by default.

## Listing functions

The flag `--list-functions` permits listing the function entries found in the `gprof` input.
This is intended as a tool to prepare for utilisations with the `--leaf` (`-l`) 
or `--root` (`-z`) flags.

  ~~~
  prof2dot.py -f pstats /tmp/myLog.profile  --list-functions "test_segments:*:*" 
    
  test_segments:5:<module>,
  test_segments:206:TestSegments,
  test_segments:46:<lambda>
  ~~~

  - The selector argument is used with Unix/Bash globbing/pattern matching, in the same
    fashion as performed by the `-l` and `-z` flags.
	  
  - Entries are formatted '\<pkg\>:\<linenum\>:\<function\>'. 
	
  - When selector argument starts with '%', a dump of all available information is 
	performed for selected entries,   after removal of selector's leading '%'. If 
	selector is "+" or "*", the full list of functions is printed.


## Frequently Asked Questions

### How can I generate a complete call graph?

By default `gprof2dot.py` generates a _partial_ call graph, excluding nodes and edges with little or no impact in the total computation time. If you want the full call graph then set a zero threshold for nodes and edges via the `-n` / `--node-thres`  and `-e` / `--edge-thres` options, as:

    gprof2dot.py -n0 -e0

### The node labels are too wide. How can I narrow them?

The node labels can get very wide when profiling C++ code, due to inclusion of scope, function arguments, and template arguments in demangled C++ function names.

If you do not need function and template arguments information, then pass the `-s` / `--strip` option to strip them.

If you want to keep all that information, or if the labels are still too wide, then you can pass the `-w` / `--wrap`, to wrap the labels. Note that because `dot` does not wrap labels automatically the label margins will not be perfectly aligned.

### Why there is no output, or it is all in the same color?

Likely, the total execution time is too short, so there is not enough precision in the profile to determine where time is being spent.

You can still force displaying the whole graph by setting a zero threshold for nodes and edges via the `-n` / `--node-thres`  and `-e` / `--edge-thres` options, as:

    gprof2dot.py -n0 -e0

But to get meaningful results you will need to find a way to run the program for a longer time period (aggregate results from multiple runs).

### Why don't the percentages add up?

You likely have an execution time too short, causing the round-off errors to be large.

See question above for ways to increase execution time.

### Which options should I pass to gcc when compiling for profiling?

Options which are _essential_ to produce suitable results are:

  * **`-g`** : produce debugging information
  * **`-fno-omit-frame-pointer`** : use the frame pointer (frame pointer usage is disabled by default in some architectures like x86\_64 and for some optimization levels; it is impossible to walk the call stack without it)

_If_ you're using gprof you will also need `-pg` option, but nowadays you can get much better results with other profiling tools, most of which require no special code instrumentation when compiling.

You want the code you are profiling to be as close as possible as the code that you will
be releasing. So you _should_ include all options that you use in your release code, typically:

  * **`-O2`** : optimizations that do not involve a space-speed tradeoff
  * **`-DNDEBUG`** : disable debugging code in the standard library (such as the assert macro)

However many of the optimizations performed by gcc interfere with the accuracy/granularity of the profiling results.  You _should_ pass these options to disable those particular optimizations:

  * **`-fno-inline-functions`** : do not inline functions into their parents (otherwise the time spent on these functions will be attributed to the caller)
  * **`-fno-inline-functions-called-once`** : similar to above
  * **`-fno-optimize-sibling-calls`** : do not optimize sibling and tail recursive calls (otherwise tail calls may be attributed to the parent function)

If the granularity is still too low, you _may_ pass these options to achieve finer granularity:

  * **`-fno-default-inline`** : do not make member functions inline by default merely because they are defined inside the class scope
  * **`-fno-inline`** : do not pay attention to the inline keyword
Note however that with these last options the timings of functions called many times will be distorted due to the function call overhead. This is particularly true for typical C++ code which _expects_ that these optimizations to be done for decent performance.

See the [full list of gcc optimization options](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html) for more information.

# Links

See the [wiki](https://github.com/jrfonseca/gprof2dot/wiki) for external resources, including complementary/alternative tools.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jrfonseca/gprof2dot",
    "name": "gprof2dot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jose Fonseca",
    "author_email": "jose.r.fonseca@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/32/11/16fc5b985741378812223f2c6213b0a95cda333b797def622ac702d28e81/gprof2dot-2024.6.6.tar.gz",
    "platform": null,
    "description": "# About _gprof2dot_\n\nThis is a Python script to convert the output from many profilers into a [dot graph](https://www.graphviz.org/doc/info/lang.html).\n\nIt can:\n\n  * read output from:\n    * [Linux perf](https://perf.wiki.kernel.org/)\n    * [Valgrind's callgrind tool](https://valgrind.org/docs/manual/cl-manual.html)\n    * [OProfile](https://oprofile.sourceforge.net/)\n    * [Sysprof](http://www.sysprof.com/)\n    * [Xperf](https://learn.microsoft.com/en-us/windows-hardware/test/wpt/)\n    * [VTune](https://www.intel.com/content/www/us/en/developer/tools/oneapi/vtune-profiler.html)\n    * [Very Sleepy](https://www.codersnotes.com/sleepy/)\n    * [Python profilers](https://docs.python.org/3/library/profile.html#profile-stats)\n    * [Java's HPROF](https://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html)\n    * prof, [gprof](https://sourceware.org/binutils/docs/gprof/)\n    * [DTrace](https://en.wikipedia.org/wiki/DTrace)\n    * stackcollapse from [FlameGraph](https://github.com/brendangregg/FlameGraph)\n  * prune nodes and edges below a certain threshold;\n  * use an heuristic to propagate time inside mutually recursive functions;\n  * use color efficiently to draw attention to hot-spots;\n  * work on any platform where Python and Graphviz is available, i.e, virtually anywhere.\n\n**If you want an interactive viewer for the graphs generated by _gprof2dot_, check [xdot.py](https://github.com/jrfonseca/xdot.py).**\n\n\n# Status\n\n_gprof2dot_ currently fulfills my needs, and I have little or no time for its\nmaintenance.  So I'm afraid that any requested features are unlikely to be\nimplemented, and I might be slow processing issue reports or pull requests.\n\n[![Build Status](https://github.com/jrfonseca/gprof2dot/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/jrfonseca/gprof2dot/actions/workflows/build.yml)\n[![codecov](https://codecov.io/gh/jrfonseca/gprof2dot/branch/master/graph/badge.svg?token=pBvnAuazx0)](https://codecov.io/gh/jrfonseca/gprof2dot)\n\n\n# Example\n\nThis is the result from the [example data](https://linuxgazette.net/100/misc/vinayak/overall-profile.txt) in the [Linux Gazette article](https://linuxgazette.net/100/vinayak.html) with the default settings:\n\n![Sample](./sample.svg)\n\n# Requirements\n\n  * [Python](https://www.python.org/download/): known to work with version >=3.8; it will most likely _not_ work with earlier releases.\n  * [Graphviz](https://www.graphviz.org/Download.php): tested with version 2.26.3, but should work fine with other versions.\n\n## Windows users\n\n  * Download and install [Python for Windows](https://www.python.org/download/)\n  * Download and install [Graphviz for Windows](https://www.graphviz.org/Download_windows.php)\n\n## Linux users\n\nOn Debian/Ubuntu run:\n\n    apt-get install python3 graphviz\n\nOn RedHat/Fedora run\n\n    yum install python3 graphviz\n\n\n# Download\n\n  * [PyPI](https://pypi.python.org/pypi/gprof2dot/)\n\n        pip install gprof2dot\n\n  * [Standalone script](https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py)\n\n  * [Git repository](https://github.com/jrfonseca/gprof2dot)\n\n\n# Documentation\n\n## Usage\n\n```\nUsage: \n\tgprof2dot.py [options] [file] ...\n\nOptions:\n  -h, --help            show this help message and exit\n  -o FILE, --output=FILE\n                        output filename [stdout]\n  -n PERCENTAGE, --node-thres=PERCENTAGE\n                        eliminate nodes below this threshold [default: 0.5]\n  -e PERCENTAGE, --edge-thres=PERCENTAGE\n                        eliminate edges below this threshold [default: 0.1]\n  -f FORMAT, --format=FORMAT\n                        profile format: axe, callgrind, collapse, dtrace,\n                        hprof, json, oprofile, perf, prof, pstats, sleepy,\n                        sysprof or xperf [default: prof]\n  --total=TOTALMETHOD   preferred method of calculating total time: callratios\n                        or callstacks (currently affects only perf format)\n                        [default: callratios]\n  -c THEME, --colormap=THEME\n                        color map: bw, color, gray, pink or print [default:\n                        color]\n  -s, --strip           strip function parameters, template parameters, and\n                        const modifiers from demangled C++ function names\n  --color-nodes-by-selftime\n                        color nodes by self time, rather than by total time\n                        (sum of self and descendants)\n  -w, --wrap            wrap function names\n  --show-samples        show function samples\n  --node-label=MEASURE  measurements to on show the node (can be specified\n                        multiple times): self-time, self-time-percentage,\n                        total-time or total-time-percentage [default: total-\n                        time-percentage, self-time-percentage]\n  --list-functions=LIST_FUNCTIONS\n                        list functions available for selection in -z or -l,\n                        requires selector argument ( use '+' to select all).\n                        Recall that the selector argument is used with\n                        Unix/Bash globbing/pattern matching, and that entries\n                        are formatted '<pkg>:<linenum>:<function>'. When\n                        argument starts with '%', a dump of all available\n                        information is performed for selected entries,  after\n                        removal of leading '%'.\n  -z ROOT, --root=ROOT  prune call graph to show only descendants of specified\n                        root function\n  -l LEAF, --leaf=LEAF  prune call graph to show only ancestors of specified\n                        leaf function\n  --depth=DEPTH         prune call graph to show only descendants or ancestors\n                        until specified depth\n  --skew=THEME_SKEW     skew the colorization curve.  Values < 1.0 give more\n                        variety to lower percentages.  Values > 1.0 give less\n                        variety to lower percentages\n  -p FILTER_PATHS, --path=FILTER_PATHS\n                        Filter all modules not in a specified path\n```\n\n## Examples\n\n### Linux perf\n\n    perf record -g -- /path/to/your/executable\n    perf script | c++filt | gprof2dot.py -f perf | dot -Tpng -o output.png\n\n### oprofile\n\n    opcontrol --callgraph=16\n    opcontrol --start\n    /path/to/your/executable arg1 arg2\n    opcontrol --stop\n    opcontrol --dump\n    opreport -cgf | gprof2dot.py -f oprofile | dot -Tpng -o output.png\n\n### xperf\n\nIf you're not familiar with xperf then read [this excellent article](https://blogs.msdn.com/b/pigscanfly/archive/2009/08/06/stack-walking-in-xperf.aspx) first. Then do:\n\n  * Start xperf as\n\n        xperf -on Latency -stackwalk profile\n\n  * Run your application.\n\n  * Save the data.\n`\n        xperf -d output.etl\n\n  * Start the visualizer:\n\n        xperf output.etl\n\n  * In _Trace_ menu, select _Load Symbols_. _Configure Symbol Paths_ if necessary.\n\n  * Select an area of interest on the _CPU sampling graph_, right-click, and select _Summary Table_.\n\n  * In the _Columns_ menu, make sure the _Stack_ column is enabled and visible.\n\n  * Right click on a row, choose _Export Full Table_, and save to _output.csv_.\n\n  * Then invoke gprof2dot as\n\n        gprof2dot.py -f xperf output.csv | dot -Tpng -o output.png\n\n### VTune Amplifier XE\n\n  * Collect profile data as (also can be done from GUI):\n\n        amplxe-cl -collect hotspots -result-dir output -- your-app\n\n  * Visualize profile data as:\n\n        amplxe-cl -report gprof-cc -result-dir output -format text -report-output output.txt\n        gprof2dot.py -f axe output.txt | dot -Tpng -o output.png\n\nSee also [Kirill Rogozhin's blog post](http://web.archive.org/web/20130506045856/http://software.intel.com:80/en-us/blogs/2013/04/05/making-visualized-call-graph-from-intel-vtune-amplifier-xe-results).\n\n### gprof\n\n    /path/to/your/executable arg1 arg2\n    gprof path/to/your/executable | gprof2dot.py | dot -Tpng -o output.png\n\n### python profile\n\n    python -m profile -o output.pstats path/to/your/script arg1 arg2\n    gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png\n\n### python cProfile (formerly known as lsprof)\n\n    python -m cProfile -o output.pstats path/to/your/script arg1 arg2\n    gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png\n\n### Java HPROF\n\n    java -agentlib:hprof=cpu=samples ...\n    gprof2dot.py -f hprof java.hprof.txt | dot -Tpng -o output.png\n\nSee [Russell Power's blog post](http://web.archive.org/web/20220122110828/http://rjp.io/2012/07/03/java-profiling/) for details.\n\n### DTrace\n\n    dtrace -x ustackframes=100 -n 'profile-97 /pid == 12345/ { @[ustack()] = count(); } tick-60s { exit(0); }' -o out.user_stacks\n    gprof2dot.py -f dtrace out.user_stacks | dot -Tpng -o output.png\n\n    # Notice: sometimes, the dtrace outputs format may be latin-1, and gprof2dot will fail to parse it.\n    # To solve this problem, you should use iconv to convert to UTF-8 explicitly.\n    # TODO: add an encoding flag to tell gprof2dot how to decode the profile file.\n    iconv -f ISO-8859-1 -t UTF-8 out.user_stacks | gprof2dot.py -f dtrace\n\n### stackcollapse\n\nBrendan Gregg's FlameGraph tool takes as its input a text file containing one\nline per sample. This format can be generated from various other inputs using\nthe `stackcollapse` scripts in the [FlameGraph\nrepository](https://github.com/brendangregg/FlameGraph). It can also be\ngenerated by tools such as [py-spy](https://github.com/benfred/py-spy).\n\nExample usage:\n\n  * Perf\n\n        perf record -g -- /path/to/your/executable\n        perf script | FlameGraph/stackcollapse-perf.pl > out.collapse\n        gprof2dot.py -f collapse out.collapse | dot -Tpng -o output.png\n\n  * Py-spy\n\n        py-spy record -p <pidfile> -f raw -o out.collapse\n        gprof2dot.py -f collapse out.collapse | dot -Tpng -o output.png\n\n## Output\n\nA node in the output graph represents a function and has the following layout:\n\n    +------------------------------+\n    |        function name         |\n    | total time % ( self time % ) |\n    |         total calls          |\n    +------------------------------+\n\nwhere:\n\n  * _total time %_ is the percentage of the running time spent in this function and all its children;\n  * _self time %_ is the percentage of the running time spent in this function alone;\n  * _total calls_ is the total number of times this function was called (including recursive calls).\n\nAn edge represents the calls between two functions and has the following layout:\n\n               total time %\n                  calls\n    parent --------------------> children\n\nWhere:\n\n  * _total time %_ is the percentage of the running time transferred from the children to this parent (if available);\n  * _calls_ is the number of calls the parent function called the children.\n\nNote that in recursive cycles, the _total time %_ in the node is the same for the whole functions in the cycle, and there is no _total time %_ figure in the edges inside the cycle, since such figure would make no sense.\n\nThe color of the nodes and edges varies according to the _total time %_ value. In the default _temperature-like_ color-map, functions where most time is spent (hot-spots) are marked as saturated red, and functions where little time is spent are marked as dark blue. Note that functions where negligible or no time is spent do not appear in the graph by default.\n\n## Listing functions\n\nThe flag `--list-functions` permits listing the function entries found in the `gprof` input.\nThis is intended as a tool to prepare for utilisations with the `--leaf` (`-l`) \nor `--root` (`-z`) flags.\n\n  ~~~\n  prof2dot.py -f pstats /tmp/myLog.profile  --list-functions \"test_segments:*:*\" \n    \n  test_segments:5:<module>,\n  test_segments:206:TestSegments,\n  test_segments:46:<lambda>\n  ~~~\n\n  - The selector argument is used with Unix/Bash globbing/pattern matching, in the same\n    fashion as performed by the `-l` and `-z` flags.\n\t  \n  - Entries are formatted '\\<pkg\\>:\\<linenum\\>:\\<function\\>'. \n\t\n  - When selector argument starts with '%', a dump of all available information is \n\tperformed for selected entries,   after removal of selector's leading '%'. If \n\tselector is \"+\" or \"*\", the full list of functions is printed.\n\n\n## Frequently Asked Questions\n\n### How can I generate a complete call graph?\n\nBy default `gprof2dot.py` generates a _partial_ call graph, excluding nodes and edges with little or no impact in the total computation time. If you want the full call graph then set a zero threshold for nodes and edges via the `-n` / `--node-thres`  and `-e` / `--edge-thres` options, as:\n\n    gprof2dot.py -n0 -e0\n\n### The node labels are too wide. How can I narrow them?\n\nThe node labels can get very wide when profiling C++ code, due to inclusion of scope, function arguments, and template arguments in demangled C++ function names.\n\nIf you do not need function and template arguments information, then pass the `-s` / `--strip` option to strip them.\n\nIf you want to keep all that information, or if the labels are still too wide, then you can pass the `-w` / `--wrap`, to wrap the labels. Note that because `dot` does not wrap labels automatically the label margins will not be perfectly aligned.\n\n### Why there is no output, or it is all in the same color?\n\nLikely, the total execution time is too short, so there is not enough precision in the profile to determine where time is being spent.\n\nYou can still force displaying the whole graph by setting a zero threshold for nodes and edges via the `-n` / `--node-thres`  and `-e` / `--edge-thres` options, as:\n\n    gprof2dot.py -n0 -e0\n\nBut to get meaningful results you will need to find a way to run the program for a longer time period (aggregate results from multiple runs).\n\n### Why don't the percentages add up?\n\nYou likely have an execution time too short, causing the round-off errors to be large.\n\nSee question above for ways to increase execution time.\n\n### Which options should I pass to gcc when compiling for profiling?\n\nOptions which are _essential_ to produce suitable results are:\n\n  * **`-g`** : produce debugging information\n  * **`-fno-omit-frame-pointer`** : use the frame pointer (frame pointer usage is disabled by default in some architectures like x86\\_64 and for some optimization levels; it is impossible to walk the call stack without it)\n\n_If_ you're using gprof you will also need `-pg` option, but nowadays you can get much better results with other profiling tools, most of which require no special code instrumentation when compiling.\n\nYou want the code you are profiling to be as close as possible as the code that you will\nbe releasing. So you _should_ include all options that you use in your release code, typically:\n\n  * **`-O2`** : optimizations that do not involve a space-speed tradeoff\n  * **`-DNDEBUG`** : disable debugging code in the standard library (such as the assert macro)\n\nHowever many of the optimizations performed by gcc interfere with the accuracy/granularity of the profiling results.  You _should_ pass these options to disable those particular optimizations:\n\n  * **`-fno-inline-functions`** : do not inline functions into their parents (otherwise the time spent on these functions will be attributed to the caller)\n  * **`-fno-inline-functions-called-once`** : similar to above\n  * **`-fno-optimize-sibling-calls`** : do not optimize sibling and tail recursive calls (otherwise tail calls may be attributed to the parent function)\n\nIf the granularity is still too low, you _may_ pass these options to achieve finer granularity:\n\n  * **`-fno-default-inline`** : do not make member functions inline by default merely because they are defined inside the class scope\n  * **`-fno-inline`** : do not pay attention to the inline keyword\nNote however that with these last options the timings of functions called many times will be distorted due to the function call overhead. This is particularly true for typical C++ code which _expects_ that these optimizations to be done for decent performance.\n\nSee the [full list of gcc optimization options](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html) for more information.\n\n# Links\n\nSee the [wiki](https://github.com/jrfonseca/gprof2dot/wiki) for external resources, including complementary/alternative tools.\n",
    "bugtrack_url": null,
    "license": "LGPL",
    "summary": "Generate a dot graph from the output of several profilers.",
    "version": "2024.6.6",
    "project_urls": {
        "Homepage": "https://github.com/jrfonseca/gprof2dot"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae2715c4d20871a86281e2bacde9e9f634225d1c2ed0db072f98acf201022411",
                "md5": "01334bff99279568e2c7a2bfc8017767",
                "sha256": "45b14ad7ce64e299c8f526881007b9eb2c6b75505d5613e96e66ee4d5ab33696"
            },
            "downloads": -1,
            "filename": "gprof2dot-2024.6.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01334bff99279568e2c7a2bfc8017767",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 34763,
            "upload_time": "2024-06-06T05:48:47",
            "upload_time_iso_8601": "2024-06-06T05:48:47.774816Z",
            "url": "https://files.pythonhosted.org/packages/ae/27/15c4d20871a86281e2bacde9e9f634225d1c2ed0db072f98acf201022411/gprof2dot-2024.6.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "321116fc5b985741378812223f2c6213b0a95cda333b797def622ac702d28e81",
                "md5": "7a29a3c2c9515fc83a697c3a0847ebaf",
                "sha256": "fa1420c60025a9eb7734f65225b4da02a10fc6dd741b37fa129bc6b41951e5ab"
            },
            "downloads": -1,
            "filename": "gprof2dot-2024.6.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7a29a3c2c9515fc83a697c3a0847ebaf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 36536,
            "upload_time": "2024-06-06T05:48:49",
            "upload_time_iso_8601": "2024-06-06T05:48:49.019512Z",
            "url": "https://files.pythonhosted.org/packages/32/11/16fc5b985741378812223f2c6213b0a95cda333b797def622ac702d28e81/gprof2dot-2024.6.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-06 05:48:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jrfonseca",
    "github_project": "gprof2dot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gprof2dot"
}
        
Elapsed time: 0.89574s