PyCharm 2016.3 Help

Profiler

This feature is supported in Professional edition only.

In this section:

Overview

PyCharm allows running the current run/debug configuration while attaching a Python profiler to it.

If you have a yappi profiler installed on your interpreter, PyCharm starts the profiling session with it by default, otherwise it uses the standard cProfile profiler.

Besides these two tracing profilers, PyCharm supports also sampling (statistical) profiler vmprof, which should be installed on the selected Python interpreter.

Note the following:

  • A profiler runs on both local and remote interpreters.
  • A profiler runs in the following order: vmprof, yappi, cProfile.

Starting the profiling session

To start the profiling session, do one of the following:

  • Click /help/img/idea/profiler_icon.png on the main toolbar.
  • Choose Run | Profile <current run.debug configuration name> on the main menu.

The profiler starts in the dedicated tab of the Run tool window.

Working with the profiling results

On the toolbar of the profiler tab, click /help/img/idea/profiler_capture_snapshot.png. This action results in the following:

  • The snapshot is saved to the default location under .PyCharmXX/system/snapshots directory under the user's home. For CProfiler, it is saved as <project name>.pstat file:
    /help/img/idea/profiler_results_saved.png
  • The profiling results open in the <project name>.pstat tab in the editor, which consists of two tabs: Statistics and Call Graph:
    /help/img/idea/profiler_results.png

    For vmprof, it is saved as <project name>.prof file.

Jumping to the source code

To navigate to the source code of a certain function, right-click the corresponding entry on the Statistics tab, and choose Navigate to Source on the context menu:

/help/img/idea/profiler_jump_to_source.png

The source code of the function in question opens in the editor.

Viewing Call Graph

To navigate to the call graph of a certain function, right-click the corresponding entry on the Statistics tab, and choose Show on Call Graph on the context menu.

The Call Graph tab opens with the function un question highlighted:

/help/img/idea/profiler_call_graph.png

To increase the graph scale, click /help/img/idea/erDiagramIconZoomIn.png; to show actual size of the graph, click /help/img/idea/erDiagramIconActualSize.png.

Use the toolbar button /help/img/idea/erDiagramIconFitContent.png to fit contents into the current diagram size.

To decrease the graph scale, use /help/img/idea/erDiagramIconZoomOut.png.

Note the color codes on the Call Graph. The functions marked red consume more time; the fastest functions are green.

/help/img/idea/profiler_current_size.png

Reviewing the existing snapshots

To open an existing snapshot, follow these steps:

  1. On the main menu, choose Tools | Open CProfile snapshot.
  2. In the Select PStat file dialog, choose the desired file with the extension pstat.

    The profiling results open in the <project name>.pstat tab in the editor.

See Also

Last modified: 23 November 2016