singed 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccc937a4dae7308cce56944f95e632c8e1001d7e2d51e148c7c24bab8ebb7e0a
4
- data.tar.gz: 3bc4cbfad22a829baf1f973b23188442a9525c000554f6485b314641ce459988
3
+ metadata.gz: 130f5fb69096f1a09875822dca8c86ca3a05876ca2b742cab274fb863ed7c253
4
+ data.tar.gz: 342357ad154850a5e5be841820cefe69609825650c8f0401c58a182f1ffd992c
5
5
  SHA512:
6
- metadata.gz: 8838d8a8b85fec579494d7a364a6f82d0a5a12245d076206a68d80264eacb01d43f1c6eb05c3258cf68c2d98f94caa160670f23d49e997b7c3ebd182028d8f99
7
- data.tar.gz: c6effbd5a23d9df99c6d19516638c730bbdfc9be400f8d0e673b2d3a06c1144dc33470a18f3ff68d67bdce8242791792fdf6ee3dee78dcbf60292fed29970f28
6
+ metadata.gz: 673f34810201f6050862488b728272ff769e5072b6a5fba90a4669b811efdbaa6fc9a8fd56c4f2cccebca7445c00bdc28700ec22881076dfcaef7bdf4bd5be2a
7
+ data.tar.gz: a839d09f7b78c96c4b1e38aa101fb755fef1c72ac3cee5068c0aef1df9d199ce3a73cfee3c40f6a2f934b6c14abb90765b3475e2a9ffc1d23e5a29f8eba01aab
data/exe/singed CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
-
4
- require 'singed/cli'
3
+ require "singed/cli"
5
4
  if Singed::CLI.chdir_rails_root
6
- require './config/environment'
5
+ require "./config/environment"
7
6
  end
8
7
 
9
8
  Singed::CLI.new(ARGV).run
data/lib/singed/cli.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'shellwords'
2
- require 'tmpdir'
3
- require 'optionparser'
4
- require 'pathname'
1
+ require "shellwords"
2
+ require "tmpdir"
3
+ require "optionparser"
4
+ require "pathname"
5
5
 
6
6
  # 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
7
7
 
@@ -17,24 +17,24 @@ module Singed
17
17
  end
18
18
 
19
19
  def parse_argv!
20
- opts.banner = 'Usage: singed [options] <command>'
20
+ opts.banner = "Usage: singed [options] <command>"
21
21
 
22
- opts.on('-h', '--help', 'Show this message') do
22
+ opts.on("-h", "--help", "Show this message") do
23
23
  @show_help = true
24
24
  end
25
25
 
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|
27
27
  @output_directory = directory
28
28
  end
29
29
 
30
30
  opts.order(@argv) do |arg|
31
- opts.terminate if arg == '--'
31
+ opts.terminate if arg == "--"
32
32
  break
33
33
  end
34
34
 
35
35
  if @argv.empty?
36
36
  @show_help = true
37
- @error_message = 'missing command to profile'
37
+ @error_message = "missing command to profile"
38
38
  return
39
39
  end
40
40
 
@@ -49,7 +49,7 @@ module Singed
49
49
  end
50
50
 
51
51
  def run
52
- require 'singed'
52
+ require "singed"
53
53
 
54
54
  if @error_message
55
55
  puts @error_message
@@ -66,31 +66,31 @@ module Singed
66
66
  Singed.output_directory = @output_directory if @output_directory
67
67
  Singed.output_directory ||= Dir.tmpdir
68
68
  FileUtils.mkdir_p Singed.output_directory
69
- @filename = Singed::Flamegraph.generate_filename(label: 'cli')
69
+ @filename = Singed::Flamegraph.generate_filename(label: "cli")
70
70
 
71
71
  options = {
72
- format: 'speedscope',
72
+ format: "speedscope",
73
73
  file: filename.to_s,
74
- silent: nil,
74
+ silent: nil
75
75
  }
76
76
 
77
77
  rbspy_args = [
78
- 'record',
78
+ "record",
79
79
  *options.map { |k, v| ["--#{k}", v].compact }.flatten,
80
- '--',
81
- *argv,
80
+ "--",
81
+ *argv
82
82
  ]
