corn 0.3.2 → 0.4.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 +14 -28
  3. data/lib/corn/rack.rb +2 -6
  4. metadata +6 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f58264f89af6bd995da6d701af22b1f9f1d5b539
4
- data.tar.gz: 451d4a5e348cc5070d9204a1ebc47072bce29cd3
3
+ metadata.gz: f6f36171dd4b5964f2fd405ee3d8bb32ec9903dc
4
+ data.tar.gz: c6a0ae40a7cc39fbe9de79bc94ab1544052e41d8
5
5
  SHA512:
6
- metadata.gz: d97a873cd81bdee21506be418be6bfa42378573654731bef4f2f5e4aae6973ab8e32b3d5c6b87d9db67f9267e4aa911f7f9bfc05428094537efa00aaa91745e8
7
- data.tar.gz: 62dfcc8c8ef95f232c359f603e6be304b977f019f00d001119d58526e2edf27a780a835a393ea622cca0cc7eb60af420bc34db34e6c65a4df0c828efc595414e
6
+ metadata.gz: 8ee868d1f6c7ead8146b24d82f5df7d53771ebc50ddefe554483528885c963e472ff2ec01392745f7e6516baf70230c3dc83ad72cac7411b66335f4158b5f06d
7
+ data.tar.gz: e9509c5b8a8925db14fbb7c6ba634e8acc560519fd15acad8361d1fc5db4b76672fc6917815da342eb3a5f591880f17c142be44d1d9b3cbae84c5a0e8d3df77f
@@ -1,7 +1,7 @@
1
+ require 'rubygems'
1
2
  require 'sampling_prof'
2
3
  require 'net/http'
3
4
  require 'net/https'
4
- require 'net/http/post/multipart'
5
5
  require 'corn/rack'
6
6
 
7
7
  module Corn
@@ -19,23 +19,17 @@ module Corn
19
19
  !!(host && client_id)
20
20
  end
21
21
 
22
- def create_prof(sampling_interval, output)
23
- SamplingProf.new(sampling_interval).tap do |prof|
24
- prof.output_file = output if output
25
- end
26
- end
27
-
28
- def start(output=nil, sampling_interval=0.1)
29
- @prof ||= create_prof(sampling_interval, output)
30
- @prof.start
31
- end
32
-
33
- def submit(name)
34
- @prof.stop
35
- if configured?
36
- upload(@prof.output_file, name)
37
- else
22
+ def profiler(report_name, sampling_interval=0.1, output_interval=nil)
23
+ if !configured?
38
24
  log("No CORN_CLIENT_ID or CORN_HOST configured, profiling data is not submitted")
25
+ return
26
+ end
27
+ SamplingProf.new(sampling_interval, true) do |data|
28
+ post(data, report_name)
29
+ end.tap do |prof|
30
+ if output_interval
31
+ prof.output_interval = output_interval
32
+ end
39
33
  end
40
34
  end
41
35
 
@@ -47,25 +41,17 @@ module Corn
47
41
  $stderr.puts msg
48
42
  end
49
43
 
50
- def upload(file, name)
51
- File.open(file) do |f|
52
- post(UploadIO.new(f, 'text/plain', File.basename(f.path)), name)
53
- end
54
- end
55
-
56
44
  def post(data, name)
57
45
  url = URI.parse(submit_url)
58
- req = Net::HTTP::Post::Multipart.new(url.path,
59
- "data" => data,
60
- 'client_id' => client_id,
61
- 'name' => name)
46
+ req = Net::HTTP::Post.new(url.path)
47
+ req.set_form_data("data" => data, 'client_id' => client_id, 'name' => name)
62
48
  res = Net::HTTP.start(url.host, url.port) do |http|
63
49
  http.use_ssl = url.scheme == 'https'
64
50
  http.request(req)
65
51
  end
66
52
  log("Corn report submitted to #{submit_url}")
67
53
  rescue Exception => e
68
- log("upload #{file} to #{submit_url} failed: #{e.message}")
54
+ log("post to #{submit_url} failed: #{e.message}")
69
55
  log(e.backtrace.join("\n"))
70
56
  end
71
57
  end
@@ -2,14 +2,10 @@ module Corn
2
2
  class Rack
3
3
  def initialize(app,
4
4
  report_name="Corn::Rack created at #{Time.now}",
5
+ sampling_interval=0.1,
5
6
  output_interval=nil)
6
7
  @app = app
7
- @prof = SamplingProf.new(0.1, true) do |data|
8
- Corn.post(data, report_name)
9
- end
10
- if output_interval
11
- @prof.output_interval = output_interval
12
- end
8
+ @prof = Corn.profiler(report_name, sampling_interval, output_interval)
13
9
  at_exit { terminate }
14
10
  end
15
11
 
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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
@@ -9,28 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-04-04 00:00:00 Z
12
+ date: 2014-04-16 00:00:00 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: multipart-post
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: "2.0"
22
- type: :runtime
23
- version_requirements: *id001
24
14
  - !ruby/object:Gem::Dependency
25
15
  name: sampling_prof
26
16
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
17
+ requirement: &id001 !ruby/object:Gem::Requirement
28
18
  requirements:
29
19
  - - ">="
30
20
  - !ruby/object:Gem::Version
31
21
  version: "0.3"
32
22
  type: :runtime
33
- version_requirements: *id002
23
+ version_requirements: *id001
34
24
  description: |
35
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.
36
26
 
@@ -58,13 +48,13 @@ require_paths:
58
48
  - lib
59
49
  required_ruby_version: !ruby/object:Gem::Requirement
60
50
  requirements:
61
- - &id003
51
+ - &id002
62
52
  - ">="
63
53
  - !ruby/object:Gem::Version
64
54
  version: "0"
65
55
  required_rubygems_version: !ruby/object:Gem::Requirement
66
56
  requirements:
67
- - *id003
57
+ - *id002
68
58
  requirements: []
69
59
 
70
60
  rubyforge_project: