awfy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/awfy/cli.rb +77 -70
  3. data/lib/awfy/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bea684a36c13b8593199aa4490e13c5fbdcb35222766daa401b9c8151a71c8f
4
- data.tar.gz: 1825c25d81bd2210269d713313a8634d66f654b13e763e1f4bb33f7f62bcfe67
3
+ metadata.gz: f90af1a6ce12d7b811d3fb6353f91d46e1637607b7890d3ed0837fbeda7fdd96
4
+ data.tar.gz: e2a17a61c3ecf4d5795fc636407b49fa1aeaf150308f67215acf8d648d8f5df5
5
5
  SHA512:
6
- metadata.gz: 273fda35ea1688650b64b815d7b8b37b15485214341de4e2ca7e048a3f84f89cc0cb5693cadd5bfb0ed14810eb2169f142080e82df26c60acdbc1b421e046403
7
- data.tar.gz: d00c1252bbb61fe0687806be84dcc6cdc2ce20148b893fe50f09dc82fa258ec0f6f4deb1a89aefae0efcb51c187aa3a2928db748dfa321f096b4f71b328e0465
6
+ metadata.gz: 22291837342e69a9da6c55e7a4a6869a80b2dfa47d67e2ad3847a870335999560109de557f73b58d1b73d564fb1f9f016654fcc542ecada0238b16276a74ca23
7
+ data.tar.gz: 4c8dfa85d87b246512f7a478bfdf844c4af7361e1b6d87a418bf1d96aaa260a592194f3c7114f79cdfb38afc3a473da871f52f93c2f20811739bdbe05ba2bf77
data/lib/awfy/cli.rb CHANGED
@@ -25,7 +25,6 @@ module Awfy
25
25
 
26
26
  class_option :summary, type: :boolean, desc: "Generate a summary of the results", default: true
27
27
  class_option :verbose, type: :boolean, desc: "Verbose output", default: false
28
- class_option :quiet, type: :boolean, desc: "Silence output", default: false
29
28
 
30
29
  class_option :ips_warmup, type: :numeric, default: 1, desc: "Number of seconds to warmup the benchmark"
31
30
  class_option :ips_time, type: :numeric, default: 3, desc: "Number of seconds to run the benchmark"
@@ -48,33 +47,34 @@ module Awfy
48
47
 
49
48
  run_pref_test(group) { run_ips(_1, report, test) }
50
49
  end
51
- #
52
- # desc "memory [GROUP] [REPORT] [TEST]", "Run memory profiling"
53
- # def memory(group = nil, report = nil, test = nil)
54
- # say "Running memory profiling for:"
55
- # say "> #{requested_tests(group, report, test)}..."
56
- #
57
- # run_pref_test(group) { run_memory(_1, report, test) }
58
- # end
59
- #
60
- # desc "flamegraph GROUP REPORT TEST", "Run flamegraph profiling"
61
- # def flamegraph(group, report, test)
62
- # say "Creating flamegraph for:"
63
- # say "> #{[group, report, test].join("/")}..."
64
- # configure_benchmark_run
65
- # run_group(group) { run_flamegraph(_1, report, test) }
66
- # end
67
- #
50
+
51
+ desc "memory [GROUP] [REPORT] [TEST]", "Run memory profiling"
52
+ def memory(group = nil, report = nil, test = nil)
53
+ say "Running memory profiling for:"
54
+ say "> #{requested_tests(group, report, test)}..."
55
+
56
+ run_pref_test(group) { run_memory(_1, report, test) }
57
+ end
58
+
59
+ desc "flamegraph GROUP REPORT TEST", "Run flamegraph profiling"
60
+ def flamegraph(group, report, test)
61
+ say "Creating flamegraph for:"
62
+ say "> #{[group, report, test].join("/")}..."
63
+
64
+ configure_benchmark_run
65
+ run_group(group) { run_flamegraph(_1, report, test) }
66
+ end
67
+
68
68
  # # TODO: also YJIT stats output?
69
- # desc "profile [GROUP] [REPORT] [TEST]", "Run CPU profiling"
70
- # option :iterations, type: :numeric, default: 1_000_000, desc: "Number of iterations to run the test"
71
- # def profile(group = nil, report = nil, test = nil)
72
- # say "Run profiling of:"
73
- # say "> #{requested_tests(group, report, test)}..."
74
- #
75
- # configure_benchmark_run
76
- # run_group(group) { run_profiling(_1, report, test) }
77
- # end
69
+ desc "profile [GROUP] [REPORT] [TEST]", "Run CPU profiling"
70
+ option :iterations, type: :numeric, default: 1_000_000, desc: "Number of iterations to run the test"
71
+ def profile(group = nil, report = nil, test = nil)
72
+ say "Run profiling of:"
73
+ say "> #{requested_tests(group, report, test)}..."
74
+
75
+ configure_benchmark_run
76
+ run_group(group) { run_profiling(_1, report, test) }
77
+ end
78
78
 
79
79
  private
80
80
 
@@ -147,7 +147,7 @@ module Awfy
147
147
  prepare_output_directory_for_ips
148
148
 
149
149
  execute_report(group, report_name) do |report, runtime|
