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