corn 0.4.4 → 0.4.5

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: 1ff8db881c521ceb58ac042cdcb8a707768da281
4
- data.tar.gz: ec0048ff2da0f637e4f1cb9a7cdf53e9941f1ca9
5
- SHA512:
6
- metadata.gz: 505b222b6998f772a4def63b12f431ea0ea7c5de50042dbb7812a98a195b3ab1bee980bd11e81a57f7b1f5f8baf336fa78495e21860bc26b49726db172d329aa
7
- data.tar.gz: 7429d8ae6c5355d82ef16c0d64d1a2b8c003f3a1f05948b4a15187ce249a097974a163e5575d66ddbe419a9945d205f861b65756c7319d712da22898c77c3733
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07429dba6e4008f4bcb1eff01f06684408a24a36
4
+ data.tar.gz: ef59195398f1c04a798ec93ba534fbe8894f6df0
5
+ SHA512:
6
+ metadata.gz: 5408556f99f1bc880d2843348044a4b8d281569d0d5b558e4cf57ea2c63fc2babdf86e792acf126a73043a4c9e04f3b816a95664b413674fd280b21fd1024c75
7
+ data.tar.gz: 7c21f7658fd447eae5c46fd42ab5bff705a536571051f59ac92c33d6b65b2e0311344ef1e018fc9ea0e9386ea1768f03e67626c3ca2c3d461bec33d158416df0
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'thread'
4
+ require 'time'
4
5
 
5
6
  module Corn
6
7
  class Post
@@ -26,14 +27,17 @@ module Corn
26
27
  end
27
28
  end
28
29
 
29
- def enqueue(data, name)
30
- @queue << [data, name]
30
+ def enqueue(*args)
31
+ @queue << args
31
32
  end
32
33
 
33
- def http_post(data, name)
34
+ def http_post(data, name, start_time)
34
35
  uri = URI.parse(submit_url)
35
36
  req = Net::HTTP::Post.new(uri.path)
36
- req.set_form_data("data" => data, 'client_id' => Corn.client_id, 'name' => name)
37
+ req.set_form_data("data" => data,
38
+ 'client_id' => Corn.client_id,
39
+ 'name' => name,
40
+ 'start_time' => start_time.iso8601)
37
41
 
38
42
  http = Net::HTTP.new(uri.host, uri.port)
39
43
  if uri.scheme == 'https'
@@ -0,0 +1,37 @@
1
+ module Corn
2
+ module Rack
3
+ class RequestEnv
4
+ def initialize(threshold)
5
+ @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']
21
+ end
22
+
23
+ def time
24
+ Time.now - start_time
25
+ end
26
+
27
+ def slow_request?
28
+ time > @threshold
29
+ end
30
+
31
+ def report_name
32
+ File.join(*[Thread.current['corn_http_host'],
33
+ Thread.current['corn_path_info']].compact)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,28 +1,30 @@
1
1
  require 'corn/post'
2
+ require 'corn/rack/request_env'
2
3
  require 'sampling_prof'
3
4
 
4
5
  module Corn
5
6
  module Rack
6
7
  class SlowRequestProfiler
7
8
  def initialize(app,
8
- slow_request=5,
9
+ slow_request_threshold=5,
9
10
  sampling_interval=0.1)
10
11
  @app = app
11
12
  @post = Post.new
13
+ @request_env = RequestEnv.new(slow_request_threshold)
12
14
  @prof = SamplingProf.new(sampling_interval) do |data|
13
- t = Thread.current
14
- if (Time.now - t['corn_start_time']) > slow_request
15
- name = [t['corn_start_time'], t['corn_path_info']].join(',')
16
- @post.enqueue(data, name)
15
+ if @request_env.slow_request?
16
+ @post.enqueue(data,
17
+ @request_env.report_name,
18
+ @request_env.start_time)
17
19
  end
18
20
  end
19
21
  at_exit { terminate }
20
22
  end
21
23
 
22
24
  def call(env)
23
- Thread.current['corn_path_info'] = env['PATH_INFO']
24
- Thread.current['corn_start_time'] = Time.now
25
- @prof.profile { @app.call(env) }
25
+ @request_env.record(env) do
26
+ @prof.profile { @app.call(env) }
27
+ end
26
28
  end
27
29
 
28
30
  def terminate
metadata CHANGED
@@ -1,65 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: corn
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
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
- date: 2014-06-15 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'
20
- requirement: !ruby/object:Gem::Requirement
21
- requirements:
22
- - - '>='
23
- - !ruby/object:Gem::Version
24
- version: '0.4'
25
- prerelease: false
26
- type: :runtime
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
27
24
  description: |
28
25
  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.
29
- email:
30
- - swing1979@gmail.com
26
+
27
+ email:
28
+ - swing1979@gmail.com
31
29
  executables: []
30
+
32
31
  extensions: []
32
+
33
33
  extra_rdoc_files: []
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/slow_request_profiler.rb
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
41
43
  homepage: https://github.com/xli/corn
42
- licenses:
43
- - MIT
44
+ licenses:
45
+ - MIT
44
46
  metadata: {}
45
- post_install_message:
47
+
48
+ post_install_message:
46
49
  rdoc_options: []
47
- require_paths:
48
- - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- required_rubygems_version: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - '>='
57
- - !ruby/object:Gem::Version
58
- version: '0'
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
59
62
  requirements: []
60
- rubyforge_project:
63
+
64
+ rubyforge_project:
61
65
  rubygems_version: 2.1.9
62
- signing_key:
66
+ signing_key:
63
67
  specification_version: 4
64
68
  summary: Corn submits profiling data to Corn server.
65
69
  test_files: []
70
+