1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Convert to a org.eclipse.test.performance test
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.perf
.trace
;
16 import static org
.junit
.Assert
.fail
;
17 import static org
.junit
.Assume
.assumeTrue
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.shared
.CtfTestTrace
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
24 import org
.eclipse
.test
.performance
.Dimension
;
25 import org
.eclipse
.test
.performance
.Performance
;
26 import org
.eclipse
.test
.performance
.PerformanceMeter
;
27 import org
.junit
.Test
;
30 * Benchmark of the CTF parser for reading a trace
32 * @author Matthew Khouzam
33 * @author Alexandre Montplaisir
35 public class TraceReadBenchmark
{
37 private static final String TEST_SUITE_NAME
= "CTF Read Benchmark";
38 private static final String TEST_ID
= "org.eclipse.linuxtools#" + TEST_SUITE_NAME
;
39 private static final int LOOP_COUNT
= 100;
42 * Benchmark reading the trace "kernel"
45 public void testKernelTrace() {
46 readTrace(CtfTestTrace
.KERNEL
, "trace-kernel", true);
50 * Benchmark reading the bigger trace "kernel_vm"
53 public void testKernelVmTrace() {
54 readTrace(CtfTestTrace
.KERNEL_VM
, "trace-kernel-vm", false);
57 private static void readTrace(CtfTestTrace testTrace
, String testName
, boolean inGlobalSummary
) {
58 assumeTrue(testTrace
.exists());
60 Performance perf
= Performance
.getDefault();
61 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
62 perf
.tagAsSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
64 if (inGlobalSummary
) {
65 perf
.tagAsGlobalSummary(pm
, TEST_SUITE_NAME
+ ':' + testName
, Dimension
.CPU_TIME
);
68 for (int loop
= 0; loop
< LOOP_COUNT
; loop
++) {
70 try (CTFTrace trace
= testTrace
.getTrace();
71 CTFTraceReader traceReader
= new CTFTraceReader(trace
);) {
73 while (traceReader
.hasMoreEvents()) {
74 EventDefinition ed
= traceReader
.getCurrentEventDef();
75 /* Do something with the event */
77 traceReader
.advance();
80 } catch (CTFReaderException e
) {
81 /* Should not happen if assumeTrue() passed above */
82 fail("Test failed at iteration " + loop
+ ':' + e
.getMessage());