83
83
 
84
84
  loop do
85
85
  break unless password_needed?
86
86
 
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..."
88
88
  prompt_password
89
89
  end
90
90
 
91
91
  rbspy = lambda do
92
92
  # 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"}
94
94
  end
95
95
 
96
96
  if defined?(Bundler)
@@ -113,8 +113,8 @@ module Singed
113
113
 
114
114
  # clean the report, similar to how Singed::Report does
115
115
  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"])
118
118
  end
119
119
  filename.write(JSON.dump(json))
120
120
 
@@ -123,15 +123,15 @@ module Singed
123
123
  end
124
124
 
125
125
  def password_needed?
126
- !system('sudo --non-interactive true >/dev/null 2>&1')
126
+ !system("sudo --non-interactive true >/dev/null 2>&1")
127
127
  end
128
128
 
129
129
  def prompt_password
130
- system('sudo true')
130
+ system("sudo true")
131
131
  end
132
132
 
133
133
  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."
135
135
  end
136
136
 
137
137
  def show_help?
@@ -147,9 +147,9 @@ module Singed
147
147
  end
148
148
 
149
149
  sudo_args = [
150
- 'sudo',
151
- '--preserve-env',
152
- *system_args.map(&:to_s),
150
+ "sudo",
151
+ "--preserve-env",
152
+ *system_args.map(&:to_s)
153
153
  ]
154
154
 
155
155
  puts "$ #{Shellwords.join(sudo_args)}"
@@ -161,7 +161,7 @@ module Singed
161
161
  original_cwd = Dir.pwd
162
162
 
163
163
  loop do
164
- if File.file?('config/environment.rb')
164
+ if File.file?("config/environment.rb")
165
165
  return Dir.pwd
166
166
  end
167
167
 
@@ -171,7 +171,7 @@ module Singed
171
171
  end
172
172
 
173
173
  # Otherwise keep moving upwards in search of an executable.
174
- Dir.chdir('..')
174
+ Dir.chdir("..")
175
175
  end
176
176
  end
177
177
  end
@@ -6,11 +6,11 @@ module Singed
6
6
  # it's been created elsewhere, ie rbspy
7
7
  if filename
8
8
  if ignore_gc
9
- raise ArgumentError, 'ignore_gc not supported when given an existing file'
9
+ raise ArgumentError, "ignore_gc not supported when given an existing file"
10
10
  end
11
11
 
12
12
  if label
13
- raise ArgumentError, 'label not supported when given an existing file'
13
+ raise ArgumentError, "label not supported when given an existing file"
14
14
  end
15
15
 
16
16
  @filename = filename
@@ -41,7 +41,7 @@ module Singed
41
41
  report = Singed::Report.new(@profile)
42
42
  report.filter!
43
43
  filename.dirname.mkpath
44
- filename.open('w') { |f| report.print_json(f) }
44
+ filename.open("w") { |f| report.print_json(f) }
45
45
  end
46
46
 
47
47
  def open
@@ -53,10 +53,10 @@ module Singed
53
53
  end
54
54
 
55
55
  def self.generate_filename(label: nil, time: Time.now) # rubocop:disable Rails/TimeZone
56
- formatted_time = time.strftime('%Y%m%d%H%M%S')
57
- basename_parts = ['speedscope', label, formatted_time].compact
56
+ formatted_time = time.strftime("%Y%m%d%H%M%S-%6N")
57
+ basename_parts = ["speedscope", label, formatted_time].compact
58
58
 
59
- file = Singed.output_directory.join("#{basename_parts.join('-')}.json")
59
+ file = Singed.output_directory.join("#{basename_parts.join("-")}.json")
60
60
  # convert to relative directory if it's an absolute path and within the current
61
61
  pwd = Pathname.pwd
62
62
  file = file.relative_path_from(pwd) if file.absolute? && file.to_s.start_with?(pwd.to_s)
@@ -1,15 +1,15 @@
1
1
  module Kernel
2
- def flamegraph(label = nil, open: true, ignore_gc: false, interval: 1000, io: $stdout, &block)
2
+ def flamegraph(label = nil, open: true, ignore_gc: false, interval: 1000, io: $stdout, &)
3
3
  fg = Singed::Flamegraph.new(label: label, ignore_gc: ignore_gc, interval: interval)
