perf_check 0.8.0 → 0.9.0

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
  SHA1:
3
- metadata.gz: a0d9ae6fc8c0d7d6581b8c8202f82bd7b2cf6f1e
4
- data.tar.gz: cdec3df9f3dc51ad2b329c652dffe1154f0f80a3
3
+ metadata.gz: 9762190d0d025f9e0b5667bb8c3617de492a60fe
4
+ data.tar.gz: 3852d966b1245fd2c7fde01b70fef9bc7c043d86
5
5
  SHA512:
6
- metadata.gz: dcb0b85c4ff22bb9dd0cd7084b513b55942e74d2a18c24fd009cab27d7f0bbd95d241119e48679ce0f9becf96abaf9da6bbb9b74305017ea3eb210a06ffe0eb5
7
- data.tar.gz: 3647a68aac43d4bd6f63678c988988de348c69ea276288d5966caef248ebe82f8226690e1d3ad0385df8bfc8cc4d5b8ab3dd56d3eff33d4b276003f7f7ef7297
6
+ metadata.gz: 43cfa5145f18d1bc38f3cc528c7f8e51e7663c93e4f4e2c62b5dc31ade5104a8c1cf25aa73e7d848234dd129afb709e7b08c9bc71084ab8c693433417d88818e
7
+ data.tar.gz: ee033dd7afe11300842e5ac28b09672881a56b38c482db2e90f0395e2dc7e9ce447a68117a40d32140c7a21874c98dbc4eedf0dd0c9ace7488a409ea3e7a4329
@@ -30,7 +30,9 @@ end
30
30
 
31
31
  perf_check.run
32
32
 
33
- if perf_check.options.brief
33
+ if perf_check.options.compare_paths?
34
+ perf_check.print_results_of_compared_paths
35
+ elsif perf_check.options.brief
34
36
  perf_check.print_brief_results
35
37
  else
36
38
  perf_check.print_full_results
@@ -28,7 +28,8 @@ class PerfCheck
28
28
  '--ignore-matching-lines=/mini-profiler-resources/includes.js'],
29
29
  brief: false,
30
30
  caching: true,
31
- json: false
31
+ json: false,
32
+ hard_reset: false
32
33
  )
33
34
 
34
35
  @logger = Logger.new(STDERR).tap do |logger|
@@ -68,20 +69,24 @@ class PerfCheck
68
69
 
69
70
  def run
70
71
  begin
71
- profile_requests
72
-
73
- if options.reference
74
- git.stash_if_needed
75
- git.checkout_reference(options.reference)
76
- test_cases.each{ |x| x.switch_to_reference_context }
77
-
72
+ if options.compare_paths?
73
+ raise "Must have two paths" if test_cases.count != 2
74
+ profile_compare_paths_requests
75
+ else
78
76
  profile_requests
77
+ if options.reference
78
+ git.stash_if_needed
79
+ git.checkout(options.reference, bundle_after_checkout: true, hard_reset: options.hard_reset)
80
+ test_cases.each{ |x| x.switch_to_reference_context }
81
+
82
+ profile_requests
83
+ end
79
84
  end
80
85
  ensure
81
- server.exit rescue nil
86
+ server.exit
82
87
  if options.reference
83
- git.checkout_current_branch(false) rescue nil
84
- (git.pop rescue nil) if git.stashed?
88
+ git.checkout(git.current_branch, bundle_after_checkout: true, hard_reset: options.hard_reset)
89
+ git.pop if git.stashed?
85
90
  end
86
91
 
87
92
  callbacks = {}
@@ -97,29 +102,39 @@ class PerfCheck
97
102
 
98
103
  private
99
104
 
100
- def profile_requests
101
- run_migrations_up if options.run_migrations?
105
+ def profile_compare_paths_requests
106
+ first = test_cases[0]
107
+ reference_test = test_cases[1]
108
+ profile_test_case(first)
109
+ reference_test.switch_to_reference_context
110
+ profile_test_case(reference_test)
111
+ end
102
112
 
113
+ def profile_test_case(test)
114
+ trigger_before_start_callbacks(test)
115
+ run_migrations_up if options.run_migrations?
103
116
  server.restart
104
- test_cases.each_with_index do |test, i|
105
- trigger_before_start_callbacks(test)
106
- server.restart unless i.zero? || options.diff
107
117
 
108
- test.cookie = options.cookie
118
+ test.cookie = options.cookie
109
119
 
110
- if options.diff
111
- logger.info("Issuing #{test.resource}")
112
- else
113
- logger.info ''
114
- logger.info("Benchmarking #{test.resource}:")
115
- end
116
-
117
- test.run(server, options)
120
+ if options.diff
121
+ logger.info("Issuing #{test.resource}")
122
+ else
123
+ logger.info ''
124
+ logger.info("Benchmarking #{test.resource}:")
118
125
  end
