perf_check 0.0.2 → 0.0.7

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: 8d4485198a9057ea60ba1525b6ac00a1ef202aa3
4
- data.tar.gz: fb4528654f7042955e990f6f267b3378a03b5138
3
+ metadata.gz: 1113bc3c586dc1e5f7e8d4d3ef14b8140151b486
4
+ data.tar.gz: e3f47dba96b00bc1061c4ff2b8f63e923d5a9fc9
5
5
  SHA512:
6
- metadata.gz: 6771cc650d1712c2308f56625b7f177edd1484cfbd57b368e8ca977974f2a9b45003ad7b49647233c25756528fa4a288384c7580279784146f86c76f95db4a9c
7
- data.tar.gz: 70e0bcf7aa68b5161eb09096c2047113515170fb63a6a2a4130e9e4ffc1c141909276bdc5101ea0058992ffef0bb9a7a66446cfe218196a3aead3f004169497f
6
+ metadata.gz: ceb56fbfa1a430635e5b172e0b268f0eaac51cbd5d323f73732822d8b5e823e14be511aae01b870684da415b43c6738b9b598a078ab13201d9b59910615469db
7
+ data.tar.gz: c44e78da727beef6a2f37a323c19edba6acfa2b3b07f147ba415a1d37d87627065c4d98b658b953986ab5b6e7993f7c8812aa9f4f762dcfb82fa551e5e73e04a
data/bin/perf_check CHANGED
@@ -8,6 +8,7 @@ options.login = :admin
8
8
  options.number_of_requests = 10
9
9
  options.reference = 'master'
10
10
 
11
+
11
12
  opts = OptionParser.new do |opts|
12
13
  opts.banner = "Usage: perf_check [options] [route ...]"
13
14
 
@@ -49,6 +50,12 @@ opts = OptionParser.new do |opts|
49
50
  options.reference = nil
50
51
  end
51
52
 
53
+ opts.separator "\nOther"
54
+ opts.on('--server') do
55
+ PerfCheck::Server.start
56
+ exit!(0)
57
+ end
58
+
52
59
  opts.separator ''
53
60
  opts.separator <<EOF
54
61
  Usage examples:
@@ -67,19 +74,7 @@ EOF
67
74
  end
68
75
  opts.parse!
69
76
 
70
- app_root = Dir.pwd
71
- until app_root == '/' || File.exist?("#{app_root}/config/application.rb")
72
- app_root = File.dirname(app_root)
73
- end
74
-
75
- unless File.exist?("#{app_root}/config/application.rb")
76
- abort("perf_check should be run from a rails directory")
77
- end
78
-
79
- ENV['RAILS_ENV'] = 'development'
80
- ENV['PERF_CHECK'] = '1'
81
- require File.expand_path("#{app_root}/config/environment")
82
-
77
+ PerfCheck.require_rails
83
78
 
84
79
  ARGV.each do |route|
85
80
  perf_check.add_test_case(route)
@@ -0,0 +1,19 @@
1
+ class PerfCheck
2
+ class Railtie < Rails::Railtie
3
+
4
+ config.before_initialize do
5
+
6
+ if defined?(Rack::MiniProfiler)
7
+ # Integrate with rack-mini-profiler
8
+ tmp = "#{Rails.root}/tmp/perf_check/miniprofiler"
9
+ FileUtils.mkdir_p(tmp)
10
+
11
+ Rack::MiniProfiler.config.storage_instance =
12
+ Rack::MiniProfiler::FileStore.new(:path => tmp)
13
+ end
14
+
15
+ # Force cache_classes = true .... :\
16
+ Rails::Application::Configuration.send(:define_method, :cache_classes){ true }
17
+ end
18
+ end
19
+ end
@@ -10,6 +10,17 @@ class PerfCheck
10
10
  define_method(:login, &block)
11
11
  end
12
12
 
13
+ def self.sign_cookie_data(key, data, opts={})
14
+ opts[:serializer] ||= Marshal
15
+ secret = Rails.application.config.secret_token
16
+
17
+ marshal = ActiveSupport::MessageVerifier.new(secret,
18
+ :serializer => opts[:serializer])
19
+ marshal_value = marshal.generate(data)
20
+
21
+ "#{key}=#{marshal_value}"
22
+ end
23
+
13
24
  def initialize
14
25
  at_exit do
15
26
  exit
@@ -19,8 +19,14 @@ class PerfCheck
19
19
  end
20
20
 
21
21
  def run(server, count)
22
+ print("\t"+'request #'.underline)
23
+ print(" "+'latency'.underline)
24
+ print(" "+'server rss'.underline)
25
+ puts(" "+'profiler data'.underline)
26
+
22
27
  (count+1).times do |i|
