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 | 17 | |
7db66c58 AM |
18 | import org.eclipse.test.performance.Dimension; |
19 | import org.eclipse.test.performance.Performance; | |
20 | import org.eclipse.test.performance.PerformanceMeter; | |
680f9173 | 21 | import org.eclipse.tracecompass.ctf.core.CTFException; |
f357bcd4 | 22 | import org.eclipse.tracecompass.ctf.core.event.EventDefinition; |
c4d57ac1 | 23 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils; |
f357bcd4 AM |
24 | import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; |
25 | import org.eclipse.tracecompass.ctf.core.trace.CTFTraceReader; | |
c4d57ac1 | 26 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
7db66c58 AM |
27 | import org.junit.Test; |
28 | ||
29 | /** | |
30 | * Benchmark of the CTF parser for reading a trace | |
31 | * | |
32 | * @author Matthew Khouzam | |
33 | * @author Alexandre Montplaisir | |
34 | */ | |
35 | public class TraceReadBenchmark { | |
36 | ||
37 | private static final String TEST_SUITE_NAME = "CTF Read Benchmark"; | |
38 | private static final String TEST_ID = "org.eclipse.linuxtools#" + TEST_SUITE_NAME; | |
f14c2f97 | 39 | private static final int LOOP_COUNT = 100; |
7db66c58 AM |
40 | |
41 | /** | |
42 | * Benchmark reading the trace "kernel" | |
43 | */ | |
44 | @Test | |
45 | public void testKernelTrace() { | |
46 | readTrace(CtfTestTrace.KERNEL, "trace-kernel", true); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Benchmark reading the bigger trace "kernel_vm" | |
51 | */ | |
52 | @Test | |
53 | public void testKernelVmTrace() { | |
54 | readTrace(CtfTestTrace.KERNEL_VM, "trace-kernel-vm", false); | |
55 | } | |
56 | ||
57 | private static void readTrace(CtfTestTrace testTrace, String testName, boolean inGlobalSummary) { | |
7db66c58 AM |
58 | Performance perf = Performance.getDefault(); |
59 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName); | |
60 | perf.tagAsSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME); | |
61 | ||
62 | if (inGlobalSummary) { | |
63 | perf.tagAsGlobalSummary(pm, TEST_SUITE_NAME + ':' + testName, Dimension.CPU_TIME); | |
64 | } | |
65 | ||
66 | for (int loop = 0; loop < LOOP_COUNT; loop++) { | |
67 | pm.start(); | |
b562a24f | 68 | try { |
c4d57ac1 | 69 | CTFTrace trace = CtfTestTraceUtils.getTrace(testTrace); |
b562a24f | 70 | try (CTFTraceReader traceReader = new CTFTraceReader(trace);) { |
7db66c58 | 71 | |
b562a24f MK |
72 | while (traceReader.hasMoreEvents()) { |
73 | EventDefinition ed = traceReader.getCurrentEventDef(); | |
74 | /* Do something with the event */ | |
75 | ed.getCPU(); | |
76 | traceReader.advance(); | |
77 | } | |
7db66c58 | 78 | } |
680f9173 | 79 | } catch (CTFException e) { |
7db66c58 AM |
80 | /* Should not happen if assumeTrue() passed above */ |
81 | fail("Test failed at iteration " + loop + ':' + e.getMessage()); | |
82 | } | |
83 | pm.stop(); | |
84 | } | |
85 | pm.commit(); | |
86 | } | |
87 | } |