4
- result = fg.record(&block)
4
+ result = fg.record(&)
5
5
  fg.save
6
6
 
7
7
  if open
8
8
  # use npx, so we don't have to add it as a dependency
9
- io.puts "🔥📈 #{'Captured flamegraph, opening with'.colorize(:bold).colorize(:red)}: #{fg.open_command}"
9
+ io.puts "🔥📈 #{"Captured flamegraph, opening with".colorize(:bold).colorize(:red)}: #{fg.open_command}"
10
10
  fg.open
11
11
  else
12
- io.puts "🔥📈 #{'Captured flamegraph to file'.colorize(:bold).colorize(:red)}: #{fg.filename}"
12
+ io.puts "🔥📈 #{"Captured flamegraph to file".colorize(:bold).colorize(:red)}: #{fg.filename}"
13
13
  end
14
14
 
15
15
  result
@@ -1,6 +1,6 @@
1
1
  # Rack Middleware
2
2
 
3
- require 'rack'
3
+ require "rack"
4
4
 
5
5
  module Singed
6
6
  class RackMiddleware
@@ -21,15 +21,15 @@ module Singed
21
21
  end
22
22
 
23
23
  def capture_flamegraph?(env)
24
- self.class.always_capture? || env['HTTP_X_SINGED'] == 'true'
24
+ self.class.always_capture? || env["HTTP_X_SINGED"] == "true"
25
25
  end
26
26
 
27
- TRUTHY_STRINGS = ['true', '1', 'yes'].freeze
27
+ TRUTHY_STRINGS = ["true", "1", "yes"].freeze
28
28
 
29
29
  def self.always_capture?
30
30
  return @always_capture if defined?(@always_capture)
31
31
 
32
- @always_capture = TRUTHY_STRINGS.include?(ENV.fetch('SINGED_MIDDLEWARE_ALWAYS_CAPTURE', 'false'))
32
+ @always_capture = TRUTHY_STRINGS.include?(ENV.fetch("SINGED_MIDDLEWARE_ALWAYS_CAPTURE", "false"))
33
33
  end
34
34
  end
35
35
  end
@@ -1,9 +1,9 @@
1
- require 'singed/backtrace_cleaner_ext'
2
- require 'singed/controller_ext'
1
+ require "singed/backtrace_cleaner_ext"
2
+ require "singed/controller_ext"
3
3
 
4
4
  module Singed
5
5
  class Railtie < Rails::Railtie
6
- initializer 'singed.configure_rails_initialization' do |app|
6
+ initializer "singed.configure_rails_initialization" do |app|
7
7
  self.class.init!
8
8
 
9
9
  app.middleware.use Singed::RackMiddleware
@@ -14,7 +14,7 @@ module Singed
14
14
  end
15
15
 
16
16
  def self.init!
17
- Singed.output_directory = Rails.root.join('tmp/speedscope')
17
+ Singed.output_directory = Rails.root.join("tmp/speedscope")
18
18
  Singed.backtrace_cleaner = Rails.backtrace_cleaner
19
19
  end
20
20
  end
data/lib/singed/rspec.rb CHANGED
@@ -1,11 +1,7 @@
1
- require 'singed'
1
+ require "singed"
2
2
 
3
3
  RSpec.configure do |config|
4
- config.around do |example|
5
- if example.metadata[:flamegraph]
6
- flamegraph { example.run }
7
- else
8
- example.run
9
- end
4
+ config.around(flamegraph: true) do |example|
5
+ flamegraph { example.run }
10
6
  end
11
7
  end
data/lib/singed.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'stackprof'
5
- require 'colorize'
3
+ require "json"
4
+ require "stackprof"
5
+ require "colorize"
6
6
 
7
7
  module Singed
8
8
  extend self
@@ -46,11 +46,11 @@ module Singed
46
46
  line
47
47
  end
48
48
 