23
28
  errors = 0
29
+
24
30
  begin
25
31
  profile = server.profile do |http|
26
32
  http.get(resource, {'Cookie' => cookie})
@@ -29,8 +35,11 @@ class PerfCheck
29
35
  File.open("public/perf_check_failed_request.html", 'w') do |error_dump|
30
36
  error_dump.write(e.body)
31
37
  end
32
- printf("\tRequest %2i: —— FAILURE (HTTP %s): %s\n",
33
- i, e.code, '/perf_check_failed_request.html')
38
+ error = sprintf("\t%2i:\tFAILED! (HTTP %s)", i, e.code)
39
+ puts(error.red.bold)
40
+ puts("\t The server responded with a non-2xx status for this request.")
41
+ print("\t The response has been written to public")
42
+ puts("/perf_check_failed_request.html".blue)
34
43
  exit(1)
35
44
  end
36
45
 
@@ -38,7 +47,7 @@ class PerfCheck
38
47
  # all the autoload overhead (?)
39
48
  next if i.zero?
40
49
 
41
- printf("\tRequest %2i: %.1fms\t%4dMB\t%s\n",
50
+ printf("\t%2i:\t %.1fms %4dMB\t %s\n",
42
51
  i, profile.latency, server.mem, profile.profile_url)
43
52
 
44
53
  self.latencies << profile.latency
data/lib/perf_check.rb CHANGED
@@ -6,10 +6,26 @@ require 'digest'
6
6
  require 'fileutils'
7
7
  require 'benchmark'
8
8
  require 'ostruct'
9
+ require 'colorize'
9
10
 
10
11
  class PerfCheck
11
12
  attr_accessor :options, :server, :test_cases
12
13
 
14
+ def self.require_rails
15
+ ENV['PERF_CHECK'] = '1'
16
+
17
+ app_root = Dir.pwd
18
+ until app_root == '/' || File.exist?("#{app_root}/config/application.rb")
19
+ app_root = File.dirname(app_root)
20
+ end
21
+
22
+ unless File.exist?("#{app_root}/config/application.rb")
23
+ abort("perf_check should be run from a rails directory")
24
+ end
25
+
26
+ require "#{app_root}/config/environment"
27
+ end
28
+
13
29
  def initialize
14
30
  self.options = OpenStruct.new
15
31
  self.server = Server.new
@@ -22,6 +38,10 @@ class PerfCheck
22
38
  end
23
39
 
24
40
  def sanity_check
41
+ if ENV['RAILS_ENV'] == 'production'
42
+ abort("perf_check cannot be run in the production environment")
43
+ end
44
+
25
45
  if Git.current_branch == "master"
26
46
  puts("Yo, profiling master vs. master isn't too useful, but hey, we'll do it")
27
47
  end
@@ -69,15 +89,17 @@ class PerfCheck
69
89
  if test.latency_difference < 0
70
90
  formatted_change = sprintf('%.1fx', test.latency_factor)
71
91
  formatted_change = "yours is #{formatted_change} faster!"
92
+ color = :green
72
93
  else
73
94
  formatted_change = sprintf('%.1fx', 1.0 / test.latency_factor)
74
95
  formatted_change = "yours is #{formatted_change} slower!!!"
96
+ color = :light_red
75
97
  end
76
98
  formatted_change = difference + " (#{formatted_change})"
77
99
 
78
100
  puts("master: ".rjust(15) + "#{master_latency}")
79
101
  puts("your branch: ".rjust(15)+ "#{this_latency}")
80
- puts("change: ".rjust(15) + "#{formatted_change}")
102
+ puts(("change: ".rjust(15) + "#{formatted_change}").bold.send(color))
81
103
  end
82
104
  end
83
105
  end
@@ -86,3 +108,7 @@ end
86
108
  require 'perf_check/server'
87
109
  require 'perf_check/test_case'
88
110
  require 'perf_check/git'
111
+
112
+ if defined?(Rails)
113
+ require 'perf_check/railtie'
114
+ 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.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - rubytune
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-06-30 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.3
13
27
  description:
14
28
  email:
15
29
  executables:
@@ -20,6 +34,7 @@ files:
20
34
  - bin/perf_check
21
35
  - lib/perf_check.rb
22
36
  - lib/perf_check/git.rb
37
+ - lib/perf_check/railtie.rb
23
38
  - lib/perf_check/server.rb
24
39
  - lib/perf_check/test_case.rb
25
40
  homepage: https://github.com/rubytune/perf_check