ctf: Update copyright headers and add missing ones
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceCallsitePerformanceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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.linuxtools.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assume.assumeTrue;
17
18 import java.util.List;
19 import java.util.Random;
20
21 import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
22 import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTraces;
23 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
24 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 /**
29 * Test the performance of the callsite storage in the CTF trace.
30 *
31 * @author Matthew Khouzam
32 */
33 public class CTFTraceCallsitePerformanceTest {
34
35 private static final int NUMBER_OF_SEEKS = 100000;
36
37 @SuppressWarnings("nls")
38 private final String[] callsites = { "Alligator", "Bunny", "Cat",
39 "Dolphin", "Echidna", "Gazelle", "Heron", "Ibex", "Jackalope",
40 "Koala", "Lynx", "Meerkat", "Narwhal", "Ocelot", "Pangolin",
41 "Quetzal", "Ringtail", "Sandpiper", "Tiger", "Urchin", "Vulture",
42 "Walrus", "X-Ray Tetra", "Zonkey" };
43
44 @SuppressWarnings("nls")
45 private final String[] functions = { "sentence", "together", "children",
46 "mountain", "chipmunk", "crashing", "drinking", "insisted",
47 "insulted", "invented", "squinted", "standing", "swishing",
48 "talented", "whiplash", "complain", "granddad", "sprinkle",
49 "surprise", "umbrella", "anything", "anywhere", "baseball",
50 "birthday", "bluebird", "cheerful", "colorful", "daylight",
51 "doghouse", "driveway", "everyone" };
52
53 @SuppressWarnings("nls")
54 private final String[] files = { "Adult.java", "Aeroplane.java",
55 "Air.java", "Airforce.java", "Airport.java", "Album.java",
56 "Alphabet.java", "Apple.java", "Arm.java", "Army.java", "Babby.java" };
57
58 Random rnd = new Random();
59 CTFTrace fTrace = null;
60
61 /**
62 * main, launches the tests.
63 * @param args not read
64 */
65 public static void main(String[] args) {
66 new org.junit.runner.JUnitCore().run(CTFTraceCallsitePerformanceTest.class);
67 }
68
69
70 /**
71 * sets up the test by making a new trace.
72 * @throws CTFReaderException an exception from the reader
73 * @throws SecurityException an exception from accessing files illegally
74 * @throws IllegalArgumentException an exception for passing bad values
75 */
76 @Before
77 public void setup() throws CTFReaderException, SecurityException,
78 IllegalArgumentException {
79 assumeTrue(CtfTestTraces.tracesExist());
80 fTrace = new CTFTrace(CtfTestTraces.getTraceFile().getParentFile());
81 }
82
83 private void addCallsites(int numCallsites) {
84 long stepSize = (Long.MAX_VALUE / (numCallsites + 1));
85 int jitter = (int) Math.min(stepSize, Integer.MAX_VALUE);
86 for (int i = 0; i < numCallsites; i++) {
87 final long ip = ((i)) * stepSize + rnd.nextInt(jitter);
88 fTrace.addCallsite(getRandomElement(callsites),
89 getRandomElement(functions), ip, getRandomElement(files),
90 (ip / 1000000) * 100);
91 }
92 }
93
94 private String getRandomElement(String[] array) {
95 return array[rnd.nextInt(array.length)];
96 }
97
98 private long testMain() {
99 List<CTFCallsite> l = fTrace.getCallsiteCandidates(callsites[0]);
100 CTFCallsite cs = fTrace.getCallsite(1);
101 CTFCallsite cs1 = fTrace.getCallsite(callsites[0]);
102 CTFCallsite cs2 = fTrace.getCallsite(callsites[0], 1);
103 assertNotNull(l);
104 assertNotNull(cs);
105 assertNotNull(cs1);
106 assertNotNull(cs2);
107 /* performance test */
108 long start = System.nanoTime();
109 perfTest();
110 long end = System.nanoTime();
111 long diff = end - start;
112 assertTrue(diff > 0);
113 return diff;
114 }
115
116 /**
117 * @param callsiteSize
118 */
119 private void test(int callsiteSize) {
120 addCallsites(callsiteSize);
121 long ns = testMain();
122 System.out.println( "perf ( " + callsiteSize + ", " + ns + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
123 }
124
125 private void perfTest() {
126 for (int i = 0; i < NUMBER_OF_SEEKS; i++) {
127 fTrace.getCallsite((((long) rnd.nextInt()) << 16L));
128 }
129 }
130
131 /**
132 * Test seeks with 1000 callsites
133 */
134 @Test
135 public void test1KCallsites() {
136 test(1000);
137 }
138
139 /**
140 * Test seeks with 2000 callsites
141 */
142 @Test
143 public void test2KCallsites() {
144 test(2000);
145 }
146
147 /**
148 * Test seeks with 5000 callsites
149 */
150 @Test
151 public void test5KCallsites() {
152 test(5000);
153 }
154
155 /**
156 * Test seeks with 10000 callsites
157 */
158 @Test
159 public void test10KCallsites() {
160 test(10000);
161 }
162
163 /**
164 * Test seeks with 20000 callsites
165 */
166 @Test
167 public void test20KCallsites() {
168 test(20000);
169 }
170
171 /**
172 * Test seeks with 50000 callsites
173 */
174 @Test
175 public void test50KCallsites() {
176 test(50000);
177 }
178
179 /**
180 * Test seeks with 100000 callsites
181 */
182 @Test
183 public void test100KCallsites() {
184 test(100000);
185 }
186
187 /**
188 * Test seeks with 1000000 callsites
189 */
190 @Test
191 public void test1MCallsites() {
192 test(1000000);
193 }
194
195 /**
196 * Test seeks with 2000000 callsites
197 */
198 @Test
199 public void test2MCallsites() {
200 test(2000000);
201 }
202 }
203
This page took 0.036717 seconds and 6 git commands to generate.