Commit | Line | Data |
---|---|---|
7db66c58 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012, 2014 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | * Alexandre Montplaisir - Convert to a org.eclipse.test.performance test | |
12 | *******************************************************************************/ | |
13 | ||
f357bcd4 | 14 | package org.eclipse.tracecompass.ctf.core.tests.perf.trace; |
7db66c58 AM |
15 | |
16 | import static org.junit.Assert.fail; | |
7db66c58 AM |
17 | |
18 | import java.util.LinkedList; | |
19 | import java.util.List; | |
20 | import java.util.Random; | |
21 | ||
7db66c58 AM |
22 | import org.eclipse.test.performance.Dimension; |
23 | import org.eclipse.test.performance.Performance; | |
24 | import org.eclipse.test.performance.PerformanceMeter; | |
680f9173 | 25 | import org.eclipse.tracecompass.ctf.core.CTFException; |
e8ece272 | 26 | import org.eclipse.tracecompass.ctf.core.event.IEventDefinition; |
c4d57ac1 | 27 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils; |
f357bcd4 AM |
28 | import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; |
29 | import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader; | |
c4d57ac1 | 30 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
7db66c58 AM |
31 | import org.junit.Test; |
32 | ||
33 | /** | |
34 | * Tests for performance regressions of the ctf reader. It only tests the ctf | |
b562a24f | 35 | * reader, not tmf. <br> |
7db66c58 AM |
36 | * This test runs in 3 passes. |
37 | * <ul> | |
38 | * <li>first it opens a trace</li> | |
39 | * <li>then it reads the trace completely</li> | |
b562a24f MK |
40 | * <li>then it randomly (seeded) seeks NB_SEEKS locations in the trace and reads |
41 | * one event at each position.</li> | |
7db66c58 AM |
42 | * </ul> |
43 | * | |
44 | * @author Matthew Khouzam | |
45 | * @author Alexandre Montplaisir | |
46 | */ | |
47 | public class TraceSeekBenchmark { | |
48 | ||
49 | private static final Random RND = new Random(1000); | |
50 | ||
51 | private static final int LOOP_COUNT = 25; | |
52 | private static final int NB_SEEKS = 500; | |
53 | private static final String TEST_SUITE_NAME = "CTF Read & Seek Benchmark (" + NB_SEEKS + " seeks)"; | |
54 | private static final String TEST_ID = "org.eclipse.linuxtools#" + TEST_SUITE_NAME; | |
55 | ||
56 | /** | |
57 | * Run the benchmark scenario for the trace "kernel" | |
b562a24f | 58 | * |
680f9173 | 59 | * @throws CTFException |
b562a24f | 60 | * Should not happen |
7db66c58 AM |
61 | */ |
62 | @Test | |
680f9173 | 63 | public void testKernelTrace() throws CTFException { |
7db66c58 AM |
64 | readAndSeekTrace(CtfTestTrace.KERNEL, "trace-kernel", true); |
65 | } | |
66 | ||
680f9173 | 67 | private static void readAndSeekTrace(CtfTestTrace testTrace, String testName, boolean inGlobalSummary) throws CTFException { |
7db66c58 AM |
68 | Performance perf = Performance.getDefault(); |
69 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName); | |
70 | perf.tagAsSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME); | |
71 | ||
72 | if (inGlobalSummary) { | |
73 | perf.tagAsGlobalSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME); | |
74 | } | |
75 | ||
76 | for (int loop = 0; loop < LOOP_COUNT; loop++) { | |
c4d57ac1 | 77 | CTFTrace trace = CtfTestTraceUtils.getTrace(testTrace); |
b562a24f | 78 | try (CTFTraceReader traceReader = new CTFTraceReader(trace);) { |
7db66c58 AM |
79 | |
80 | /* Read the whole trace to find out the start and end times */ | |
e8ece272 | 81 | IEventDefinition firstEvent = traceReader.getCurrentEventDef(); |
7db66c58 AM |
82 | final long startTime = firstEvent.getTimestamp(); |
83 | long endTime = startTime; | |
84 | while (traceReader.hasMoreEvents()) { | |
e8ece272 | 85 | IEventDefinition ev = traceReader.getCurrentEventDef(); |
7db66c58 AM |
86 | endTime = ev.getTimestamp(); |
87 | traceReader.advance(); | |
88 | } | |
89 | ||
90 | /* Generate the timestamps we will seek to */ | |
91 | List<Long> seekTimestamps = new LinkedList<>(); | |
92 | final long range = endTime - startTime; | |
93 | for (int i = 0; i < NB_SEEKS; i++) { | |
f2d6b526 VP |
94 | long delta = (RND.nextLong() % range); |
95 | if (delta < 0) { | |
96 | delta += range; | |
97 | } | |
98 | seekTimestamps.add(startTime + delta); | |
7db66c58 AM |
99 | } |
100 | ||
101 | /* Benchmark seeking to the generated timestamps */ | |
102 | pm.start(); | |
103 | for (Long ts : seekTimestamps) { | |
104 | traceReader.seek(ts); | |
105 | traceReader.advance(); | |
106 | } | |
107 | pm.stop(); | |
108 | ||
680f9173 | 109 | } catch (CTFException e) { |
7db66c58 AM |
110 | /* Should not happen if assumeTrue() passed above */ |
111 | fail("Test failed at iteration " + loop + ':' + e.getMessage()); | |
112 | } | |
113 | } | |
114 | pm.commit(); | |
115 | } | |
116 | } |