rubyatscale / singed Goto Github PK
View Code? Open in Web Editor NEWGet a flamegraph anywhere in your code base. Powered by stackprof, rbspy, and speedscope
License: MIT License
Get a flamegraph anywhere in your code base. Powered by stackprof, rbspy, and speedscope
License: MIT License
License scanners indicate this gem license is "Unknown" since it's not in the gemspec.
Gem::Specification.new do |spec|
spec.name = 'singed'
spec.version = '0.2.0'
spec.authors = ['Josh Nichols']
spec.email = ['[email protected]']
+ spec.licenses = 'MIT'
We updated to ruby 3.3.2, and got this error when using the CLI:
โฏ bin/singed bin/tapioca dsl
๐ฅ๐ Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now...
$ sudo --preserve-env rbspy record --format speedscope --file tmp/speedscope/speedscope-cli-20240603122127.json --silent -- bin/tapioca dsl
Dropping permissions: running Ruby command as user josh.nichols
rbspy is recording traces. Press Ctrl+C to stop.
Wrote raw data to /Users/josh.nichols/Library/Caches/rbspy/2024-06-03-Y4xcYuW4vl.raw.gz
Wrote formatted output to tmp/speedscope/speedscope-cli-20240603122127.json
Something went wrong while rbspy was sampling the process. Here's what we know:
- new spy
- get ruby VM state
- rbspy doesn't support Ruby 3.3.2 yet. If this is a new patch-level version of Ruby, you can try using `--force-version` with the previous version number.
/Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/lib/singed/cli.rb:157:in `system': Command failed with exit 1: sudo (RuntimeError)
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/lib/singed/cli.rb:157:in `sudo'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/lib/singed/cli.rb:93:in `block in run'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/lib/singed/cli.rb:98:in `block in run'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.11/lib/bundler.rb:424:in `block in with_unbundled_env'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.11/lib/bundler.rb:679:in `with_env'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.11/lib/bundler.rb:424:in `with_unbundled_env'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/lib/singed/cli.rb:97:in `run'
from /Users/josh.nichols/.local/share/mise/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/singed-0.2.1/exe/singed:9:in `<top (required)>'
from bin/singed:27:in `load'
from bin/singed:27:in `<main>'
Vernier, as featured on https://www.youtube.com/watch?v=9nvX3OHykGQ#t=27m43
The most appealing part of vernier is that it seems to handle threads a lot better, so thread switching doesn't make it as hard to read.
(this is probably an edge case)
My project had stackprof on 0.2.12
in the Gemfile.lock
. It turns out print_json
is not defined in this version. It might help someone in the future if you update your gemspec to ensure a supported version of stackprof is installed:
spec.add_dependency 'stackprof', '>= 0.2.13'
stackprof supports using start / stop in addition to the block usage. This is helpful for when things aren't cleanly block wrapped.
cc @baweaver who requested it
I needed to run mkdir tmp/speedscope
to make it work
bundle exec singed -- bin/rails runner 'User.all.to_a'
You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
๐ฅ๐ Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now...
Password:
$ sudo --preserve-env rbspy record --format speedscope --file tmp/speedscope/speedscope-cli-20230309144106.json --silent -- bin/rails runner User.all.to_a
Dropping permissions: running Ruby command as user kivanio
rbspy is recording traces. Press Ctrl+C to stop.
You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
Wrote raw data to /Users/kivanio/Library/Caches/rbspy/2023-03-09-lxTiyfen4D.raw.gz
Wrote formatted output to tmp/speedscope/speedscope-cli-20230309144106.json
Something went wrong while rbspy was sampling the process. Here's what we know:
- Failed to create output file tmp/speedscope/speedscope-cli-20230309144106.json
- No such file or directory (os error 2)
bundler: failed to load command: singed (/Users/kivanio/.rbenv/versions/3.2.1/bin/singed)
/Users/kivanio/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/singed-0.1.1/lib/singed/cli.rb:147:in `system': Command failed with exit 1: sudo (RuntimeError)
It needs to clarify at README that in projects with rspec, the gem 'singed'
needs to be at same group as rspec
gem in your Gemfile.
Otherwise you get this:
bundle exec singed -- bin/rails runner 'User.all.to_a'
You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'.
bundler: failed to load command: singed (/Users/kivanio/.rbenv/versions/3.2.1/bin/singed)
/Users/kivanio/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/singed-0.1.1/lib/singed/rspec.rb:3:in `<main>': undefined method `configure' for RSpec:Module (NoMethodError)
RSpec.configure do |config|
^^^^^^^^^^
Right now, it's me manually pulling and running rake release
. Ideally, this happens automatically on main when the gemspec version changes, or if it is manually run.
Tried this, but without luck so far:
It is currently failing with:
singed 0.2.2 built to pkg/singed-0.2.2.gem.
rake aborted!
There are files that need to be committed first.
/home/runner/work/singed/singed/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/hostedtoolcache/Ruby/3.1.4/x64/bin/bundle:25:in `load'
/opt/hostedtoolcache/Ruby/3.1.4/x64/bin/bundle:25:in `<main>'
Tasks: TOP => release => release:guard_clean
(See full trace by running task with --trace)
I thought it could be the cache step, but I've added vendor/bundler to .gitignore . It's unfortunate it doesn't tell you what is uncommitted.
My next thought is to add a git status
to the build, but that might not trigger in the right place. If that doesn't show it, then I think it's a matter of adding rake tasks to do git status
before various steps ๐ค
We already have a Rack middleware. I could see there being a Sidekiq middleware too: https://github.com/sidekiq/sidekiq/wiki/Middleware . The execution of a job will be most interesting, which means just server middleware.
Currently, singed assumes you have a working node install, and can run npx
to be able to install and run speedscope.
Is there any way to bundle speedscope to reduce friction even more?
When you run npx speedscope <path>
, it is essentially creating a static HTML file, and then singed is using open
on it to get a browser for it.
I am trying to profile bin/rails server
backgrounded in a script, and then kill
it at the end. When I go to kill it, it seems to only kill the singed process, and rbspy
that it is calling.
cleanup() {
local pids
pids=$(jobs -pr)
if [ -n "$pids" ]; then
echo "Killing processes: $pids"
kill $pids
fi
}
trap "cleanup" SIGINT SIGTERM EXIT
echo "Starting server"
bin/rails server &
I'm not sure if rbspy is smart enough to be able to dump its progress or not, but at least trapping and passing it on would be a good first step
The readme mentions:
If you are calling it in a loop, or with different variations, you can include a label on the filename:
flamegraph(label: "rspec") {
# your code here
}
This is not accurate, as it results in:
ArgumentError:
unknown keyword: :label
If the library wants to support both a normal parameter and a keyword arg, it could use:
def flamegraph(_label = nil, label: _label, open: true, ignore_gc: false, interval: 1000, &block)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.