126
+
127
+ test.run(server, options)
119
128
  ensure
120
129
  run_migrations_down if options.run_migrations?
121
130
  end
122
131
 
132
+ def profile_requests
133
+ test_cases.each do |test|
134
+ profile_test_case(test)
135
+ end
136
+ end
137
+
123
138
  def run_migrations_up
124
139
  logger.info "Running db:migrate"
125
140
  logger.info `cd #{app_root} && bundle exec rake db:migrate`
@@ -25,11 +25,11 @@ class PerfCheck
25
25
  end
26
26
 
27
27
  opts.on('--quick', '-q',
28
- 'Fire off 20 requests just on this branch (no comparison with master)') do
28
+ '20 requests just on this branch (no comparison with master)') do
29
29
  options.reference = nil
30
30
  end
31
31
 
32
- opts.on('--no-caching', 'Do not enable fragment caching') do
32
+ opts.on('--no-caching', 'Do not enable fragment caching (Rails.cache will still work)') do
33
33
  options.caching = false
34
34
  end
35
35
 
@@ -37,6 +37,10 @@ class PerfCheck
37
37
  options[:run_migrations?] = true
38
38
  end
39
39
 
40
+ opts.on('--compare-paths', 'Compare two paths against each other on the same branch') do
41
+ options[:compare_paths?] = true
42
+ end
43
+
40
44
  opts.on('--302-success', 'Consider HTTP 302 code a successful request') do
41
45
  options.http_statuses.push(302)
42
46
  end
@@ -46,6 +50,14 @@ class PerfCheck
46
50
  end
47
51
 
48
52
  opts.separator "\nMisc"
53
+ opts.on('-h', 'Display this help') do
54
+ # Do nothing, just don't error
55
+ end
56
+
57
+ opts.on('--deployment','Use git fetch/reset instead of the safe/friendly checkout') do
58
+ options.hard_reset = true
59
+ end
60
+
49
61
  opts.on('--cookie COOKIE', '-c') do |cookie|
50
62
  options.cookie = cookie
51
63
  end
@@ -18,32 +18,21 @@ class PerfCheck
18
18
  @current_branch = exec "git rev-parse --abbrev-ref HEAD"
19
19
  end
20
20
 
21
- def checkout_reference(reference='master')
22
- checkout(reference)
23
- end
24
-
25
- def checkout_current_branch(bundle=true)
26
- checkout(@current_branch, bundle)
27
- end
28
-
29
- def checkout(branch, bundle=true)
21
+ def checkout(branch, bundle_after_checkout: true, hard_reset: false)
30
22
  logger.info("Checking out #{branch} and bundling... ")
31
- exec "git checkout #{branch} --quiet"
23
+ if hard_reset
24
+ exec "git fetch --quiet && git reset --hard origin/#{branch} --quiet"
25
+ else
26
+ exec "git checkout #{branch} --quiet"
27
+ end
32
28
 
33
29
  unless $?.success?
34
30
  logger.fatal("Problem with git checkout! Bailing...")
35
31
  raise NoSuchBranch
36
32
  end
37
33
 
38
- exec "git submodule update --quiet"
39
-
40
- if bundle
41
- Bundler.with_clean_env{ exec "bundle" }
42
- unless $?.success?
43
- logger.fatal("Problem bundling! Bailing...")
44
- raise BundleError
45
- end
46
- end
34
+ update_submodules
35
+ bundle if bundle_after_checkout
47
36
  end
48
37
 
49
38
  def stash_if_needed
@@ -92,6 +81,18 @@ class PerfCheck
92
81
 
93
82
  private
94
83
 
84
+ def update_submodules
85
+ exec "git submodule update --quiet"
86
+ end
87
+
88
+ def bundle
89
+ Bundler.with_clean_env{ exec "bundle" }
90
+ unless $?.success?
91
+ logger.fatal("Problem bundling! Bailing...")
92
+ raise BundleError
93
+ end
94
+ end
95
+
95
96
  def current_migrations_not_on_master
96
97
  exec("git diff master --name-only --diff-filter=A db/migrate/").
97
98
  split.reverse
@@ -25,6 +25,37 @@ class PerfCheck
25
25
  end
26
26
  end
27
27
 
