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



106
107
108
109
110
111
112
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 106

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



100
101
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 100

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 77

def on_test_finish(worker, result)
  return if result.benchmarks.empty?
  print(",") unless @first_benchmark
  puts
  benchmarks = result.benchmarks.collect do |benchmark|
    name = "#{worker.suite_name}/#{result.test_name}"
    <<-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
  print(benchmarks.join(",\n"))
  @first_benchmark = false
end

#on_test_leak(worker, result) ⇒ Object



68
69
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 68

def on_test_leak(worker, result)
end

#on_test_no_check(worker, result) ⇒ Object



74
75
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 74

def on_test_no_check(worker, result)
end

#on_test_omission(worker, result) ⇒ Object



71
72
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 71

def on_test_omission(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



103
104
# File 'lib/grntest/reporters/benchmark-json-reporter.rb', line 103

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