RubyMine 2023.3 Help

Profile 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 later 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.

  1. Open the Settings dialog Control+Alt+S.

  2. Go to the Build, Execution, Deployment | Ruby Profiler page and 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 'script name' with 'RbSpy profiler'.

Run the test(s) with the profiler

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

    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 'test name' with 'RbSpy profiler'.

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

Run the specific configuration with the profiler

RubyMine allows you to run any 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 'configuration name' with 'RbSpy Profiler'.

    Profile configuration

Attach the profiler to a running process

To attach the profiler to a process already running on your machine, do the following:

  1. In the main menu, go to 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 is 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

RubyMine uses different colors for various types of frames:

  • Orange for project Ruby methods calls.

  • Dark orange for Ruby method calls from external gems.

  • Blue for calls to native C extensions.

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. In case you use the icicle chart, read it from top to bottom.

Analyze results

  • Hover over any item to view the details.

  • To zoom in/out the chart, use Ctrl + 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.

  • 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 on Method List to the corresponding method in the Method List tab.

Switch to the icicle chart

An icicle chart is a frame chart upside down. You can read this chart from top to bottom, following the code flow from parent to child frames.

  1. Click the Presentation Settings button.

  2. In the invoked list, enable the Show icicle graph option.

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.

Method 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 and import profiling results

Export results

  1. In the main menu, go to 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 results

Importing results can be useful if you want to analyze profiling results recorded on the production server using rbspy.

  • To import profiling results from a file, select Run | Import Profiler Results | From File from the main menu.

Last modified: 10 January 2024