28
+ def print_results_of_compared_paths
29
+ puts("==== Results ====")
30
+
31
+ first_test = test_cases[0]
32
+ second_test = test_cases[1]
33
+
34
+ test_latency = first_test.this_latency
35
+ reference_latency = second_test.reference_latency
36
+
37
+ test_latency_output = latency_output(test_latency)
38
+ reference_latency_output = latency_output(reference_latency)
39
+
40
+ puts("reference path:" + first_test.resource.bold)
41
+ puts("test path:" + second_test.resource.bold)
42
+
43
+ latency_difference = test_latency - reference_latency
44
+
45
+ change_factor = change_factor(latency_difference, reference_latency, test_latency)
46
+ change_factor_output = sprintf('%.1fx', change_factor)
47
+ percent_change = calculate_percent_change(latency_difference, reference_latency)
48
+
49
+ formatted_change, color = formatted_change_and_color(
50
+ change_factor_output,
51
+ percent_change,
52
+ latency_difference
53
+ )
54
+
55
+ formatted_change = latency_output(latency_difference) + " (#{formatted_change})"
56
+ print_results(reference_latency_output, test_latency, formatted_change, color)
57
+ end
58
+
28
59
  def print_full_results
29
60
  puts("==== Results ====")
30
61
  test_cases.each do |test|
@@ -35,35 +66,65 @@ class PerfCheck
35
66
  next
36
67
  end
37
68
 
38
- master_latency = sprintf('%.1fms', test.reference_latency)
39
- this_latency = sprintf('%.1fms', test.this_latency)
40
- difference = sprintf('%+.1fms', test.latency_difference)
69
+ reference_latency_output = latency_output(test.reference_latency)
70
+ test_latency_output = latency_output(test.this_latency)
41
71
 
42
- if test.latency_difference < 0
43
- change_factor = test.reference_latency / test.this_latency
44
- else
45
- change_factor = test.this_latency / test.reference_latency
46
- end
47
- formatted_change = sprintf('%.1fx', change_factor)
48
-
49
- percent_change = 100*(test.latency_difference / test.reference_latency).abs
50
- if percent_change < 10
51
- formatted_change = "yours is about the same"
52
- color = :blue
53
- elsif test.latency_difference < 0
54
- formatted_change = "yours is #{formatted_change} faster!"
55
- color = :green
56
- else
57
- formatted_change = "yours is #{formatted_change} slower!!!"
58
- color = :light_red
59
- end
60
- formatted_change = difference + " (#{formatted_change})"
72
+ latency_difference = test.latency_difference
73
+ reference_latency = test.reference_latency
74
+ test_latency = test.this_latency
75
+
76
+ change_factor = change_factor(
77
+ latency_difference,
78
+ reference_latency,
79
+ test_latency
80
+ )
81
+
82
+ change_factor_output = sprintf('%.1fx', change_factor)
83
+ percent_change = calculate_percent_change(latency_difference, reference_latency)
61
84
 
62
- puts("reference: ".rjust(15) + "#{master_latency}")
63
- puts("your branch: ".rjust(15)+ "#{this_latency}")
64
- puts(("change: ".rjust(15) + "#{formatted_change}").bold.send(color))
85
+ formatted_change, color = formatted_change_and_color(change_factor_output, percent_change, latency_difference)
86
+ formatted_change = latency_output(latency_difference) + " (#{formatted_change})"
65
87
 
88
+ print_results(reference_latency_output, test_latency_output, formatted_change, color)
66
89
  print_diff_results(test.response_diff) if options.verify_no_diff
67
90
  end
68
91
  end
92
+
93
+ private
94
+
95
+ def latency_output(latency)
96
+ sprintf('%.1fms', latency)
97
+ end
98
+
99
+ def change_factor(latency_difference, reference_latency, test_latency)
100
+ if latency_difference < 0
101
+ reference_latency / test_latency
102
+ else
103
+ test_latency / reference_latency
104
+ end
105
+ end
106
+
107
+ def print_results(reference_latency, test_latency, formatted_change, color)
108
+ puts("reference: ".rjust(15) + "#{reference_latency}")
109
+ puts("your branch: ".rjust(15)+ "#{test_latency}")
110
+ puts(("change: ".rjust(15) + "#{formatted_change}").bold.send(color))
111
+ end
112
+
113
+ def formatted_change_and_color(change_factor_output, percent_change, latency_difference)
114
+ if percent_change < 10
115
+ formatted_change = "yours is about the same"
116
+ color = :blue
117
+ elsif latency_difference < 0
118
+ formatted_change = "yours is #{change_factor_output} faster!"
119
+ color = :green
120
+ else
121
+ formatted_change = "yours is #{change_factor_output} slower!!!"
122
+ color = :light_red
123
+ end
124
+ [formatted_change, color]
125
+ end
126
+
127
+ def calculate_percent_change(latency_difference, reference_latency)
128
+ 100*(latency_difference / reference_latency).abs
129
+ end
69
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perf_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubytune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec