RubyMine 2019.1 Help

Profiling applications

RubyMine provides the ability to profile running Ruby/Rails processes using the rbspy sampling profiler. The profiler collects information about the execution of your application. You can run Ruby/Rails applications with the attached profiler, or you can attach the profiler to the already running processes. After you stop the profiling session, you can analyze how much time is spent on each method/block and determine performance issues.

In this topic, we’ll show you how to run/stop the profiling session and analyze results.

Prerequisites

Before starting a profiling session, install the rbspy profiler for your platform using this instruction: Installing rbspy. After that, you will be able to profile applications with local Ruby MRI interpreters from the 1.9.1 and higher versions. If your version is not supported, create an issue in the rbspy Github repository: https://github.com/rbspy/rbspy/issues.

Configure profiling settings

Before running the profiling session, you can adjust the profiler settings. Open the Settings/Preferences dialog and go to Build, Execution, Deployment | Ruby Profiler. Here you can specify the following options:

  • Name - specify the profiler name.

  • RbSpy executable - specify the path to the rbspy executable.

  • Profile rate - set how many samples per seconds are recorded.

  • Profile subprocesses - specify whether to profile subprocesses for the profiled process.

In this dialog, you can use the Add New Configuration button to add additional profiles with specific settings. The Delete button removes the selected profile.

Run the profiling session

RubyMine provides two main ways to run the profiling session:

  • Running Ruby/Rails applications with the attached profiler

  • Attaching the profiler to the already running processes

The procedures below show how to start a profiling session.

Run the Ruby script with the profiler

  • Right-click the script in the editor or Project view, and select Run with 'RbSpy profiler' 'script name'.

Run the test(s) with the profiler

Do one of the following:

  • To profile a specific test, click the Run Test button next to this test and select Run with 'RbSpy profiler' 'test name'.

    Profile a test using a gutter

  • To profile tests inside a specific file, right-click the script in the editor or Project view, and select Run with 'RbSpy profiler' 'test name'.

  • To profile tests inside a specific folder, right-click this folder in the Project view, and select Run with 'RbSpy profiler'.

Run the Ruby/Rails configuration with the profiler

RubyMine allows you to run any Ruby/Rails-specific configuration with the profiler attached. For example, this might be the Ruby, Rails, Rake, or RSpec configuration. To run the required configuration with the profiler, perform the following steps:

  1. Select the required run configuration on the main toolbar.

  2. Click the Run with Profiler button next to the selected configuration and choose Run with 'RbSpy Profiler' 'configuration name'.

    Profile configuration

Attach the profiler to a running process

To attach the profiler to the Ruby/Rails process already running on your machine, do the following:

  1. From the main menu, select Run | Attach Profiler to Process.

  2. Select the required process from the popup and press Enter.

    Attach with RbSpy Profiler to

Stop the profiling session

The profiling session will be stopped automatically after stopping an application. To stop the profiling session manually, do the following:

  1. Open the Profiler tool window.

  2. Click the Stop Profiler button.

After the profiling session is finished, you can analyze profiling results.

Analyze profiling results

Profiling data for this script will be displayed on three tabs - Flame Chart, Call Tree, and Method List. In the left-hand part, you can filter data by the specified thread.

Profiling results

Flame Chart

This tab shows you the state of the call stack at any moment of time. Each frame represents a method/block in the stack (a stack frame). On the Y-axis, there is a stack depth going from bottom up. The X-axis shows the stack sorted from the most time-consuming methods/blocks to the least consuming ones.

Flame chart

When you read the flame chart, focus on the widest frames. You can start from the bottom and move up, following the code flow from parent to child frames.

To navigate within the flame chart, do the following:

  • To zoom in/out the chart, use the mouse wheel or Zoom in/Zoom out buttons on the toolbar. You can use the Actual zoom button to reset to the initial chart width.

  • Use the mouse or arrow keys to scroll the chart.

  • Navigate to a specific method by using a double-click. In this case, the chart shows the call stack starting with a parent method colored with grey.

You can also analyze data in the flame chart in the following ways:

  • Hover the mouse over any item to view the details.

  • Right-click the item and select Jump to Source to open corresponding code in the editor.

  • Right-click the item and select Focus on method in Methods List to the corresponding method in the Methods List tab.

Call Tree

The Call Tree tab shows the program call tree with the percentage of each method in the total profiling time.

Call tree

To configure and filter the Call Tree view, use the Tree Node View Settings and Call Tree Filter Settings buttons.

Methods List

The Method List tab shows the list of methods sorted by the number of samples.

Method list

For each method from the list, the profiler provides more information on the nested tabs. The Back Traces tab shows where the selected method has been called. The Merged Callees tab shows call traces that started from the selected method.

Export profiling results

To export profiling results to a file, do the following:

  1. From the main menu, select View | Tool Windows | Profiler to open the profiler tool window.

  2. In the left-hand toolbar, click Export Profiler Result.

  3. In the dialog that opens, name the file and specify a folder in which you want to save it. Click Save.

Import profiling results

To import profiling results from a file, select Run | Import Profiler Results | From File from the main menu. For example, this can be useful if you want to analyze profiling results recorded on the production server using rbspy.
Last modified: 8 May 2019