corn 0.1.9 → 0.3.0
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.rb +19 -18
- data/lib/corn/rack.rb +13 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a683dd6a7151d53b1e5d4f39f2825cb636cb16fb
|
4
|
+
data.tar.gz: 014031992189ffdb40867829d556a13af552c57c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bf5360fc21c770b1ea32fc6fba2c1af60ed68371033b6b161946f1be74de4d634788529e91d4d64ade38727d6e64afa555e9343e72f1873a5413c3373227f6
|
7
|
+
data.tar.gz: 96d5a703ba798e4a2bfd4e383a7653d9bf228e282be757c252ca6942cde4f00c5671d5c39ffad30271d59f7b14d8b6dbfeb6360bfb0d28c17862006aaa0e3df1
|
data/lib/corn.rb
CHANGED
@@ -19,23 +19,21 @@ module Corn
|
|
19
19
|
!!(host && client_id)
|
20
20
|
end
|
21
21
|
|
22
|
-
def create_prof(
|
23
|
-
SamplingProf.new(
|
22
|
+
def create_prof(sampling_interval, output)
|
23
|
+
SamplingProf.new(sampling_interval).tap do |prof|
|
24
24
|
prof.output_file = output if output
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def start(output=nil,
|
29
|
-
@prof ||= create_prof(
|
28
|
+
def start(output=nil, sampling_interval=0.1)
|
29
|
+
@prof ||= create_prof(sampling_interval, output)
|
30
30
|
@prof.start
|
31
|
-
@prof_start_at = Time.now
|
32
31
|
end
|
33
32
|
|
34
33
|
def submit(name)
|
35
|
-
runtime, @prof_start_at = (Time.now - @prof_start_at), nil
|
36
34
|
@prof.stop
|
37
35
|
if configured?
|
38
|
-
upload(@prof.output_file, name
|
36
|
+
upload(@prof.output_file, name)
|
39
37
|
else
|
40
38
|
log("No CORN_CLIENT_ID or CORN_HOST configured, profiling data is not submitted")
|
41
39
|
end
|
@@ -49,18 +47,21 @@ module Corn
|
|
49
47
|
$stderr.puts msg
|
50
48
|
end
|
51
49
|
|
52
|
-
def upload(file, name
|
53
|
-
url = URI.parse(submit_url)
|
50
|
+
def upload(file, name)
|
54
51
|
File.open(file) do |f|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
post(f, name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def post(data, name)
|
57
|
+
url = URI.parse(submit_url)
|
58
|
+
req = Net::HTTP::Post::Multipart.new(url.path,
|
59
|
+
"data" => UploadIO.new(data, 'text/plain', 'profile.txt'),
|
60
|
+
'client_id' => client_id,
|
61
|
+
'name' => name)
|
62
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
63
|
+
http.use_ssl = url.scheme == 'https'
|
64
|
+
http.request(req)
|
64
65
|
end
|
65
66
|
log("Corn report submitted to #{submit_url}")
|
66
67
|
rescue Exception => e
|
data/lib/corn/rack.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
module Corn
|
2
2
|
class Rack
|
3
|
-
def initialize(app,
|
3
|
+
def initialize(app,
|
4
|
+
report_name="Corn::Rack created at #{Time.now}",
|
5
|
+
output_interval=nil)
|
4
6
|
@app = app
|
5
|
-
@
|
7
|
+
@prof = SamplingProf.new(0.1, true) do |data|
|
8
|
+
Corn.post(StringIO.new(data), report_name)
|
9
|
+
end
|
10
|
+
if output_interval
|
11
|
+
@prof.output_interval = output_interval
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
def call(env)
|
9
|
-
if Corn.configured?
|
10
|
-
profile do
|
16
|
+
if Corn.configured?
|
17
|
+
@prof.profile do
|
11
18
|
@app.call(env)
|
12
19
|
end
|
13
20
|
else
|
@@ -15,12 +22,8 @@ module Corn
|
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
|
-
def
|
19
|
-
|
20
|
-
yield
|
21
|
-
ensure
|
22
|
-
Corn.submit(@report_name)
|
25
|
+
def terminate
|
26
|
+
@prof.terminate
|
23
27
|
end
|
24
|
-
|
25
28
|
end
|
26
29
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xiao Li
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-24 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multipart-post
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: "0.
|
31
|
+
version: "0.3"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id002
|
34
34
|
description: |
|