perf_check 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/perf_check/git.rb +1 -0
- data/lib/perf_check/railtie.rb +2 -0
- data/lib/perf_check/server.rb +24 -1
- data/lib/perf_check/test_case.rb +19 -4
- data/lib/perf_check.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0044f60e2a24034b680d872ba644802609544bd
|
4
|
+
data.tar.gz: a6af1d7e8a2fa0407874e4c0a37081da8de5941c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cefb6316cea89e4f891a6430407001a22bf44757e08e857247bdda84eaa75f2fe9c1b545c2556a1d1e3f2ec8b24941d34d3b41518572217a6bcb375075e0f46
|
7
|
+
data.tar.gz: 8212ec527aa899f2a57efbbba827eee7a01751112377055f98d31599fcb50aa0476dd092e9aa71cb76021b88c8720af9086089849b80f67b312f4cb11f53d053
|
data/lib/perf_check/git.rb
CHANGED
data/lib/perf_check/railtie.rb
CHANGED
data/lib/perf_check/server.rb
CHANGED
@@ -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
|
data/lib/perf_check/test_case.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
class PerfCheck
|
4
4
|
class TestCase
|
5
5
|
attr_accessor :resource, :controller, :action, :format
|
6
|
-
attr_accessor :
|
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
|
-
|
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.
|
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
|