corn 0.4.5 → 0.4.6

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
- ---
2
- SHA1:
3
- metadata.gz: 07429dba6e4008f4bcb1eff01f06684408a24a36
4
- data.tar.gz: ef59195398f1c04a798ec93ba534fbe8894f6df0
5
- SHA512:
6
- metadata.gz: 5408556f99f1bc880d2843348044a4b8d281569d0d5b558e4cf57ea2c63fc2babdf86e792acf126a73043a4c9e04f3b816a95664b413674fd280b21fd1024c75
7
- data.tar.gz: 7c21f7658fd447eae5c46fd42ab5bff705a536571051f59ac92c33d6b65b2e0311344ef1e018fc9ea0e9386ea1768f03e67626c3ca2c3d461bec33d158416df0
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44550a060755050d6930b2921ba78abb6abe6553
4
+ data.tar.gz: 964e84445c59fe3631c4a96c163c1dae2e3aaad0
5
+ SHA512:
6
+ metadata.gz: 213d49a2eff2d13f557b46e66bed4a9eea5492f508e29f4488a677d2a2b3bd3dc60267e6ddef0ef52d1459abebb74f329cf949152d673486161c5b231d3bf83e
7
+ data.tar.gz: c390d9e3b98b03e562a1867dcee8a406ba7fc5f45e5b1d4dac3c537dc87283bdd40c836d0fc9f6f8264453b20e97ddf831288245af53fd1ecd682cc45237033b
@@ -1,23 +1,12 @@
1
1
  module Corn
2
2
  module Rack
3
3
  class RequestEnv
4
- def initialize(threshold)
4
+ attr_reader :start_time
5
+ def initialize(env, threshold)
6
+ @path_info = env['PATH_INFO']
7
+ @http_host = env['HTTP_HOST']
5
8
  @threshold = threshold
6
- end
7
-
8
- def record(env, &block)
9
- Thread.current['corn_path_info'] = env['PATH_INFO']
10
- Thread.current['corn_http_host'] = env['HTTP_HOST']
11
- Thread.current['corn_start_time'] = Time.now
12
- yield
13
- ensure
14
- Thread.current['corn_path_info'] = nil
15
- Thread.current['corn_http_host'] = nil
16
- Thread.current['corn_start_time'] = nil
17
- end
18
-
19
- def start_time
20
- Thread.current['corn_start_time']
9
+ @start_time = Time.now
21
10
  end
22
11
 
23
12
  def time
@@ -29,8 +18,8 @@ module Corn
29
18
  end
30
19
 
31
20
  def report_name
32
- File.join(*[Thread.current['corn_http_host'],
33
- Thread.current['corn_path_info']].compact)
21
+ File.join(*[@http_host,
22
+ @path_info].compact)
34
23
  end
35
24
  end
36
25
  end
@@ -9,28 +9,31 @@ module Corn
9
9
  slow_request_threshold=5,
10
10
  sampling_interval=0.1)
11
11
  @app = app
12
+ @slow_request_threshold = slow_request_threshold
12
13
  @post = Post.new
13
- @request_env = RequestEnv.new(slow_request_threshold)
14
- @prof = SamplingProf.new(sampling_interval) do |data|
15
- if @request_env.slow_request?
16
- @post.enqueue(data,
17
- @request_env.report_name,
18
- @request_env.start_time)
19
- end
20
- end
14
+ @prof = SamplingProf.new(sampling_interval)
21
15
  at_exit { terminate }
22
16
  end
23
17
 
24
18
  def call(env)
25
- @request_env.record(env) do
26
- @prof.profile { @app.call(env) }
27
- end
19
+ @prof.profile(output_handler(env)) { @app.call(env) }
28
20
  end
29
21
 
30
22
  def terminate
31
23
  @prof.terminate rescue nil
32
24
  @post.terminate
33
25
  end
26
+
27
+ def output_handler(env)
28
+ request_env = RequestEnv.new(env, @slow_request_threshold)
29
+ lambda do |data|
30
+ if request_env.slow_request?
31
+ @post.enqueue(data,
32
+ request_env.report_name,
33
+ request_env.start_time)
34
+ end
35
+ end
36
+ end
34
37
  end
35
38
  end
36
39
  end
metadata CHANGED
@@ -1,70 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: corn
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.6
5
5
  platform: ruby
6
- authors:
7
- - Xiao Li
8
- autorequire:
6
+ authors:
7
+ - Xiao Li
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-06-18 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: sampling_prof
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: "0.4"
22
- type: :runtime
23
- version_requirements: *id001
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sampling_prof
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.5
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.5
25
+ prerelease: false
26
+ type: :runtime
24
27
  description: |
25
28
  Corn collects your application's profiling data by sampling_prof gem, and submits the result to server, so that you can merge multiple server's profiling data and do analysis together.
26
-
27
- email:
28
- - swing1979@gmail.com
29
+ email:
30
+ - swing1979@gmail.com
29
31
  executables: []
30
-
31
32
  extensions: []
32
-
33
33
  extra_rdoc_files: []
34
-
35
- files:
36
- - README.md
37
- - lib/corn.rb
38
- - lib/corn/config.rb
39
- - lib/corn/post.rb
40
- - lib/corn/rack.rb
41
- - lib/corn/rack/request_env.rb
42
- - lib/corn/rack/slow_request_profiler.rb
34
+ files:
35
+ - README.md
36
+ - lib/corn.rb
37
+ - lib/corn/config.rb
38
+ - lib/corn/post.rb
39
+ - lib/corn/rack.rb
40
+ - lib/corn/rack/request_env.rb
41
+ - lib/corn/rack/slow_request_profiler.rb
43
42
  homepage: https://github.com/xli/corn
44
- licenses:
45
- - MIT
43
+ licenses:
44
+ - MIT
46
45
  metadata: {}
47
-
48
- post_install_message:
46
+ post_install_message:
49
47
  rdoc_options: []
50
-
51
- require_paths:
52
- - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
54
- requirements:
55
- - &id002
56
- - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - *id002
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
62
60
  requirements: []
63
-
64
- rubyforge_project:
61
+ rubyforge_project:
65
62
  rubygems_version: 2.1.9
66
- signing_key:
63
+ signing_key:
67
64
  specification_version: 4
68
65
  summary: Corn submits profiling data to Corn server.
69
66
  test_files: []
70
-