1- require ' shellwords'
2- require ' tmpdir'
3- require ' optionparser'
4- require ' pathname'
1+ require " shellwords"
2+ require " tmpdir"
3+ require " optionparser"
4+ require " pathname"
55
66# 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
77
@@ -17,24 +17,24 @@ def initialize(argv)
1717 end
1818
1919 def parse_argv!
20- opts . banner = ' Usage: singed [options] <command>'
20+ opts . banner = " Usage: singed [options] <command>"
2121
22- opts . on ( '-h' , ' --help' , ' Show this message' ) do
22+ opts . on ( "-h" , " --help" , " Show this message" ) do
2323 @show_help = true
2424 end
2525
26- opts . on ( '-o' , ' --output-directory DIRECTORY' , ' Directory to write flamegraph to' ) do |directory |
26+ opts . on ( "-o" , " --output-directory DIRECTORY" , " Directory to write flamegraph to" ) do |directory |
2727 @output_directory = directory
2828 end
2929
3030 opts . order ( @argv ) do |arg |
31- opts . terminate if arg == '--'
31+ opts . terminate if arg == "--"
3232 break
3333 end
3434
3535 if @argv . empty?
3636 @show_help = true
37- @error_message = ' missing command to profile'
37+ @error_message = " missing command to profile"
3838 return
3939 end
4040
@@ -49,7 +49,7 @@ def parse_argv!
4949 end
5050
5151 def run
52- require ' singed'
52+ require " singed"
5353
5454 if @error_message
5555 puts @error_message
@@ -66,31 +66,31 @@ def run
6666 Singed . output_directory = @output_directory if @output_directory
6767 Singed . output_directory ||= Dir . tmpdir
6868 FileUtils . mkdir_p Singed . output_directory
69- @filename = Singed ::Flamegraph . generate_filename ( label : ' cli' )
69+ @filename = Singed ::Flamegraph . generate_filename ( label : " cli" )
7070
7171 options = {
72- format : ' speedscope' ,
72+ format : " speedscope" ,
7373 file : filename . to_s ,
74- silent : nil ,
74+ silent : nil
7575 }
7676
7777 rbspy_args = [
78- ' record' ,
78+ " record" ,
7979 *options . map { |k , v | [ "--#{ k } " , v ] . compact } . flatten ,
80- '--' ,
81- *argv ,
80+ "--" ,
81+ *argv
8282 ]
8383
8484 loop do
8585 break unless password_needed?
8686
87- puts ' 🔥📈 Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now...'
87+ puts " 🔥📈 Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now..."
8888 prompt_password
8989 end
9090
9191 rbspy = lambda do
9292 # don't run things with spring, because it forks and rbspy won't see it
93- sudo [ ' rbspy' , *rbspy_args ] , reason : ' Singed needs to run as root, but will drop permissions back to your user.' , env : { ' DISABLE_SPRING' => '1' }
93+ sudo [ " rbspy" , *rbspy_args ] , reason : " Singed needs to run as root, but will drop permissions back to your user." , env : { " DISABLE_SPRING" => "1" }
9494 end
9595
9696 if defined? ( Bundler )
@@ -113,8 +113,8 @@ def run
113113
114114 # clean the report, similar to how Singed::Report does
115115 json = JSON . parse ( filename . read )
116- json [ ' shared' ] [ ' frames' ] . each do |frame |
117- frame [ ' file' ] = Singed . filter_line ( frame [ ' file' ] )
116+ json [ " shared" ] [ " frames" ] . each do |frame |
117+ frame [ " file" ] = Singed . filter_line ( frame [ " file" ] )
118118 end
119119 filename . write ( JSON . dump ( json ) )
120120
@@ -123,15 +123,15 @@ def run
123123 end
124124
125125 def password_needed?
126- !system ( ' sudo --non-interactive true >/dev/null 2>&1' )
126+ !system ( " sudo --non-interactive true >/dev/null 2>&1" )
127127 end
128128
129129 def prompt_password
130- system ( ' sudo true' )
130+ system ( " sudo true" )
131131 end
132132
133133 def adjust_ownership!
134- sudo [ ' chown' , ENV [ ' USER' ] , filename ] , reason : "Adjusting ownership of #{ filename } , but need root."
134+ sudo [ " chown" , ENV [ " USER" ] , filename ] , reason : "Adjusting ownership of #{ filename } , but need root."
135135 end
136136
137137 def show_help?
@@ -147,9 +147,9 @@ def sudo(system_args, reason:, env: {})
147147 end
148148
149149 sudo_args = [
150- ' sudo' ,
151- ' --preserve-env' ,
152- *system_args . map ( &:to_s ) ,
150+ " sudo" ,
151+ " --preserve-env" ,
152+ *system_args . map ( &:to_s )
153153 ]
154154
155155 puts "$ #{ Shellwords . join ( sudo_args ) } "
@@ -161,7 +161,7 @@ def self.chdir_rails_root
161161 original_cwd = Dir . pwd
162162
163163 loop do
164- if File . file? ( ' config/environment.rb' )
164+ if File . file? ( " config/environment.rb" )
165165 return Dir . pwd
166166 end
167167
@@ -171,7 +171,7 @@ def self.chdir_rails_root
171171 end
172172
173173 # Otherwise keep moving upwards in search of an executable.
174- Dir . chdir ( '..' )
174+ Dir . chdir ( ".." )
175175 end
176176 end
177177 end
0 commit comments