corn 0.1.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/corn.rb +19 -18
  3. data/lib/corn/rack.rb +13 -10
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2794de12eebae473fe6e080c9540e88e47d3358d
4
- data.tar.gz: bb75e03506695bc2d02076fe7d77d153c7a0f66c
3
+ metadata.gz: a683dd6a7151d53b1e5d4f39f2825cb636cb16fb
4
+ data.tar.gz: 014031992189ffdb40867829d556a13af552c57c
5
5
  SHA512:
6
- metadata.gz: 4b7fcdb777001eb9700dc08176afb9f5de994e713a13914c4528e3b69a7a8ec9190304e3ab3857613fb523ddae51c55a1797b2bf6956de66d125442da3dc28d1
7
- data.tar.gz: e04a9c049b8ebd6aab24339f926db4d2046648fc48bc9f0d566b03bcc0be04a1fcd1f939facedf0fe25a2fbb6856505c3fda76700a9f263befc3cb6051067bf6
6
+ metadata.gz: 17bf5360fc21c770b1ea32fc6fba2c1af60ed68371033b6b161946f1be74de4d634788529e91d4d64ade38727d6e64afa555e9343e72f1873a5413c3373227f6
7
+ data.tar.gz: 96d5a703ba798e4a2bfd4e383a7653d9bf228e282be757c252ca6942cde4f00c5671d5c39ffad30271d59f7b14d8b6dbfeb6360bfb0d28c17862006aaa0e3df1
@@ -19,23 +19,21 @@ module Corn
19
19
  !!(host && client_id)
20
20
  end
21
21
 
22
- def create_prof(period, output)
23
- SamplingProf.new(period).tap do |prof|
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, period=0.1)
29
- @prof ||= create_prof(period, output)
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, runtime)
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, runtime)
53
- url = URI.parse(submit_url)
50
+ def upload(file, name)
54
51
  File.open(file) do |f|
55
- req = Net::HTTP::Post::Multipart.new(url.path,
56
- "data" => UploadIO.new(f, "text/plain"),
57
- 'client_id' => client_id,
58
- 'name' => name,
59
- 'runtime' => runtime)
60
- res = Net::HTTP.start(url.host, url.port) do |http|
61
- http.use_ssl = url.scheme == 'https'
62
- http.request(req)
63
- end
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
@@ -1,13 +1,20 @@
1
1
  module Corn
2
2
  class Rack
3
- def initialize(app, report_name='Corn::Rack')
3
+ def initialize(app,
4
+ report_name="Corn::Rack created at #{Time.now}",
5
+ output_interval=nil)
4
6
  @app = app
5
- @report_name = report_name
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? && env["QUERY_STRING"] =~ /corn_profiling=true/
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 profile(&block)
19
- Corn.start(Rails.root.join('tmp', "corn_rack.tmp.#{Thread.current.object_id}"))
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.1.9
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-14 00:00:00 Z
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.1"
31
+ version: "0.3"
32
32
  type: :runtime
33
33
  version_requirements: *id002
34
34
  description: |