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