49
- autoload :Flamegraph, 'singed/flamegraph'
50
- autoload :Report, 'singed/report'
51
- autoload :RackMiddleware, 'singed/rack_middleware'
49
+ autoload :Flamegraph, "singed/flamegraph"
50
+ autoload :Report, "singed/report"
51
+ autoload :RackMiddleware, "singed/rack_middleware"
52
52
  end
53
53
 
54
- require 'singed/kernel_ext'
55
- require 'singed/railtie' if defined?(Rails::Railtie)
56
- require 'singed/rspec' if defined?(RSpec) && RSpec.respond_to?(:configure)
54
+ require "singed/kernel_ext"
55
+ require "singed/railtie" if defined?(Rails::Railtie)
56
+ require "singed/rspec" if defined?(RSpec) && RSpec.respond_to?(:configure)
data/singed.gemspec CHANGED
@@ -1,27 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = 'singed'
4
+ spec.name = "singed"
5
5
 
6
- spec.version = '0.2.1'
7
- spec.license = 'MIT'
8
- spec.authors = ['Josh Nichols']
9
- spec.email = ['josh.nichols@gusto.com']
6
+ spec.version = "0.2.2"
7
+ spec.license = "MIT"
8
+ spec.authors = ["Josh Nichols"]
9
+ spec.email = ["josh.nichols@gusto.com"]
10
+ spec.summary = "Quick and easy way to get flamegraphs from a specific part of your code base"
11
+ spec.required_ruby_version = ">= 2.7.0"
12
+ spec.homepage = "https://github.com/rubyatscale/singed"
13
+ spec.metadata = {
14
+ "source_code_uri" => "https://github.com/rubyatscale/singed.git",
15
+ "bug_tracker_uri" => "https://github.com/rubyatscale/singed/issues",
16
+ "homepage_uri" => "https://github.com/rubyatscale/singed"
17
+ }
10
18
 
11
- spec.summary = 'Quick and easy way to get flamegraphs from a specific part of your code base'
12
- spec.required_ruby_version = '>= 2.7.0'
19
+ spec.files = Dir["README.md", "*.gemspec", "lib/**/*", "exe/**/*"]
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
13
23
 
14
- spec.files = Dir['README.md', '*.gemspec', 'lib/**/*', 'exe/**/*']
15
- spec.bindir = 'exe'
16
- spec.executables = spec.files.grep(%r(\Aexe/)) { |f| File.basename(f) }
17
- spec.require_paths = ['lib']
24
+ spec.add_dependency "colorize"
25
+ spec.add_dependency "stackprof", ">= 0.2.13"
18
26
 
19
- spec.add_dependency 'colorize'
20
- spec.add_dependency 'stackprof', '>= 0.2.13'
21
-
22
- spec.add_development_dependency 'rake', '~> 13.0'
23
- spec.add_development_dependency 'rspec'
24
-
25
- # For more information and examples about making a new gem, checkout our
26
- # guide at: https://bundler.io/guides/creating_gem.html
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
+ spec.add_development_dependency "rspec"
27
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-10 00:00:00.000000000 Z
11
+ date: 2024-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
69
+ description:
70
70
  email:
71
71
  - josh.nichols@gusto.com
72
72
  executables:
@@ -87,11 +87,14 @@ files:
87
87
  - lib/singed/report.rb
88
88
  - lib/singed/rspec.rb
89
89
  - singed.gemspec
90
- homepage:
90
+ homepage: https://github.com/rubyatscale/singed
91
91
  licenses:
92
92
  - MIT
93
- metadata: {}
94
- post_install_message:
93
+ metadata:
94
+ source_code_uri: https://github.com/rubyatscale/singed.git
95
+ bug_tracker_uri: https://github.com/rubyatscale/singed/issues
96
+ homepage_uri: https://github.com/rubyatscale/singed
97
+ post_install_message:
95
98
  rdoc_options: []
96
99
  require_paths:
97
100
  - lib
@@ -106,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  - !ruby/object:Gem::Version
107
110
  version: '0'
108
111
  requirements: []
109
- rubygems_version: 3.4.4
110
- signing_key:
112
+ rubygems_version: 3.5.9
113
+ signing_key:
111
114
  specification_version: 4
112
115
  summary: Quick and easy way to get flamegraphs from a specific part of your code base
113
116
  test_files: []