1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Geneviève Bastien - Convert to JUnit performance test
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.perf
.experiment
;
17 import java
.io
.IOException
;
18 import java
.util
.Arrays
;
19 import java
.util
.HashSet
;
20 import java
.util
.List
;
23 import org
.eclipse
.core
.runtime
.FileLocator
;
24 import org
.eclipse
.test
.performance
.Dimension
;
25 import org
.eclipse
.test
.performance
.Performance
;
26 import org
.eclipse
.test
.performance
.PerformanceMeter
;
27 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
35 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
36 import org
.junit
.Test
;
39 * Coalescing benchmark
41 * @author Matthew Khouzam
43 public class ExperimentBenchmark
{
45 private static final String TEST_ID
= "org.eclipse.linuxtools#Experiment benchmark#";
46 private static final int MAX_TRACES
= 160;
47 private static final int BLOCK_SIZE
= 100;
48 private static final String TRACES_ROOT_PATH
;
51 TRACES_ROOT_PATH
= FileLocator
.toFileURL(CtfTestTrace
.TRACE_EXPERIMENT
.getTraceURL()).getPath();
52 } catch (IOException e
) {
53 throw new IllegalStateException();
56 private static final int SAMPLE_SIZE_SLOW
= 20;
57 private static final int SAMPLE_SIZE
= 100;
59 private TmfExperimentStub fExperiment
;
65 public void benchmarkExperimentSizeRequest() {
66 Performance perf
= Performance
.getDefault();
68 for (int numTraces
= 1; numTraces
< MAX_TRACES
; numTraces
= (int) (1.6 * (numTraces
+ 1))) {
69 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ numTraces
+ " traces");
70 perf
.tagAsSummary(pm
, "Experiment Benchmark:" + numTraces
+ " traces", Dimension
.CPU_TIME
);
71 if ((int) (1.6 * (numTraces
+ 1)) > MAX_TRACES
) {
72 perf
.tagAsGlobalSummary(pm
, "Experiment Benchmark:" + numTraces
+ " traces", Dimension
.CPU_TIME
);
75 int sampleSize
= SAMPLE_SIZE
;
77 sampleSize
= SAMPLE_SIZE_SLOW
;
80 for (int s
= 0; s
< sampleSize
; s
++) {
82 InnerEventRequest expReq
= new InnerEventRequest(ITmfEvent
.class, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
);
83 InnerEventRequest traceReq
[] = new InnerEventRequest
[numTraces
];
86 fExperiment
.sendRequest(expReq
);
87 List
<ITmfTrace
> traces
= fExperiment
.getTraces();
88 for (int i
= 0; i
< numTraces
; i
++) {
89 traceReq
[i
] = new InnerEventRequest(ITmfEvent
.class, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
);
90 traces
.get(i
).sendRequest(traceReq
[i
]);
94 waitForRequest(expReq
, traceReq
);
97 for (int i
= 0; i
< traces
.size(); i
++) {
98 if (!expReq
.isTraceHandled(traces
.get(i
))) {
99 System
.err
.println("Trace " + i
+ " not handled!");
103 fExperiment
.dispose();
113 * maximum number of traces to open
115 private void init(int maxTraces
) {
117 File parentDir
= new File(TRACES_ROOT_PATH
);
118 File
[] traceFiles
= parentDir
.listFiles();
119 ITmfTrace
[] traces
= new CtfTmfTrace
[Math
.min(maxTraces
, traceFiles
.length
)];
120 for (int i
= 0; i
< traces
.length
; i
++) {
121 traces
[i
] = new CtfTmfTrace();
123 fExperiment
= new TmfExperimentStub("MegaExperiment", traces
, BLOCK_SIZE
);
125 for (int i
= 0; i
< (traces
.length
) && (j
< traces
.length
); i
++) {
126 String absolutePath
= traceFiles
[j
].getAbsolutePath();
127 if (traces
[i
].validate(null, absolutePath
).isOK()) {
128 traces
[i
].initTrace(null, absolutePath
, ITmfEvent
.class);
134 if (traces
[traces
.length
- 1].getPath() == null) {
135 throw new TmfTraceException("Insufficient valid traces in directory");
137 } catch (TmfTraceException e
) {
138 System
.out
.println(e
.getMessage());
142 private static void waitForRequest(InnerEventRequest expReq
, InnerEventRequest
[] traceReqs
) {
144 expReq
.waitForCompletion();
145 List
<InnerEventRequest
> reqs
= Arrays
.asList(traceReqs
);
146 for (InnerEventRequest traceReq
: reqs
) {
147 traceReq
.waitForCompletion();
149 } catch (InterruptedException e
) {
153 private static class InnerEventRequest
extends TmfEventRequest
{
154 private Set
<String
> fTraces
= new HashSet
<>();
156 public InnerEventRequest(Class
<?
extends ITmfEvent
> dataType
, long index
, int nbRequested
, ExecutionType priority
) {
157 super(dataType
, index
, nbRequested
, priority
);
161 public void handleData(ITmfEvent event
) {
162 super.handleData(event
);
163 if (!fTraces
.contains(event
.getTrace().getName())) {
164 fTraces
.add(event
.getTrace().getName());
168 public boolean isTraceHandled(ITmfTrace trace
) {
169 return fTraces
.contains(trace
.getName());