blob: 5bd407ae0fd09a87379f178f220d39736927ae07 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package com.yahoo.vespa.hosted.node.verification.hardware;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.vespa.hosted.node.verification.commons.CommandExecutor;
import com.yahoo.vespa.hosted.node.verification.hardware.benchmarks.Benchmark;
import com.yahoo.vespa.hosted.node.verification.hardware.benchmarks.BenchmarkResults;
import com.yahoo.vespa.hosted.node.verification.hardware.benchmarks.CPUBenchmark;
import com.yahoo.vespa.hosted.node.verification.hardware.benchmarks.DiskBenchmark;
import com.yahoo.vespa.hosted.node.verification.hardware.benchmarks.MemoryBenchmark;
import com.yahoo.vespa.hosted.node.verification.hardware.report.BenchmarkReport;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Benchmarks different hardware components and creates report
*/
public class HardwareBenchmarker {
public static boolean hardwareBenchmarks(CommandExecutor commandExecutor) {
BenchmarkResults benchmarkResults = new BenchmarkResults();
ArrayList<Benchmark> benchmarks = new ArrayList<>(Arrays.asList(
new DiskBenchmark(benchmarkResults, commandExecutor),
new CPUBenchmark(benchmarkResults, commandExecutor),
new MemoryBenchmark(benchmarkResults, commandExecutor)));
for (Benchmark benchmark : benchmarks) {
benchmark.doBenchmark();
}
BenchmarkReport benchmarkReport = BenchmarkResultInspector.makeBenchmarkReport(benchmarkResults);
printBenchmarkResults(benchmarkReport);
return isAllBenchmarksOK(benchmarkReport);
}
private static boolean isAllBenchmarksOK(BenchmarkReport benchmarkReport) {
ObjectMapper om = new ObjectMapper();
try {
String jsonReport = om.writeValueAsString(benchmarkReport);
return jsonReport.length() == 2;
} catch (JsonProcessingException e){
e.printStackTrace();
return false;
}
}
private static void printBenchmarkResults(BenchmarkReport benchmarkReport) {
ObjectMapper om = new ObjectMapper();
try {
System.out.println(om.writeValueAsString(benchmarkReport));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CommandExecutor commandExecutor = new CommandExecutor();
if (!HardwareBenchmarker.hardwareBenchmarks(commandExecutor)){
System.exit(2);
}
}
}
|