corn 0.1.0 → 0.1.1

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 +7 -7
  2. data/lib/corn.rb +22 -53
  3. metadata +50 -30
  4. data/lib/corn/report.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 1286a1c4fa1681980a80beb37f953ef73fdd9bbd
4
- data.tar.gz: 102e0c92b4f5deddc98e29d9e525b7865b1d9743
5
- SHA512:
6
- metadata.gz: cc856cd5c679a58da2f584ca1d1d66ab1beb59d1be9025db2e7f7d34c3590bc23307208aa59b3d609de53e4ab39042de52643993d10b8f137bc113df51cc39cb
7
- data.tar.gz: e0ca9ab344dd596b379ff480c8920a932a2fa8d1954b0d5eabbb6243ed7c97b5abe08cf9a5f4c184b9e39c0a534ff5ccc03e0efdeda79b1e061c12b131f91f71
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6cfee2778ad98d567976a0bb9b6027da9e24472
4
+ data.tar.gz: ae18162e7ab186da5bd0e3d78db2cb594b06c96f
5
+ SHA512:
6
+ metadata.gz: b5cdd75cd5d47dac34bef34913c96635e4a4fb56ca26839d7b8a40985fd5fed062735be6e446ff8c96d2dbc3cd72f8f677ef023c0d3562633cca17089a23dc4a
7
+ data.tar.gz: d05aa533388a37465368baa15fa8a87495bd2c1f94b651d44261a04ff9fb1f88efa7ac874dd6c9a3f65ff345633eae25b836134abe70d90595f6a568386ce392
@@ -1,79 +1,48 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'logger'
4
- require 'csv'
5
-
6
- require 'corn/report'
1
+ require 'sampling_prof'
7
2
 
8
3
  module Corn
9
4
  module_function
10
5
 
11
6
  def host
12
- ENV['CORN_HOST'] || raise('No environment vairable CORN_HOST defined')
7
+ ENV['CORN_HOST']
13
8
  end
14
9
 
15
10
  def client_id
16
- ENV['CORN_CLIENT_ID'] || raise('No environment vairable CORN_CLIENT_ID defined')
11
+ ENV['CORN_CLIENT_ID']
17
12
  end
18
13
 
19
14
  def configured?
20
- !!ENV['CORN_CLIENT_ID']
21
- end
22
-
23
- def logger
24
- @logger ||= Logger.new(STDOUT)
25
- end
26
-
27
- def create_report(name)
28
- Thread.current[report_key] = Report.new(name)
15
+ !!(host && client_id)
29
16
  end
30
17
 
31
- def report(label=nil, &block)
32
- if label
33
- self.report.record(label, &block)
34
- else
35
- Thread.current[report_key]
18
+ def create_prof(period, output)
19
+ SamplingProf.new(period).tap do |prof|
20
+ prof.output_file = output if output
36
21
  end
37
22
  end
38
23
 
39
- def submit
40
- return if self.report.nil? || self.report.empty?
41
- log_error do
42
- data = {
43
- 'client_id' => client_id,
44
- 'report[name]' => self.report.name,
45
- 'report[records]' => self.report.to_csv
46
- }
47
- http_post(File.join(host, 'benchmarks'), data)
48
- end
24
+ def start(output=nil, period=0.1)
25
+ @prof ||= create_prof(period, output)
26
+ @prof.start
49
27
  end
50
28
 
51
- def http_post(url, data)
52
- uri = URI(url)
53
- Net::HTTP.start(uri.host, uri.port) do |http|
54
- http.use_ssl = uri.scheme == 'https'
55
- req = Net::HTTP::Post.new(uri.path)
56
- req.set_form_data(data)
57
- res = http.request req
58
- case res
59
- when Net::HTTPSuccess, Net::HTTPRedirection
60
- # OK
61
- else
62
- res.error!
29
+ def submit(name)
30
+ @prof.stop
31
+ if configured?
32
+ o = `curl -F data=@#{@prof.output_file} -F client_id=#{client_id} -F name=#{name} #{submit_url}`
33
+ if $?.exitstatus != 0
34
+ log("Submit report error: \n#{o}")
63
35
  end
