corn 0.5.5 → 0.5.6

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: 759ed8b4825185d198f5ac578d23004bd8569724
4
- data.tar.gz: 8a9d9cdf4085189b76c7177c01e05fff8c758b52
3
+ metadata.gz: 2128d61b559f2364bb060b87e258069ed0573622
4
+ data.tar.gz: 84dadacc4a71ad7b6c33209ef3cf1c5829e91936
5
5
  SHA512:
6
- metadata.gz: 005c5d90a218768e58b7f392158891961488715067994c7bd470f56380814434f8657b3453a277677dc367dd7f3b0db76006ac0a3876e77c63c99dad22d8cd43
7
- data.tar.gz: 617f8d391b4fe3f864e1b19ce7c9b5f10f3281b8fd7e7107478dab66ccffb3c617e4cc9f52ebe9622cbaf5f27e292a9c9e3542b3d4bf91c84190111d8ca8f420
6
+ metadata.gz: fa94880e60a3bf2e53e8901fc13e62d74424708c67d1f0c9848bbc63bcf825fc5c286298ca3ea0da847a315cc516fbb075ead74f4f1fd881ce17d4d3ee5a1ac0
7
+ data.tar.gz: 7791a5595a58ac89cf35ec041112ee78999e14f17665f8adf168f8f32b3bb78f28b75d2e3dc7f46ac58f7a4ecad7a612f88a4bc5ebe105a57c3c3857d46a9713
@@ -18,9 +18,9 @@ module Corn
18
18
  end
19
19
  q = !!value == value ? '?' : ''
20
20
  self.class_eval <<-RUBY, __FILE__, __LINE__
21
- def self.#{key}#{q}
21
+ def self.#{key}#{q}(*args)
22
22
  r = @config[:#{key}]
23
- r.is_a?(Proc) ? r.call : r
23
+ r.is_a?(Proc) ? r.call(*args) : r
24
24
  end
25
25
  RUBY
26
26
  end
@@ -1,8 +1,9 @@
1
1
  module Corn
2
2
  module Rack
3
3
  class RequestEnv
4
+ KEYS = [:request_method, :path_info, :http_host, :query_string]
4
5
  def initialize(env, start_time=Time.now)
5
- @env = [:path_info, :http_host, :query_string].inject({}) do |memo, k|
6
+ @env = KEYS.inject({}) do |memo, k|
6
7
  v = env[k.to_s.upcase]
7
8
  if v.nil? || v.empty?
8
9
  memo
@@ -23,6 +24,9 @@ module Corn
23
24
 
24
25
  def to_report
25
26
  name = File.join(@env[:http_host].to_s, @env[:path_info].to_s)
27
+ if @env[:request_method]
28
+ name = "#{@env[:request_method]} #{name}"
29
+ end
26
30
  if @env[:query_string]
27
31
  name = "#{name}?#{@env[:query_string]}"
28
32
  end
@@ -9,10 +9,12 @@ module Corn
9
9
  @@prof ||= Profiler.new(Corn.post_interval,
10
10
  Corn.sampling_interval)
11
11
  @app = app
12
+ Corn.logger.info("Corn sampling interval: #{Corn.sampling_interval}")
13
+ Corn.logger.info("Corn slow request threshold: #{Corn.slow_request_threshold}")
12
14
  end
13
15
 
14
16
  def call(env)
15
- if Corn.profiling?
17
+ if Corn.profiling?(env)
16
18
  @@prof.profile(output_handler(env)) { @app.call(env) }
17
19
  else
18
20
  @app.call(env)
@@ -6,14 +6,60 @@ module Corn
6
6
  def do_config
7
7
  create_file "config/initializers/corn_config.rb", <<-RUBY
8
8
  Corn.config({
9
+ # setup Corn logger, default is output to STDOUT.
9
10
  :logger => Rails.logger,
11
+
12
+ # Every Corn project has its own client id, you can find it in your
13
+ # Corn project page. This is a unique identifier for reporting your
14
+ # data, please keep it secret.
10
15
  # :client_id => ENV["CORN_CLIENT_ID"],
16
+
17
+ # Corn only reprots requests that are exceeded this threshold;
18
+ # default threshold is 5 seconds. Please use your 97 percentile response
19
+ # time as slow_request_threshold value, so that you can focus on
20
+ # improving slow requests. Doing nothing with generated reports
21
+ # is a waste.
22
+ # You can change this value to 0 for testing Corn configurations,
23
+ # and learn how Corn works.
24
+ # Set this threshold to smaller value may cause performance overhead.
11
25
  # :slow_request_threshold => 5,
26
+
27
+ # Sampling interval controls how frequent profiler should take
28
+ # sample of processing request threads' stacktrace. The default value
29
+ # is 0.1 seconds. Change the value to larger number will reduce the
30
+ # performance impact to your application. Change the value to smaller
31
+ # number will increase performance impact.
32
+ # The more samples we have for processing a request, the more accurate
33
+ # of the profiling call-graph report we will have.
34
+ # Hence it needs a balance.
35
+ # For example, when a request processing time is 5 seconds, sampling_interval
36
+ # value is 0.1 second, then we will get approximately 50 samples, which
37
+ # is good enough for you to understand what's your code doing in most
38
+ # of cases.
12
39
  # :sampling_interval => 0.1,
40
+
41
+ # Corn launchs a standalone thread to post profiling data back to Corn server.
42
+ # post_interval controls how frequent we will post one report back to
43
+ # Corn server. Default value is 2 seconds. It means the posting thread will
44
+ # sleep 2 seconds after Corn posted one processed slow request profiling
45
+ # data to Corn server. If you had too many reports need to be posted to Corn
46
+ # server, we recommend you increase slow_request_threshold instead of reduce
47
+ # post_interval value.
13
48
  # :post_interval => 2,
49
+
50
+ # Why we need this configuration? The anwser is runtime toggle.
51
+ # You may like to turn off the Corn profiler in most of time,
52
+ # and only turn on profiling when you need it in production.
53
+ # The value can be "true", "false" or a lambda (or Proc).
54
+ # For example: Corn.config(:profiling => lambda {|env| YourAppConfig.corn_profiling? })
55
+ # The "env" argument is the Rack env argument when a Rack middleware is
56
+ # called. So you can also use it to turn on profiling by a request parameter.
57
+ # For example: Corn.config(:profiling => lambda {|env| env["QUERY_STRING"] =~ /corn_profiling=true/ })
58
+ # This configuration will be checked for every request, so don't do anything
59
+ # expense here.
14
60
  # :profiling => true,
15
61
  })
16
-
62
+ # Install corn rack middleware for profiling slow requests
17
63
  Rails.configuration.middleware.use(Corn.rack_middleware)
18
64
  RUBY
19
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-04 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sampling_prof