150
- Benchmark.ips(time: options[:ips_time], warmup: options[:ips_warmup], quiet: quiet_steps?) do |bm|
150
+ Benchmark.ips(time: options[:ips_time], warmup: options[:ips_warmup], quiet: show_summary? || verbose?) do |bm|
151
151
  execute_tests(report, test_name, output: false) do |test, _|
152
152
  test_label = "[#{runtime}] #{test[:control] ? CONTROL_MARKER : TEST_MARKER} #{test[:name]}"
153
153
  bm.item(test_label, &test[:block])
@@ -158,50 +158,56 @@ module Awfy
158
158
  bm.save!(file_name)
159
159
  end
160
160
 
161
- bm.compare! if verbose?
161
+ bm.compare! if verbose? || !show_summary?
162
162
  end
163
163
  end
164
164
 
165
165
  generate_ips_summary if options[:summary]
166
166
  end
167
- #
168
- # def run_memory(group, report_name, test_name)
169
- # say "> Memory profiling for #{group[:name]}...", :cyan if verbose?
170
- # execute_report(group, report_name) do |report, runtime|
171
- # execute_tests(report, test_name) do |test, _|
172
- # MemoryProfiler.report do
173
- # test[:block].call
174
- # end.pretty_print
175
- # end
176
- # end
177
- # end
178
- #
179
- # def run_flamegraph(group, report_name, test_name)
180
- # execute_report(group, report_name) do |report, runtime|
181
- # execute_tests(report, test_name) do |test, _|
182
- # label = "report-#{group[:name]}-#{report[:name]}-#{test[:name]}".gsub(/[^A-Za-z0-9_\-]/, "_")
183
- # generate_flamegraph(label) do
184
- # test[:block].call
185
- # end
186
- # end
187
- # end
188
- # end
189
- #
190
- # def run_profiling(group, report_name, test_name)
191
- # say "> Profiling for #{group[:name]} (iterations: #{options[:iterations]})..." if verbose?
192
- # execute_report(group, report_name) do |report, runtime|
193
- # execute_tests(report, test_name) do |test, iterations|
194
- # data = StackProf.run(mode: :cpu, interval: 100) do
195
- # i = 0
196
- # while i < iterations
197
- # test[:block].call
198
- # i += 1
199
- # end
200
- # end
201
- # StackProf::Report.new(data).print_text
202
- # end
203
- # end
204
- # end
167
+
168
+ def run_memory(group, report_name, test_name)
169
+ if verbose?
170
+ say "> Memory profiling for:"
171
+ say "> #{group[:name]}...", :cyan
172
+ end
173
+ execute_report(group, report_name) do |report, runtime|
174
+ execute_tests(report, test_name) do |test, _|
175
+ MemoryProfiler.report do
176
+ test[:block].call
177
+ end.pretty_print
178
+ end
179
+ end
180
+ end
181
+
182
+ def run_flamegraph(group, report_name, test_name)
183
+ execute_report(group, report_name) do |report, runtime|
184
+ execute_tests(report, test_name) do |test, _|
185
+ label = "report-#{group[:name]}-#{report[:name]}-#{test[:name]}".gsub(/[^A-Za-z0-9_\-]/, "_")
186
+ generate_flamegraph(label) do
187
+ test[:block].call
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ def run_profiling(group, report_name, test_name)
194
+ if verbose?
195
+ say "> Profiling for:"
196
+ say "> #{group[:name]} (iterations: #{options[:iterations]})...", :cyan
197
+ end
198
+ execute_report(group, report_name) do |report, runtime|
199
+ execute_tests(report, test_name) do |test, iterations|
200
+ data = StackProf.run(mode: :cpu, interval: 100) do
201
+ i = 0
202
+ while i < iterations
203
+ test[:block].call
204
+ i += 1
205
+ end
206
+ end
207
+ StackProf::Report.new(data).print_text
208
+ end
209
+ end
210
+ end
205
211
 
206
212
  def execute_report(group, report_name, &)
207
213
  runtime = options[:runtime]
@@ -242,7 +248,7 @@ module Awfy
242
248
 
243
249
  say if verbose?
244
250
  say "> --------------------------" if verbose?
245
- say "> Report (#{runtime} - branch '#{git_current_branch_name}'): #{report[:name]}"
251
+ say "> Report (#{runtime} - branch '#{git_current_branch_name}'): #{report[:name]}", :magenta
246
252
  say "> --------------------------" if verbose?
247
253
  say if verbose?
248
254
  yield run_report, runtime
@@ -403,7 +409,8 @@ module Awfy
403
409
  ensure
404
410
  say "Switching back to branch '#{previous_branch}'" if verbose?
405
411
  git_client.checkout(previous_branch)
406
- git_client.lib.stash_apply(0)
412
+ # Git client does not have a pop method so send our own command
413
+ git_client.lib.send(:command, "stash", "pop")
407
414
  end
408
415
 
409
416
  def git_current_branch_name = git_client.current_branch
@@ -416,6 +423,6 @@ module Awfy
416
423
 
417
424
  def verbose? = options[:verbose]
418
425
 
419
- def quiet_steps? = options[:quiet] || options[:summary]
426
+ def show_summary? = options[:summary]
420
427
  end
421
428
  end
data/lib/awfy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Awfy
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou