Mike Slinn

Profiling Jekyll and plugins with rbspy

Published 2022-05-03.
Time to read: 1 minutes.

This page is part of the jekyll collection.

Have you ever wanted to know what functions your Ruby program is calling? rbspy can tell you!

rbspy lets you profile Ruby processes that are already running. You give it a PID, and it starts profiling! It’s a sampling profiler, which means it's low overhead and safe to run in production.

Installing

I downloaded rbspy-x86_64-musl.tar.gz. The musl build is statically linked and should be compatible with most Linux systems. More details here.

Shell
$ wget -O ~/Downloads/rbspy.tar.gz https://github.com/rbspy/rbspy/releases/download/v0.12.1/rbspy-x86_64-musl.tar.gz
--2022-05-03 07:58:33--  https://github.com/rbspy/rbspy/releases/download/v0.12.1/rbspy-x86_64-musl.tar.gz
Resolving github.com (github.com)... 140.82.112.4
Connecting to github.com (github.com)|140.82.112.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/58655757/f10942b5-592b-4ed6-8a62-d76776c4fdb3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220503%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220503T115837Z&X-Amz-Expires=300&X-Amz-Signature=7e70c4443ddd4053d887244deaa01ac8c2033dbc06b9bdf9d4389580bebfa179&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=58655757&response-content-disposition=attachment%3B%20filename%3Drbspy-x86_64-musl.tar.gz&response-content-type=application%2Foctet-stream [following]
--2022-05-03 07:58:33--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/58655757/f10942b5-592b-4ed6-8a62-d76776c4fdb3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220503%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220503T115837Z&X-Amz-Expires=300&X-Amz-Signature=7e70c4443ddd4053d887244deaa01ac8c2033dbc06b9bdf9d4389580bebfa179&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=58655757&response-content-disposition=attachment%3B%20filename%3Drbspy-x86_64-musl.tar.gz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.109.133, 185.199.108.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2610927 (2.5M) [application/octet-stream]
Saving to: ‘/home/mslinn/Downloads/rbspy.tar.gz’

/home/mslinn/Downloads/rbspy.tar.gz         100%[===========================================================================================>]   2.49M  --.-KB/s    in 0.04s

2022-05-03 07:58:34 (57.7 MB/s) - ‘/home/mslinn/Downloads/rbspy.tar.gz’ saved [2610927/2610927] 

The recommended directory for user scripts on Ubuntu is ~/.local/bin/. This directory does not exist by default. More information here.

Shell
$ cd ~/.local/bin/

$ tar -xvf ~/Downloads/rbspy.tar.gz
rbspy-x86_64-musl 

$ mv ./rbspy-x86_64-musl rbspy

$ chmod a+x rbspy

Now we can learn how to use rbspy:

Shell
$ rbspy --help
Sampling profiler for Ruby programs

USAGE:
    rbspy <SUBCOMMAND>

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

SUBCOMMANDS:
    help        Print this message or the help of the given subcommand(s)
    record      Continuously capture traces from a Ruby process
    report      Generate visualization from raw data recorded by `rbspy record`
    snapshot    Capture a single stack trace from a running Ruby program


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.