corn 0.5.3 → 0.5.4
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 +4 -4
- data/lib/corn/post.rb +4 -3
- data/lib/corn/profiler.rb +21 -0
- data/lib/corn/rack/slow_request_profiler.rb +7 -9
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 350b0a06c165a783afcb852799e10c9b1e0c7773
|
4
|
+
data.tar.gz: 35cdfb9da1153beda11dd19f841e7f3b78e498d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147290199a7b42dd8d2a73b478c5a644e115ba51b0ce03a3211b42278750bc56ff5500741a89662b185710d6eb5c2337d78b3b8b92890be20bacea15b10402e9
|
7
|
+
data.tar.gz: 7d8450a6461dd85f0d7ddda2ab7a4525f2876ffb3ac8c26f3884b4cb5e51f40249c0ff1c1df5dd83ef74452c2889a2d25b0aae465ddedd08b4ce03f9f1554c24
|
data/lib/corn/post.rb
CHANGED
@@ -24,7 +24,7 @@ module Corn
|
|
24
24
|
Thread.start do
|
25
25
|
begin
|
26
26
|
loop do
|
27
|
-
http_post(
|
27
|
+
http_post(@queue.pop)
|
28
28
|
sleep interval
|
29
29
|
end
|
30
30
|
rescue => e
|
@@ -33,8 +33,9 @@ module Corn
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def enqueue(
|
37
|
-
|
36
|
+
def enqueue(data)
|
37
|
+
return if data.nil?
|
38
|
+
@queue << data
|
38
39
|
end
|
39
40
|
|
40
41
|
def http_post(data)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'corn/post'
|
2
|
+
require 'sampling_prof'
|
3
|
+
|
4
|
+
module Corn
|
5
|
+
class Profiler
|
6
|
+
def initialize(post_interval, sampling_interval)
|
7
|
+
@post = Post.new(post_interval)
|
8
|
+
@prof = SamplingProf.new(sampling_interval)
|
9
|
+
at_exit { terminate }
|
10
|
+
end
|
11
|
+
|
12
|
+
def profile(handler, &block)
|
13
|
+
@prof.profile(lambda {|data| @post.enqueue(handler.call(data))}, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def terminate
|
17
|
+
@prof.terminate rescue nil
|
18
|
+
@post.terminate rescue nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'corn/config'
|
2
|
-
require 'corn/
|
2
|
+
require 'corn/profiler'
|
3
3
|
require 'corn/rack/request_env'
|
4
|
-
require 'sampling_prof'
|
5
4
|
|
6
5
|
module Corn
|
7
6
|
module Rack
|
@@ -14,31 +13,30 @@ module Corn
|
|
14
13
|
|
15
14
|
class ProfilingApp
|
16
15
|
def initialize(app, config)
|
16
|
+
@@prof ||= Profiler.new(config.post_interval,
|
17
|
+
config.sampling_interval)
|
17
18
|
@app = app
|
18
19
|
@config = config
|
19
|
-
@post = Post.new(config.post_interval)
|
20
|
-
@prof = SamplingProf.new(config.sampling_interval)
|
21
|
-
at_exit { terminate }
|
22
20
|
end
|
23
21
|
|
24
22
|
def call(env)
|
25
23
|
if @config.profiling?
|
26
|
-
|
24
|
+
@@prof.profile(output_handler(env)) { @app.call(env) }
|
27
25
|
else
|
28
26
|
@app.call(env)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
def terminate
|
33
|
-
|
34
|
-
|
31
|
+
@@prof.terminate
|
32
|
+
@@prof = nil
|
35
33
|
end
|
36
34
|
|
37
35
|
def output_handler(env)
|
38
36
|
request_env = RequestEnv.new(env)
|
39
37
|
lambda do |data|
|
40
38
|
if request_env.time > @config.slow_request_threshold
|
41
|
-
|
39
|
+
request_env.to_report.merge("data" => data)
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xiao Li
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/corn.rb
|
37
37
|
- lib/corn/config.rb
|
38
38
|
- lib/corn/post.rb
|
39
|
+
- lib/corn/profiler.rb
|
39
40
|
- lib/corn/rack.rb
|
40
41
|
- lib/corn/rack/request_env.rb
|
41
42
|
- lib/corn/rack/slow_request_profiler.rb
|