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
.linuxtools
.tmf
.ctf
.core
.tests
.perf
.experiment
;
17 import java
.util
.Arrays
;
18 import java
.util
.HashSet
;
19 import java
.util
.List
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.tests
.shared
.CtfTestTrace
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
.ExecutionType
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfExperimentStub
;
31 import org
.eclipse
.test
.performance
.Dimension
;
32 import org
.eclipse
.test
.performance
.Performance
;
33 import org
.eclipse
.test
.performance
.PerformanceMeter
;
34 import org
.junit
.Test
;
37 * Coalescing benchmark
39 * @author Matthew Khouzam
41 public class ExperimentBenchmark
{
43 private static final String TEST_ID
= "org.eclipse.linuxtools#Experiment benchmark";
44 private static final int MAX_TRACES
= 160;
45 private static final int BLOCK_SIZE
= 100;
46 private static final String TRACES_ROOT_PATH
= CtfTestTrace
.TRACE_EXPERIMENT
.getPath();
47 private static final int SAMPLE_SIZE
= 5;
49 private TmfExperimentStub fExperiment
;
55 public void benchmarkExperimentSizeRequest() {
56 Performance perf
= Performance
.getDefault();
58 for (int numTraces
= 1; numTraces
< MAX_TRACES
; numTraces
= (int) (1.6 * (numTraces
+ 1))) {
59 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '(' + numTraces
+ ')');
60 perf
.tagAsSummary(pm
, "Experiment Benchmark traces:" + numTraces
, Dimension
.CPU_TIME
);
61 if ((int) (1.6 * (numTraces
+ 1)) > MAX_TRACES
) {
62 perf
.tagAsGlobalSummary(pm
, "Experiment Benchmark traces: " + numTraces
, Dimension
.CPU_TIME
);
65 for (int s
= 0; s
< SAMPLE_SIZE
; s
++) {
67 InnerEventRequest expReq
= new InnerEventRequest(ITmfEvent
.class, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
);
68 InnerEventRequest traceReq
[] = new InnerEventRequest
[numTraces
];
71 fExperiment
.sendRequest(expReq
);
72 ITmfTrace
[] traces
= fExperiment
.getTraces();
73 for (int i
= 0; i
< numTraces
; i
++) {
74 traceReq
[i
] = new InnerEventRequest(ITmfEvent
.class, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.BACKGROUND
);
75 traces
[i
].sendRequest(traceReq
[i
]);
79 waitForRequest(expReq
, traceReq
);
82 for (int i
= 0; i
< traces
.length
; i
++) {
83 if (!expReq
.isTraceHandled(traces
[i
])) {
84 System
.err
.println("Trace " + i
+ " not handled!");
88 fExperiment
.dispose();
98 * maximum number of traces to open
100 private void init(int maxTraces
) {
102 File parentDir
= new File(TRACES_ROOT_PATH
);
103 File
[] traceFiles
= parentDir
.listFiles();
104 ITmfTrace
[] traces
= new CtfTmfTrace
[Math
.min(maxTraces
, traceFiles
.length
)];
105 for (int i
= 0; i
< traces
.length
; i
++) {
106 traces
[i
] = new CtfTmfTrace();
108 fExperiment
= new TmfExperimentStub("MegaExperiment", traces
, BLOCK_SIZE
);
110 for (int i
= 0; i
< (traces
.length
) && (j
< traces
.length
); i
++) {
111 String absolutePath
= traceFiles
[j
].getAbsolutePath();
112 if (traces
[i
].validate(null, absolutePath
).isOK()) {
113 traces
[i
].initTrace(null, absolutePath
, ITmfEvent
.class);
119 if (traces
[traces
.length
- 1].getPath() == null) {
120 throw new TmfTraceException("Insufficient valid traces in directory");
122 } catch (TmfTraceException e
) {
123 System
.out
.println(e
.getMessage());
127 private static void waitForRequest(InnerEventRequest expReq
, InnerEventRequest
[] traceReqs
) {
129 expReq
.waitForCompletion();
130 List
<InnerEventRequest
> reqs
= Arrays
.asList(traceReqs
);
131 for (InnerEventRequest traceReq
: reqs
) {
132 traceReq
.waitForCompletion();
134 } catch (InterruptedException e
) {
138 private static class InnerEventRequest
extends TmfEventRequest
{
139 private Set
<String
> fTraces
= new HashSet
<>();
141 public InnerEventRequest(Class
<?
extends ITmfEvent
> dataType
, long index
, int nbRequested
, ExecutionType priority
) {
142 super(dataType
, index
, nbRequested
, priority
);
146 public void handleData(ITmfEvent event
) {
147 super.handleData(event
);
148 if (!fTraces
.contains(event
.getTrace().getName())) {
149 fTraces
.add(event
.getTrace().getName());
153 public boolean isTraceHandled(ITmfTrace trace
) {
154 return fTraces
.contains(trace
.getName());