diff options
author | Matthew Khouzam | 2014-03-20 15:03:50 +0000 |
---|---|---|
committer | Matthew Khouzam | 2014-03-31 21:34:05 +0000 |
commit | 927744ff36f5f5b3ddd7bad890a8bff07ac0773e (patch) | |
tree | dae69851d50a3d4f37c2e62735526668e9c69e36 | |
parent | ccfa6aacb8d12643b140df13d3e03238835558b7 (diff) | |
download | org.eclipse.linuxtools-927744ff36f5f5b3ddd7bad890a8bff07ac0773e.tar.gz org.eclipse.linuxtools-927744ff36f5f5b3ddd7bad890a8bff07ac0773e.tar.xz org.eclipse.linuxtools-927744ff36f5f5b3ddd7bad890a8bff07ac0773e.zip |
ctf: mini benchmark for performance regressions
Change-Id: I951e3abe0f51e7e267411d416e0bccd83f8327c7
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/23662
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
IP-Clean: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
-rw-r--r-- | lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTraceBenchmark.java | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTraceBenchmark.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTraceBenchmark.java new file mode 100644 index 0000000000..efdd843b5a --- /dev/null +++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTraceBenchmark.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.ctf.core.tests.headless; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Random; +import java.util.Vector; + +import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; + +/** + * Tests for performance regressions of the ctf reader. It only tests the ctf + * reader, not tmf. You can give it the arguments : <b>trace path</b>(trace to + * read), <b>output file</b>(the path to the resulting output) and <b>title</b> + * (The name of this benchmark run) <br> + * <br> + * This test runs in 3 passes. + * <ul> + * <li>first it opens a trace</li> + * <li>then it reads the trace completely</li> + * <li>then it randomly (seeded) seeks 1000 locations in the trace and reads one + * event after</li> + * </ul> + * + * @author Matthew Khouzam + * + */ +public class ReadTraceBenchmark { + + /** + * @param args + * Tracepath, where to store, title + * @throws IOException + * file not found or such + */ + public static void main(String[] args) throws IOException { + String tracePath = "traces/kernel"; + String outFile = "results.csv"; + String title = "run a"; + Random random = new Random(1000); + if (args.length > 0) { + tracePath = args[0]; + } + if (args.length > 1) { + outFile = args[1]; + } + if (args.length > 2) { + title = args[2]; + } + + final int LOOP_COUNT = 4; + + Vector<Long> timestamps = new Vector<>(); + for (int i = 0; i < 500; i++) { + long start = 4277198419110L; + long range = 4287422865814L - 4277198419110L; + timestamps.add(start + (random.nextLong() % range)); + } + + // Work variables + long nbEvent = 0L; + Vector<Long> openTime = new Vector<>(); + Vector<Double> benchs = new Vector<>(); + Vector<Double> seeks = new Vector<>(); + CTFTrace trace = null; + long start, stop; + double time; + for (int loops = 0; loops < LOOP_COUNT; loops++) { + start = System.nanoTime(); + try { + nbEvent = 0L; + trace = new CTFTrace(tracePath); + } catch (CTFReaderException e) { + // do nothing + } + stop = System.nanoTime(); + openTime.add(stop - start); + start = System.nanoTime(); + try { + if (trace != null) { + CTFTraceReader traceReader = new CTFTraceReader(trace); + + start = System.nanoTime(); + + while (traceReader.hasMoreEvents()) { + traceReader.getCurrentEventDef(); + nbEvent++; + traceReader.advance(); + } + stop = System.nanoTime(); + + time = (stop - start) / (double) nbEvent; + benchs.add(time); + start = System.nanoTime(); + for (Long ts : timestamps) { + traceReader.seek(ts); + traceReader.advance(); + } + stop = System.nanoTime(); + seeks.add((double) (stop - start) / timestamps.size()); + } + } catch (CTFReaderException e) { + System.out.println("error"); + } + } + System.out.println(""); + double avg = 0; + for (Double val : benchs) { + avg += val; + } + avg /= benchs.size(); + System.out.println("Time to read " + nbEvent + " events = " + avg + + " ns/event"); + File output = new File(outFile); + boolean writeHeader = !output.exists(); + try (FileOutputStream fos = new FileOutputStream(output, true)) { + if (writeHeader) { + fos.write(new String("title,open time(us),read time(us),seeks(us) \n").getBytes()); + } + for (int i = 0; i < LOOP_COUNT; i++) { + fos.write(new String(title + "," + openTime.get(i) * 0.001 + "," + benchs.get(i) * 0.001 + "," + seeks.get(i) * 0.001 + "\n").getBytes()); + } + } + } +} |