Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/singed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def output_directory=(directory)
end

def self.output_directory
@output_directory || raise("output directory hasn't been set!")
@output_directory
end

def enabled=(enabled)
Expand Down
16 changes: 13 additions & 3 deletions lib/singed/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'shellwords'
require 'tmpdir'
require 'optionparser'
require 'pathname'

# NOTE: we defer requiring singed until we run. that lets Rails load it if its in the gemfile, so the railtie has had a chance to run

Expand Down Expand Up @@ -64,6 +65,7 @@ def run

Singed.output_directory = @output_directory if @output_directory
Singed.output_directory ||= Dir.tmpdir
FileUtils.mkdir_p Singed.output_directory
@filename = Singed::Flamegraph.generate_filename(label: 'cli')

options = {
Expand All @@ -86,11 +88,19 @@ def run
prompt_password
end

Bundler.with_unbundled_env do
rbspy = lambda do
# don't run things with spring, because it forks and rbspy won't see it
sudo ['rbspy', *rbspy_args], reason: 'Singed needs to run as root, but will drop permissions back to your user.', env: { 'DISABLE_SPRING' => '1' }
end

if defined?(Bundler)
Bundler.with_unbundled_env do
rbspy.call
end
else
rbspy.call
end

unless filename.exist?
puts "#{filename} doesn't exist. Maybe rbspy had a failure capturing it? Check the scrollback."
exit 1
Expand All @@ -102,9 +112,9 @@ def run
end

# clean the report, similar to how Singed::Report does
json = JSON.parse(filename.read).with_indifferent_access
json = JSON.parse(filename.read)
json['shared']['frames'].each do |frame|
frame[:file] = Singed.filter_line(frame[:file])
frame['file'] = Singed.filter_line(frame['file'])
end
filename.write(JSON.dump(json))

Expand Down