Differential D4028 Diff 14692 java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java
Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public void parseCommandLineArgs(String[] args) throws JSAPException { | ||||
"Benchmark tool for Software Heritage use-cases scenarios.", | "Benchmark tool for Software Heritage use-cases scenarios.", | ||||
new Parameter[]{ | new Parameter[]{ | ||||
new UnflaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | new UnflaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | ||||
JSAP.NOT_GREEDY, "The basename of the compressed graph."), | JSAP.NOT_GREEDY, "The basename of the compressed graph."), | ||||
new FlaggedOption("nbNodes", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'n', | new FlaggedOption("nbNodes", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'n', | ||||
"nb-nodes", "Number of random nodes used to do the benchmark."), | "nb-nodes", "Number of random nodes used to do the benchmark."), | ||||
new FlaggedOption("logFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'l', | new FlaggedOption("logFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'l', | ||||
"log-file", "File name to output CSV format benchmark log."), | "log-file", "File name to output CSV format benchmark log."), | ||||
new FlaggedOption("seed", JSAP.LONG_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 's', | new FlaggedOption("seed", JSAP.LONG_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 's', "seed", | ||||
"seed", "Random generator seed."), | "Random generator seed."),}); | ||||
}); | |||||
JSAPResult config = jsap.parse(args); | JSAPResult config = jsap.parse(args); | ||||
if (jsap.messagePrinted()) { | if (jsap.messagePrinted()) { | ||||
System.exit(1); | System.exit(1); | ||||
} | } | ||||
this.args.graphPath = config.getString("graphPath"); | this.args.graphPath = config.getString("graphPath"); | ||||
this.args.nbNodes = config.getInt("nbNodes"); | this.args.nbNodes = config.getInt("nbNodes"); | ||||
this.args.logFile = config.getString("logFile"); | this.args.logFile = config.getString("logFile"); | ||||
this.args.random = config.contains("seed") ? new Random(config.getLong("seed")) : new Random(); | this.args.random = config.contains("seed") ? new Random(config.getLong("seed")) : new Random(); | ||||
} | } | ||||
/** | /** | ||||
* Creates CSV file for log output. | * Creates CSV file for log output. | ||||
*/ | */ | ||||
public void createCSVLogFile() throws IOException { | public void createCSVLogFile() throws IOException { | ||||
try (Writer csvLog = new BufferedWriter(new FileWriter(args.logFile))) { | try (Writer csvLog = new BufferedWriter(new FileWriter(args.logFile))) { | ||||
StringJoiner csvHeader = new StringJoiner(CSV_SEPARATOR); | StringJoiner csvHeader = new StringJoiner(CSV_SEPARATOR); | ||||
csvHeader.add("use case name") | csvHeader.add("use case name").add("SWHID").add("number of edges accessed").add("traversal timing") | ||||
.add("SWHID") | .add("swhid2node timing").add("node2swhid timing"); | ||||
.add("number of edges accessed") | |||||
.add("traversal timing") | |||||
.add("swhid2node timing") | |||||
.add("node2swhid timing"); | |||||
csvLog.write(csvHeader.toString() + "\n"); | csvLog.write(csvHeader.toString() + "\n"); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Times a specific endpoint and outputs individual datapoints along with aggregated statistics. | * Times a specific endpoint and outputs individual datapoints along with aggregated statistics. | ||||
* | * | ||||
* @param useCaseName benchmark use-case name | * @param useCaseName benchmark use-case name | ||||
* @param graph compressed graph used in the benchmark | * @param graph compressed graph used in the benchmark | ||||
* @param nodeIds node ids to use as starting point for the endpoint traversal | * @param nodeIds node ids to use as starting point for the endpoint traversal | ||||
* @param operation endpoint function to benchmark | * @param operation endpoint function to benchmark | ||||
* @param dstFmt destination formatted string as described in the <a | * @param dstFmt destination formatted string as described in the | ||||
* href="https://docs.softwareheritage.org/devel/swh-graph/api.html#walk">API</a> | * <a href="https://docs.softwareheritage.org/devel/swh-graph/api.html#walk">API</a> | ||||
* @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") | * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") | ||||
*/ | */ | ||||
public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, | public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, | ||||
Function<Endpoint.Input, Endpoint.Output> operation, String dstFmt, String algorithm) | Function<Endpoint.Input, Endpoint.Output> operation, String dstFmt, String algorithm) throws IOException { | ||||
throws IOException { | |||||
ArrayList<Double> timings = new ArrayList<>(); | ArrayList<Double> timings = new ArrayList<>(); | ||||
ArrayList<Double> timingsNormalized = new ArrayList<>(); | ArrayList<Double> timingsNormalized = new ArrayList<>(); | ||||
ArrayList<Double> nbEdgesAccessed = new ArrayList<>(); | ArrayList<Double> nbEdgesAccessed = new ArrayList<>(); | ||||
final boolean append = true; | final boolean append = true; | ||||
try (Writer csvLog = new BufferedWriter(new FileWriter(args.logFile, append))) { | try (Writer csvLog = new BufferedWriter(new FileWriter(args.logFile, append))) { | ||||
for (long nodeId : nodeIds) { | for (long nodeId : nodeIds) { | ||||
SWHID swhid = graph.getSWHID(nodeId); | SWHID swhid = graph.getSWHID(nodeId); | ||||
Endpoint.Output output = (dstFmt == null) | Endpoint.Output output = (dstFmt == null) | ||||
? operation.apply(new Endpoint.Input(swhid)) | ? operation.apply(new Endpoint.Input(swhid)) | ||||
: operation.apply(new Endpoint.Input(swhid, dstFmt, algorithm)); | : operation.apply(new Endpoint.Input(swhid, dstFmt, algorithm)); | ||||
StringJoiner csvLine = new StringJoiner(CSV_SEPARATOR); | StringJoiner csvLine = new StringJoiner(CSV_SEPARATOR); | ||||
csvLine.add(useCaseName) | csvLine.add(useCaseName).add(swhid.toString()).add(Long.toString(output.meta.nbEdgesAccessed)) | ||||
.add(swhid.toString()) | |||||
.add(Long.toString(output.meta.nbEdgesAccessed)) | |||||
.add(Double.toString(output.meta.timings.traversal)) | .add(Double.toString(output.meta.timings.traversal)) | ||||
.add(Double.toString(output.meta.timings.swhid2node)) | .add(Double.toString(output.meta.timings.swhid2node)) | ||||
.add(Double.toString(output.meta.timings.node2swhid)); | .add(Double.toString(output.meta.timings.node2swhid)); | ||||
csvLog.write(csvLine.toString() + "\n"); | csvLog.write(csvLine.toString() + "\n"); | ||||
timings.add(output.meta.timings.traversal); | timings.add(output.meta.timings.traversal); | ||||
nbEdgesAccessed.add((double) output.meta.nbEdgesAccessed); | nbEdgesAccessed.add((double) output.meta.nbEdgesAccessed); | ||||
if (output.meta.nbEdgesAccessed != 0) { | if (output.meta.nbEdgesAccessed != 0) { | ||||
Show All 16 Lines | public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, | ||||
Statistics statsNbEdgesAccessed = new Statistics(nbEdgesAccessed); | Statistics statsNbEdgesAccessed = new Statistics(nbEdgesAccessed); | ||||
statsNbEdgesAccessed.printAll(); | statsNbEdgesAccessed.printAll(); | ||||
} | } | ||||
/** | /** | ||||
* Same as {@link #timeEndpoint} but without destination or algorithm specified to endpoint call. | * Same as {@link #timeEndpoint} but without destination or algorithm specified to endpoint call. | ||||
*/ | */ | ||||
public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, | public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, | ||||
Function<Endpoint.Input, Endpoint.Output> operation) throws IOException { | Function<Endpoint.Input, Endpoint.Output> operation) throws IOException { | ||||
timeEndpoint(useCaseName, graph, nodeIds, operation, null, null); | timeEndpoint(useCaseName, graph, nodeIds, operation, null, null); | ||||
} | } | ||||
/** | /** | ||||
* Input arguments. | * Input arguments. | ||||
*/ | */ | ||||
public class Args { | public class Args { | ||||
/** Basename of the compressed graph */ | /** Basename of the compressed graph */ | ||||
Show All 9 Lines |