corn 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd6bf050c9281d4d7466d536e0c21a742b49a54c
4
- data.tar.gz: 85b6e57c88e13ef0e4eef17c92bc8084b2aeb0ca
3
+ metadata.gz: 8772493b9949b6c7b4867b7c7f2c3c7efa8b5ab5
4
+ data.tar.gz: 6dc258e0d06b44a8548b6b2a9efb8e1a9daf253f
5
5
  SHA512:
6
- metadata.gz: 8397e9bf1689a62df96fd5a07e7d576ee576dd0f66c749e38f1564fb0697a6cf5d0e97ff8f5d290220c6f0f1ec1768a89de3874e11f0b4a1be71056e92a8564a
7
- data.tar.gz: 1823d6d382275608edeace1b8114e14a48baf57ba122be4ac05d048dbffaa85eb7b77ca55739ec6a7922d5c8381f4fbb14350182a0b93909a332c4149fe29e3c
6
+ metadata.gz: db292f19239353bc7eb1abc990dbd4a88f48e9afdf922d4a4833e0b7568aaa61a10d5a64bfd7ea723682e1c272c5de28a9dc306ae01a2bc786bb156b62dd605c
7
+ data.tar.gz: 2141b7349b808cef1a5e74e79096cf798e3483deb98ffa0fde3f8c22d6017026338ac1d576593345b90144f7cce257a118d5adb0d32e95a088aa8dd9ec0f0ef2
@@ -37,41 +37,23 @@ module Corn
37
37
  end
38
38
  end
39
39
 
40
- def report(test_name, &block)
41
- rep = report_start
42
- begin
43
- yield(rep)
44
- ensure
45
- report_end(test_name, rep)
46
- end
47
- end
48
-
49
- def report_start
50
- @reports ||= create_reports
51
- Report.new
40
+ def report(label, &block)
41
+ @report ||= Report.new
42
+ @report.record(label, &block)
52
43
  end
53
44
 
54
- def report_end(test_name, report)
55
- @reports << [test_name] + report.records.flatten
45
+ def exit_submit_hook
46
+ at_exit { submit }
56
47
  end
57
48
 
58
- def create_reports
59
- at_exit { submit_reports }
60
- []
61
- end
62
-
63
- def submit_reports
64
- return if @reports.nil? || @reports.empty?
49
+ def submit(report=@report)
50
+ return if report.empty?
65
51
  log_error do
66
- reports_csv = CSV.generate do |csv|
67
- @reports.each do |rep|
68
- csv << rep
69
- end
70
- end
71
- data = { client_id: client_id,
72
- build_label: build_label,
73
- reports: reports_csv }
74
- @reports = []
52
+ data = {
53
+ :client_id => client_id,
54
+ :build_label => build_label,
55
+ :reports => report.to_csv
56
+ }
75
57
  http_post(File.join(host, 'benchmarks'), data)
76
58
  end
77
59
  end
@@ -6,28 +6,29 @@ module Corn
6
6
  end
7
7
 
8
8
  def run_with_corn(runner, &block)
9
- Corn.report("#{__name__}(#{self.class.name})") do |report|
10
- @__corn_report__ = report
9
+ label = "#{self.class.name}.#{__name__}"
10
+ Corn.report(label) do |report|
11
+ @corn_report = report
11
12
  run_without_corn(runner, &block)
12
13
  end
13
14
  end
14
15
 
15
16
  def before_setup
16
- @__corn_report__.record_start(:setup)
17
+ @corn_report.record_start(:setup)
17
18
  end
18
19
 
19
20
  def after_setup
20
- @__corn_report__.record_end
21
- @__corn_report__.record_start(:run_test)
21
+ @corn_report.record_end
22
+ @corn_report.record_start(:run_test)
22
23
  end
23
24
 
24
25
  def before_teardown
25
- @__corn_report__.record_end
26
- @__corn_report__.record_start(:teardown)
26
+ @corn_report.record_end
27
+ @corn_report.record_start(:teardown)
27
28
  end
28
29
 
29
30
  def after_teardown
30
- @__corn_report__.record_end
31
+ @corn_report.record_end
31
32
  end
32
33
  end
33
34
  end
@@ -1,29 +1,66 @@
1
+ require 'csv'
2
+
1
3
  module Corn
2
4
  class Report
3
- attr_reader :records
4
5
 
5
- def initialize
6
+ def initialize(prefix=nil)
7
+ @prefix = prefix
6
8
  @records = []
7
9
  end
8
10
 
9
11
  def record(label, &block)
10
12
  record_start(label)
11
- yield
13
+ yield(sub_report)
12
14
  ensure
13
15
  record_end
14
16
  end
15
17
 
18
+ # start record a benchmark time by label
16
19
  def record_start(label)
17
- @record = [label, Time.now]
20
+ @record = [record_label(label), Time.now]
21
+ end
22
+
23
+ # should only be called between record_start and record_end to generate
24
+ # sub report for current report
25
+ def sub_report
26
+ @sub_report ||= Report.new(@record[0])
18
27
  end
19
28
 
29
+ # should only be called after record_start
20
30
  def record_end
21
31
  @record << Time.now - @record[1]
22
32
  @records << @record
33
+ if @sub_report
34
+ @records.concat @sub_report.to_a
35
+ @sub_report = nil
36
+ end
37
+ end
38
+
39
+ def empty?
40
+ @records.empty?
41
+ end
42
+
43
+ def to_a
44
+ @records
45
+ end
46
+
47
+ def to_csv
48
+ if RUBY_VERSION =~ /1.8/
49
+ buf = ''
50
+ @records.each do |r|
51
+ CSV.generate_row(r, r.size, buf)
52
+ end
53
+ buf
54
+ else
55
+ CSV.generate do |csv|
56
+ @records.each { |r| csv << r }
57
+ end
58
+ end
23
59
  end
24
60
 
25
- def record_time
26
- Time.now - @start_at
61
+ private
62
+ def record_label(label)
63
+ [@prefix, label].compact.join('.').to_sym
27
64
  end
28
65
  end
29
66
  end
@@ -8,7 +8,8 @@ module Corn
8
8
  end
9
9
 
10
10
  def run_with_corn(result, &block)
11
- Corn.report(name) do |report|
11
+ label = "#{self.class.name}.#{@method_name}"
12
+ Corn.report(label) do |report|
12
13
  __run_with_corn__(report, result, &block)
13
14
  end
14
15
  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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li