Commit | Line | Data |
---|---|---|
4bd7f2db | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Ericsson |
4bd7f2db AM |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Matthew Khouzam - Initial API and implementation | |
10 | *******************************************************************************/ | |
11 | ||
5c0140dc | 12 | package org.eclipse.tracecompass.ctf.core.tests.perf.trace; |
4c9d2941 MK |
13 | |
14 | import static org.junit.Assert.assertNotNull; | |
e5acb357 | 15 | import static org.junit.Assume.assumeTrue; |
4c9d2941 | 16 | |
4c9d2941 | 17 | import java.util.Random; |
890f9136 | 18 | import java.util.TreeSet; |
4c9d2941 | 19 | |
5c0140dc MK |
20 | import org.eclipse.test.performance.Dimension; |
21 | import org.eclipse.test.performance.Performance; | |
22 | import org.eclipse.test.performance.PerformanceMeter; | |
680f9173 | 23 | import org.eclipse.tracecompass.ctf.core.CTFException; |
f357bcd4 AM |
24 | import org.eclipse.tracecompass.ctf.core.event.CTFCallsite; |
25 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace; | |
f357bcd4 | 26 | import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; |
4c9d2941 MK |
27 | import org.junit.Before; |
28 | import org.junit.Test; | |
29 | ||
30 | /** | |
31 | * Test the performance of the callsite storage in the CTF trace. | |
4c9d2941 | 32 | * |
4bd7f2db | 33 | * @author Matthew Khouzam |
4c9d2941 MK |
34 | */ |
35 | public class CTFTraceCallsitePerformanceTest { | |
36 | ||
5c0140dc MK |
37 | private static final String TEST_SUITE_NAME = "CTF Callsite Benchmark"; |
38 | private static final String TEST_ID = "org.eclipse.linuxtools#" + TEST_SUITE_NAME; | |
39 | ||
9ac63b5b AM |
40 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
41 | ||
4c9d2941 MK |
42 | private static final int NUMBER_OF_SEEKS = 100000; |
43 | ||
4c9d2941 MK |
44 | private final String[] callsites = { "Alligator", "Bunny", "Cat", |
45 | "Dolphin", "Echidna", "Gazelle", "Heron", "Ibex", "Jackalope", | |
46 | "Koala", "Lynx", "Meerkat", "Narwhal", "Ocelot", "Pangolin", | |
47 | "Quetzal", "Ringtail", "Sandpiper", "Tiger", "Urchin", "Vulture", | |
48 | "Walrus", "X-Ray Tetra", "Zonkey" }; | |
49 | ||
4c9d2941 MK |
50 | private final String[] functions = { "sentence", "together", "children", |
51 | "mountain", "chipmunk", "crashing", "drinking", "insisted", | |
52 | "insulted", "invented", "squinted", "standing", "swishing", | |
53 | "talented", "whiplash", "complain", "granddad", "sprinkle", | |
54 | "surprise", "umbrella", "anything", "anywhere", "baseball", | |
55 | "birthday", "bluebird", "cheerful", "colorful", "daylight", | |
56 | "doghouse", "driveway", "everyone" }; | |
57 | ||
4c9d2941 MK |
58 | private final String[] files = { "Adult.java", "Aeroplane.java", |
59 | "Air.java", "Airforce.java", "Airport.java", "Album.java", | |
60 | "Alphabet.java", "Apple.java", "Arm.java", "Army.java", "Babby.java" }; | |
61 | ||
62 | Random rnd = new Random(); | |
63 | CTFTrace fTrace = null; | |
64 | ||
65 | /** | |
66 | * main, launches the tests. | |
5c0140dc MK |
67 | * |
68 | * @param args | |
69 | * not read | |
4c9d2941 MK |
70 | */ |
71 | public static void main(String[] args) { | |
72 | new org.junit.runner.JUnitCore().run(CTFTraceCallsitePerformanceTest.class); | |
73 | } | |
74 | ||
4c9d2941 MK |
75 | /** |
76 | * sets up the test by making a new trace. | |
5c0140dc | 77 | * |
680f9173 | 78 | * @throws CTFException |
5c0140dc MK |
79 | * an exception from the reader |
80 | * @throws SecurityException | |
81 | * an exception from accessing files illegally | |
82 | * @throws IllegalArgumentException | |
83 | * an exception for passing bad values | |
4c9d2941 MK |
84 | */ |
85 | @Before | |
680f9173 | 86 | public void setup() throws CTFException, SecurityException, |
4c9d2941 | 87 | IllegalArgumentException { |
9ac63b5b AM |
88 | assumeTrue(testTrace.exists()); |
89 | fTrace = new CTFTrace(testTrace.getPath()); | |
4c9d2941 MK |
90 | } |
91 | ||
92 | private void addCallsites(int numCallsites) { | |
93 | long stepSize = (Long.MAX_VALUE / (numCallsites + 1)); | |
94 | int jitter = (int) Math.min(stepSize, Integer.MAX_VALUE); | |
95 | for (int i = 0; i < numCallsites; i++) { | |
96 | final long ip = ((i)) * stepSize + rnd.nextInt(jitter); | |
97 | fTrace.addCallsite(getRandomElement(callsites), | |
98 | getRandomElement(functions), ip, getRandomElement(files), | |
99 | (ip / 1000000) * 100); | |
100 | } | |
101 | } | |
102 | ||
103 | private String getRandomElement(String[] array) { | |
104 | return array[rnd.nextInt(array.length)]; | |
105 | } | |
106 | ||
5c0140dc | 107 | private void testMain(PerformanceMeter pm) { |
890f9136 | 108 | TreeSet<CTFCallsite> l = fTrace.getCallsiteCandidates(callsites[0]); |
4c9d2941 MK |
109 | CTFCallsite cs = fTrace.getCallsite(1); |
110 | CTFCallsite cs1 = fTrace.getCallsite(callsites[0]); | |
111 | CTFCallsite cs2 = fTrace.getCallsite(callsites[0], 1); | |
112 | assertNotNull(l); | |
113 | assertNotNull(cs); | |
114 | assertNotNull(cs1); | |
115 | assertNotNull(cs2); | |
116 | /* performance test */ | |
5c0140dc | 117 | pm.start(); |
4c9d2941 | 118 | perfTest(); |
5c0140dc | 119 | pm.stop(); |
4c9d2941 MK |
120 | } |
121 | ||
122 | /** | |
123 | * @param callsiteSize | |
124 | */ | |
125 | private void test(int callsiteSize) { | |
5c0140dc | 126 | String testName = "Test" + callsiteSize + " callsites"; |
4c9d2941 | 127 | addCallsites(callsiteSize); |
5c0140dc MK |
128 | Performance perf = Performance.getDefault(); |
129 | PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName); | |
130 | perf.tagAsSummary(pm, TEST_SUITE_NAME + ':' + callsiteSize + " callsites", Dimension.CPU_TIME); | |
131 | testMain(pm); | |
132 | pm.commit(); | |
4c9d2941 MK |
133 | } |
134 | ||
135 | private void perfTest() { | |
136 | for (int i = 0; i < NUMBER_OF_SEEKS; i++) { | |
137 | fTrace.getCallsite((((long) rnd.nextInt()) << 16L)); | |
138 | } | |
139 | } | |
140 | ||
141 | /** | |
142 | * Test seeks with 1000 callsites | |
143 | */ | |
144 | @Test | |
145 | public void test1KCallsites() { | |
5c0140dc | 146 | |
4c9d2941 MK |
147 | test(1000); |
148 | } | |
149 | ||
150 | /** | |
151 | * Test seeks with 2000 callsites | |
152 | */ | |
153 | @Test | |
154 | public void test2KCallsites() { | |
155 | test(2000); | |
156 | } | |
157 | ||
158 | /** | |
159 | * Test seeks with 5000 callsites | |
160 | */ | |
161 | @Test | |
162 | public void test5KCallsites() { | |
163 | test(5000); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Test seeks with 10000 callsites | |
168 | */ | |
169 | @Test | |
170 | public void test10KCallsites() { | |
171 | test(10000); | |
172 | } | |
173 | ||
174 | /** | |
175 | * Test seeks with 20000 callsites | |
176 | */ | |
177 | @Test | |
178 | public void test20KCallsites() { | |
179 | test(20000); | |
180 | } | |
181 | ||
182 | /** | |
183 | * Test seeks with 50000 callsites | |
184 | */ | |
185 | @Test | |
186 | public void test50KCallsites() { | |
187 | test(50000); | |
188 | } | |
189 | ||
190 | /** | |
191 | * Test seeks with 100000 callsites | |
192 | */ | |
193 | @Test | |
194 | public void test100KCallsites() { | |
195 | test(100000); | |
196 | } | |
197 | ||
198 | /** | |
199 | * Test seeks with 1000000 callsites | |
200 | */ | |
201 | @Test | |
202 | public void test1MCallsites() { | |
203 | test(1000000); | |
204 | } | |
205 | ||
206 | /** | |
207 | * Test seeks with 2000000 callsites | |
208 | */ | |
209 | @Test | |
210 | public void test2MCallsites() { | |
211 | test(2000000); | |
212 | } | |
4c9d2941 | 213 | } |