bd87f15494f43fa3cb8870c88abb61aa001c2dd6
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / perf / org / eclipse / tracecompass / ctf / core / tests / perf / trace / CTFTraceCallsitePerformanceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
12 package org.eclipse.tracecompass.ctf.core.tests.perf.trace;
13
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assume.assumeTrue;
16
17 import java.util.Random;
18 import java.util.TreeSet;
19
20 import org.eclipse.test.performance.Dimension;
21 import org.eclipse.test.performance.Performance;
22 import org.eclipse.test.performance.PerformanceMeter;
23 import org.eclipse.tracecompass.ctf.core.CTFException;
24 import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
25 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
26 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 /**
31 * Test the performance of the callsite storage in the CTF trace.
32 *
33 * @author Matthew Khouzam
34 */
35 public class CTFTraceCallsitePerformanceTest {
36
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
40 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
41
42 private static final int NUMBER_OF_SEEKS = 100000;
43
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
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
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.
67 *
68 * @param args
69 * not read
70 */
71 public static void main(String[] args) {
72 new org.junit.runner.JUnitCore().run(CTFTraceCallsitePerformanceTest.class);
73 }
74
75 /**
76 * sets up the test by making a new trace.
77 *
78 * @throws CTFException
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
84 */
85 @Before
86 public void setup() throws CTFException, SecurityException,
87 IllegalArgumentException {
88 assumeTrue(testTrace.exists());
89 fTrace = new CTFTrace(testTrace.getPath());
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
107 private void testMain(PerformanceMeter pm) {
108 TreeSet<CTFCallsite> l = fTrace.getCallsiteCandidates(callsites[0]);
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 */
117 pm.start();
118 perfTest();
119 pm.stop();
120 }
121
122 /**
123 * @param callsiteSize
124 */
125 private void test(int callsiteSize) {
126 String testName = "Test" + callsiteSize + " callsites";
127 addCallsites(callsiteSize);
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();
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() {
146
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 }
213 }
This page took 0.060231 seconds and 4 git commands to generate.