Commit | Line | Data |
---|---|---|
43d15218 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
088b4f19 | 11 | * Geneviève Bastien - Convert to JUnit performance test |
43d15218 MK |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ctf.core.tests.perf.experiment; |
43d15218 MK |
15 | |
16 | import java.io.File; | |
5d421b46 | 17 | import java.io.IOException; |
43d15218 MK |
18 | import java.util.Arrays; |
19 | import java.util.HashSet; | |
20 | import java.util.List; | |
21 | import java.util.Set; | |
22 | ||
5d421b46 | 23 | import org.eclipse.core.runtime.FileLocator; |
088b4f19 GB |
24 | import org.eclipse.test.performance.Dimension; |
25 | import org.eclipse.test.performance.Performance; | |
26 | import org.eclipse.test.performance.PerformanceMeter; | |
c4d57ac1 | 27 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
2bdf0193 AM |
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; | |
2bdf0193 | 31 | import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType; |
9722e5d7 | 32 | import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest; |
2bdf0193 | 33 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
9722e5d7 | 34 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
2bdf0193 | 35 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub; |
088b4f19 | 36 | import org.junit.Test; |
43d15218 MK |
37 | |
38 | /** | |
39 | * Coalescing benchmark | |
40 | * | |
41 | * @author Matthew Khouzam | |
43d15218 MK |
42 | */ |
43 | public class ExperimentBenchmark { | |
088b4f19 | 44 | |
b09d20dc | 45 | private static final String TEST_ID = "org.eclipse.linuxtools#Experiment benchmark#"; |
43d15218 MK |
46 | private static final int MAX_TRACES = 160; |
47 | private static final int BLOCK_SIZE = 100; | |
5d421b46 MAL |
48 | private static final String TRACES_ROOT_PATH; |
49 | static { | |
50 | try { | |
51 | TRACES_ROOT_PATH = FileLocator.toFileURL(CtfTestTrace.TRACE_EXPERIMENT.getTraceURL()).getPath(); | |
52 | } catch (IOException e) { | |
53 | throw new IllegalStateException(); | |
54 | } | |
55 | } | |
f14c2f97 MAL |
56 | private static final int SAMPLE_SIZE_SLOW = 20; |
57 | private static final int SAMPLE_SIZE = 100; | |
43d15218 | 58 | |
088b4f19 | 59 | private TmfExperimentStub fExperiment; |
43d15218 MK |
60 | |
61 | /** | |
62 | * Run the benchmark | |
63 | */ | |
088b4f19 GB |
64 | @Test |
65 | public void benchmarkExperimentSizeRequest() { | |
66 | Performance perf = Performance.getDefault(); | |
67 | ||
68 | for (int numTraces = 1; numTraces < MAX_TRACES; numTraces = (int) (1.6 * (numTraces + 1))) { | |
b09d20dc GB |
69 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + numTraces + " traces"); |
70 | perf.tagAsSummary(pm, "Experiment Benchmark:" + numTraces + " traces", Dimension.CPU_TIME); | |
088b4f19 | 71 | if ((int) (1.6 * (numTraces + 1)) > MAX_TRACES) { |
b09d20dc | 72 | perf.tagAsGlobalSummary(pm, "Experiment Benchmark:" + numTraces + " traces", Dimension.CPU_TIME); |
088b4f19 | 73 | } |
43d15218 | 74 | |
f14c2f97 MAL |
75 | int sampleSize = SAMPLE_SIZE; |
76 | if (numTraces > 20) { | |
77 | sampleSize = SAMPLE_SIZE_SLOW; | |
78 | } | |
79 | ||
80 | for (int s = 0; s < sampleSize; s++) { | |
43d15218 | 81 | |
088b4f19 GB |
82 | InnerEventRequest expReq = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND); |
83 | InnerEventRequest traceReq[] = new InnerEventRequest[numTraces]; | |
43d15218 | 84 | |
088b4f19 GB |
85 | init(numTraces); |
86 | fExperiment.sendRequest(expReq); | |
fa62dc1d | 87 | List<ITmfTrace> traces = fExperiment.getTraces(); |
088b4f19 GB |
88 | for (int i = 0; i < numTraces; i++) { |
89 | traceReq[i] = new InnerEventRequest(ITmfEvent.class, 0, ITmfEventRequest.ALL_DATA, ExecutionType.BACKGROUND); | |
fa62dc1d | 90 | traces.get(i).sendRequest(traceReq[i]); |
088b4f19 | 91 | } |
43d15218 | 92 | |
088b4f19 GB |
93 | pm.start(); |
94 | waitForRequest(expReq, traceReq); | |
95 | pm.stop(); | |
43d15218 | 96 | |
fa62dc1d BH |
97 | for (int i = 0; i < traces.size(); i++) { |
98 | if (!expReq.isTraceHandled(traces.get(i))) { | |
088b4f19 GB |
99 | System.err.println("Trace " + i + " not handled!"); |
100 | } | |
43d15218 | 101 | } |
43d15218 | 102 | |
088b4f19 GB |
103 | fExperiment.dispose(); |
104 | } | |
105 | pm.commit(); | |
43d15218 | 106 | } |
43d15218 MK |
107 | } |
108 | ||
088b4f19 GB |
109 | /** |
110 | * Initialization | |
111 | * | |
112 | * @param maxTraces | |
113 | * maximum number of traces to open | |
114 | */ | |
115 | private void init(int maxTraces) { | |
43d15218 | 116 | try { |
088b4f19 GB |
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(); | |
122 | } | |
088b4f19 GB |
123 | int j = 0; |
124 | for (int i = 0; i < (traces.length) && (j < traces.length); i++) { | |
125 | String absolutePath = traceFiles[j].getAbsolutePath(); | |
126 | if (traces[i].validate(null, absolutePath).isOK()) { | |
127 | traces[i].initTrace(null, absolutePath, ITmfEvent.class); | |
128 | } else { | |
129 | i--; | |
130 | } | |
131 | j++; | |
132 | } | |
e2b65c8f | 133 | fExperiment = new TmfExperimentStub("MegaExperiment", traces, BLOCK_SIZE); |
088b4f19 GB |
134 | if (traces[traces.length - 1].getPath() == null) { |
135 | throw new TmfTraceException("Insufficient valid traces in directory"); | |
136 | } | |
43d15218 MK |
137 | } catch (TmfTraceException e) { |
138 | System.out.println(e.getMessage()); | |
139 | } | |
43d15218 MK |
140 | } |
141 | ||
142 | private static void waitForRequest(InnerEventRequest expReq, InnerEventRequest[] traceReqs) { | |
43d15218 MK |
143 | try { |
144 | expReq.waitForCompletion(); | |
145 | List<InnerEventRequest> reqs = Arrays.asList(traceReqs); | |
146 | for (InnerEventRequest traceReq : reqs) { | |
147 | traceReq.waitForCompletion(); | |
148 | } | |
149 | } catch (InterruptedException e) { | |
150 | } | |
43d15218 MK |
151 | } |
152 | ||
153 | private static class InnerEventRequest extends TmfEventRequest { | |
154 | private Set<String> fTraces = new HashSet<>(); | |
155 | ||
156 | public InnerEventRequest(Class<? extends ITmfEvent> dataType, long index, int nbRequested, ExecutionType priority) { | |
157 | super(dataType, index, nbRequested, priority); | |
158 | } | |
159 | ||
160 | @Override | |
161 | public void handleData(ITmfEvent event) { | |
162 | super.handleData(event); | |
163 | if (!fTraces.contains(event.getTrace().getName())) { | |
164 | fTraces.add(event.getTrace().getName()); | |
165 | } | |
166 | } | |
167 | ||
168 | public boolean isTraceHandled(ITmfTrace trace) { | |
169 | return fTraces.contains(trace.getName()); | |
170 | } | |
171 | } | |
172 | } |