Class: Grntest::Reporters::BenchmarkJSONReporter

Inherits:
BaseReporter
  • Object
show all
Defined in:
lib/grntest/reporters/benchmark-json-reporter.rb

Instance Method Summary collapse

Methods inherited from BaseReporter

#initialize

Constructor Details

This class inherits a constructor from Grntest::Reporters::BaseReporter

Instance Method Details

#on_finish(result) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 117

def on_finish(result)
  puts
  puts(<<-JSON)
  ]
}
  JSON
end

#on_start(result) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 24

def on_start(result)
  puts(<<-JSON)
{
  "context": {
    "date": #{Time.now.iso8601.to_json},
    "host_name": #{Socket.gethostname.to_json},
    "executable": #{@tester.testee.to_json},
    "num_cpus": #{Etc.nprocessors},
  JSON
  cpu_cycles_per_second = detect_cpu_cycles_per_second
  if cpu_cycles_per_second
    puts(<<-JSON)
    "mhz_per_cpu": #{cpu_cycles_per_second / 1_000_000.0},
    JSON
  end
  print(<<-JSON.chomp)
    "caches": []
  },
  "benchmarks": [
  JSON
  @first_benchmark = true
end

#on_suite_finish(worker) ⇒ Object



111
112
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 111

def on_suite_finish(worker)
end

#on_suite_start(worker) ⇒ Object



50
51
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 50

def on_suite_start(worker)
end

#on_test_failure(worker, result) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 59

def on_test_failure(worker, result)
  output, @output = @output, $stderr
  begin
    report_failure(result)
  ensure
    @output = output
  end
end

#on_test_finish(worker, result) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 87

def on_test_finish(worker, result)
  return if result.benchmarks.empty?
  result.benchmarks.each do |benchmark|
    print(",") unless @first_benchmark
    @first_benchmark = false
    puts
    name = "#{@tester.interface}: " +
           "#{@tester.input_type}|#{@tester.output_type}: " +
           "#{worker.suite_name}/#{result.test_name}"
    print(<<-JSON.chomp)
    {
"name": #{name.to_json},
"run_name": #{benchmark.name.to_json},
"run_type": "iteration",
"iterations": #{benchmark.n_iterations},
"real_time": #{benchmark.real_elapsed_time},
"cpu_time": #{benchmark.cpu_elapsed_time},
"time_unit": "s",
"items_per_second": #{benchmark.items_per_second}
    }
    JSON
  end
end

#on_test_leak(worker, result) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 68

def on_test_leak(worker, result)
  output, @output = @output, $stderr
  begin
    puts
    report_test(worker, result)
  ensure
    @output = output
  end
end

#on_test_no_check(worker, result) ⇒ Object



84
85
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 84

def on_test_no_check(worker, result)
end

#on_test_omission(worker, result) ⇒ Object



78
79
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 78

def on_test_omission(worker, result)
end

#on_test_omission_suppressed(worker, result) ⇒ Object



81
82
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 81

def on_test_omission_suppressed(worker, result)
end

#on_test_start(worker) ⇒ Object



53
54
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 53

def on_test_start(worker)
end

#on_test_success(worker, result) ⇒ Object



56
57
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 56

def on_test_success(worker, result)
end

#on_worker_finish(worker) ⇒ Object



114
115
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 114

def on_worker_finish(worker)
end

#on_worker_start(worker) ⇒ Object



47
48
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 47

def on_worker_start(worker)
end