36
+ else
37
+ log("No CORN_CLIENT_ID configured, profiling data is not submitted")
64
38
  end
65
39
  end
66
40
 
67
- def log_error(&block)
68
- yield
69
- rescue Exception => e
70
- logger.debug do
71
- "Report error: #{e.message}:\n#{e.backtrace.join("\n")}"
72
- end
41
+ def submit_url
42
+ File.join(host, 'profile_data')
73
43
  end
74
44
 
75
- def report_key
76
- '__corn_report__'
45
+ def log(msg)
46
+ $stderr.puts msg
77
47
  end
78
-
79
48
  end
metadata CHANGED
@@ -1,48 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: corn
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
5
  platform: ruby
6
- authors:
7
- - Xiao Li
6
+ authors:
7
+ - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-02 00:00:00.000000000 Z
12
- dependencies: []
11
+
12
+ date: 2014-02-08 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.0"
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.2
25
+ type: :development
26
+ version_requirements: *id001
13
27
  description: |
14
- Corn provides simple api for collecting benchmark reports and submits reports to Corn Server.
15
- email:
16
- - swing1979@gmail.com
28
+ 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
+
30
+ email:
31
+ - swing1979@gmail.com
17
32
  executables: []
33
+
18
34
  extensions: []
35
+
19
36
  extra_rdoc_files: []
20
- files:
21
- - README.md
22
- - lib/corn.rb
23
- - lib/corn/report.rb
37
+
38
+ files:
39
+ - README.md
40
+ - lib/corn.rb
24
41
  homepage: https://github.com/xli/corn
25
- licenses:
26
- - MIT
42
+ licenses:
43
+ - MIT
27
44
  metadata: {}
45
+
28
46
  post_install_message:
29
47
  rdoc_options: []
30
- require_paths:
31
- - lib
32
- required_ruby_version: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: '0'
37
- required_rubygems_version: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - &id002
54
+ - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - *id002
42
60
  requirements: []
61
+
43
62
  rubyforge_project:
44
- rubygems_version: 2.2.0
63
+ rubygems_version: 2.1.9
45
64
  signing_key:
46
65
  specification_version: 4
47
- summary: Corn is a simple benchmark report tool.
66
+ summary: Corn submits profiling data to Corn server.
48
67
  test_files: []
68
+
@@ -1,84 +0,0 @@
1
- require 'csv'
2
-
3
- module Corn
4
- class Report
5
-
6
- class RecordNotStartError < StandardError
7
- end
8
-
9
- class Record
10
- attr_reader :data
11
-
12
- def initialize(label, parent=nil)
13
- @label = label
14
- @parent = parent
15
- @data = []
16
- @start = Time.now
17
- end
18
-
19
- def push(label)
20
- Record.new(label, self)
21
- end
22
-
23
- def pop
24
- return if @parent.nil?
25
- @parent.record(@label, @start, Time.now - @start)
26
- @data.each { |d| @parent.record(*d) }
27
- @parent
28
- end
29
-
30
- def record(label, start, time)
31
- @data << [record_label(label), start, time]
32
- end
33
-
34
- private
35
- def record_label(label)
36
- [@label, label].compact.join('.').to_sym
37
- end
38
- end
39
-
40
- attr_reader :name
41
-
42
- def initialize(name)
43
- @name = name
44
- @record = Record.new(nil)
45
- end
46
-
47
- def record(label, &block)
48
- record_start(label)
49
- yield
50
- ensure
51
- record_end
52
- end
53
-
54
- def record_start(label)
55
- @record = @record.push(label)
56
- end
57
-
58
- def record_end
59
- @record = @record.pop || raise(RecordNotStartError)
60
- end
61
-
62
- def empty?
63
- to_a.empty?
64
- end
65
-
66
- def to_a
67
- @record.data
68
- end
69
-
70
- def to_csv
71
- if RUBY_VERSION =~ /1.8/
72
- buf = ''
73
- self.to_a.each do |r|
74
- CSV.generate_row(r, r.size, buf)
75
- end
76
- buf
77
- else
78
- CSV.generate do |csv|
79
- self.to_a.each { |r| csv << r }
80
- end
81
- end
82
- end
83
- end
84
- end