perf_check 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ea85bab0194c6138083f20d54ddccd20024c886
4
- data.tar.gz: 9479060df80ba93d13695da8953eed296f24fa9e
3
+ metadata.gz: a0044f60e2a24034b680d872ba644802609544bd
4
+ data.tar.gz: a6af1d7e8a2fa0407874e4c0a37081da8de5941c
5
5
  SHA512:
6
- metadata.gz: 71f853f4b2adb6f2a713f71f8f687417339a6435f376bc6310840f66f28eef64a4efea4665494ccf0836580e813f0ef0c34b89ff2c287f74622d3690b8d86a7d
7
- data.tar.gz: c76944ca5d33b1dc1d84eea2ea7d7a376b7871a1b19f0cd77be70650f83efa69dfccb8e9be0e54c6f320fbfe79003b1a76d23be9d1171c3fb9d63c472e6267aa
6
+ metadata.gz: 7cefb6316cea89e4f891a6430407001a22bf44757e08e857247bdda84eaa75f2fe9c1b545c2556a1d1e3f2ec8b24941d34d3b41518572217a6bcb375075e0f46
7
+ data.tar.gz: 8212ec527aa899f2a57efbbba827eee7a01751112377055f98d31599fcb50aa0476dd092e9aa71cb76021b88c8720af9086089849b80f67b312f4cb11f53d053
@@ -32,6 +32,7 @@ class PerfCheck
32
32
  system('git stash -q >/dev/null')
33
33
  abort("Problem with git stash! Bailing...") unless $?.success?
34
34
  at_exit do
35
+ system('git checkout .')
35
36
  Git.pop
36
37
  end
37
38
  end
@@ -21,6 +21,8 @@ class PerfCheck
21
21
  config = ActiveSupport::Configurable::Configuration
22
22
  config.send(:define_method, :perform_caching){ fragment_caching }
23
23
  end
24
+
25
+ PerfCheck::Server.seed_random!
24
26
  end
25
27
  end
26
28
  end
@@ -35,6 +35,29 @@ class PerfCheck
35
35
  end
36
36
  end
37
37
 
38
+ def self.seed_random!
39
+ # Seed random, for --verify purposes
40
+ srand(1)
41
+
42
+ # SecureRandom cannot be seeded, so we have to monkey patch it instead
43
+
44
+ def SecureRandom.hex(n=16)
45
+ '4' * n
46
+ end
47
+ def SecureRandom.random_bytes(n=16)
48
+ '4' * n
49
+ end
50
+ def SecureRandom.random_number(n=0)
51
+ n > 4 ? 4 : n
52
+ end
53
+ def SecureRandom.urlsafe_base64(n=16, padding=false)
54
+ '4' * (4*n / 3)
55
+ end
56
+ def SecureRandom.uuid
57
+ "00000000-0000-0000-0000-000000000004"
58
+ end
59
+ end
60
+
38
61
  def self.sign_cookie_data(key, data, opts={})
39
62
  opts[:serializer] ||= Marshal
40
63
  secret = Rails.application.config.secret_token
@@ -80,7 +103,7 @@ class PerfCheck
80
103
  mp_link
81
104
  end
82
105
 
83
- def profile
106
+ def profile
84
107
  http = Net::HTTP.new(host, port).tap{ |http| http.read_timeout = 1000 }
85
108
  response = nil
86
109
  prepare_to_profile
@@ -3,7 +3,7 @@
3
3
  class PerfCheck
4
4
  class TestCase
5
5
  attr_accessor :resource, :controller, :action, :format
6
- attr_accessor :latencies, :cookie
6
+ attr_accessor :cookie, :this_response, :reference_response
7
7
  attr_accessor :this_latencies, :reference_latencies
8
8
 
9
9
  def initialize(route)
@@ -11,7 +11,6 @@ class PerfCheck
11
11
 
12
12
  self.this_latencies = []
13
13
  self.reference_latencies = []
14
- self.latencies = this_latencies
15
14
 
16
15
  self.controller = params[:controller].split('/')[-1]
17
16
  self.action = params[:action]
@@ -19,17 +18,23 @@ class PerfCheck
19
18
  self.resource = route
20
19
  end
21
20
 
21
+ def switch_to_reference_context
22
+ @context = :reference
23
+ end
24
+
22
25
  def run(server, options)
23
26
  print("\t"+'request #'.underline)
24
27
  print(" "+'latency'.underline)
25
28
  print(" "+'server rss'.underline)
26
29
  puts(" "+'profiler data'.underline)
27
30
 
31
+ latencies = (@context == :reference) ? reference_latencies : this_latencies
32
+
28
33
  headers = {'Cookie' => "#{cookie}"}
29
34
  unless self.format
30
35
  headers['Accept'] = 'text/html,application/xhtml+xml,application/xml'
31
36
  end
32
- options.number_of_requests.times do |i|
37
+ (options.number_of_requests+1).times do |i|
33
38
  profile = server.profile do |http|
34
39
  http.get(resource, headers)
35
40
  end
@@ -45,10 +50,20 @@ class PerfCheck
45
50
  exit(1)
46
51
  end
47
52
 
53
+ next if i.zero?
54
+
55
+ if i == 1
56
+ if @context == :reference
57
+ self.reference_response = profile.response_body
58
+ else
59
+ self.this_response = profile.response_body
60
+ end
61
+ end
62
+
48
63
  printf("\t%2i:\t %.1fms %4dMB\t %s\n",
49
64
  i, profile.latency, server.mem, profile.profile_url)
50
65
 
51
- self.latencies << profile.latency
66
+ latencies << profile.latency
52
67
  end
53
68
  puts
54
69
  end
data/lib/perf_check.rb CHANGED
@@ -57,7 +57,7 @@ class PerfCheck
57
57
  if i == 1
58
58
  Git.stash_if_needed
59
59
  Git.checkout_reference(options.reference)
60
- test_cases.each{ |x| x.latencies = x.reference_latencies }
60
+ test_cases.each{ |x| x.switch_to_reference_context }
61
61
  end
62
62
 
63
63
  test_cases.each do |test|
@@ -110,6 +110,16 @@ class PerfCheck
110
110
  puts("master: ".rjust(15) + "#{master_latency}")
111
111
  puts("your branch: ".rjust(15)+ "#{this_latency}")
112
112
  puts(("change: ".rjust(15) + "#{formatted_change}").bold.send(color))
113
+
114
+ Tempfile.new('this_response').tap do |this_response|
115
+ Tempfile.new('reference_response').tap do |reference_response|
116
+ this_response.write(test.this_response)
117
+ reference_response.write(test.reference_response)
118
+ this_response.close
119
+ reference_response.close
120
+ system('diff', '-U0', this_response.path, reference_response.path)
121
+ end
122
+ end
113
123
  end
114
124
  end
115
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perf_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubytune