corn 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/lib/corn.rb +22 -53
- metadata +50 -30
- data/lib/corn/report.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6cfee2778ad98d567976a0bb9b6027da9e24472
|
4
|
+
data.tar.gz: ae18162e7ab186da5bd0e3d78db2cb594b06c96f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5cdd75cd5d47dac34bef34913c96635e4a4fb56ca26839d7b8a40985fd5fed062735be6e446ff8c96d2dbc3cd72f8f677ef023c0d3562633cca17089a23dc4a
|
7
|
+
data.tar.gz: d05aa533388a37465368baa15fa8a87495bd2c1f94b651d44261a04ff9fb1f88efa7ac874dd6c9a3f65ff345633eae25b836134abe70d90595f6a568386ce392
|
data/lib/corn.rb
CHANGED
@@ -1,79 +1,48 @@
|
|
1
|
-
require '
|
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']
|
7
|
+
ENV['CORN_HOST']
|
13
8
|
end
|
14
9
|
|
15
10
|
def client_id
|
16
|
-
ENV['CORN_CLIENT_ID']
|
11
|
+
ENV['CORN_CLIENT_ID']
|
17
12
|
end
|
18
13
|
|
19
14
|
def configured?
|
20
|
-
!!
|
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
|
32
|
-
|
33
|
-
|
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
|
40
|
-
|
41
|
-
|
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
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
68
|
-
|
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
|
76
|
-
|
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.
|
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
|
-
|
12
|
-
|
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
|
15
|
-
|
16
|
-
|
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
|
-
|
21
|
-
|
22
|
-
-
|
23
|
-
- lib/corn
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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.
|
63
|
+
rubygems_version: 2.1.9
|
45
64
|
signing_key:
|
46
65
|
specification_version: 4
|
47
|
-
summary: Corn
|
66
|
+
summary: Corn submits profiling data to Corn server.
|
48
67
|
test_files: []
|
68
|
+
|
data/lib/corn/report.rb
DELETED
@@ -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
|