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