1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
3 import static org
.junit
.Assert
.assertNotNull
;
4 import static org
.junit
.Assert
.assertTrue
;
5 import static org
.junit
.Assume
.assumeTrue
;
8 import java
.util
.Random
;
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
;
18 * Test the performance of the callsite storage in the CTF trace.
19 * @author Matthew Khouzam
22 public class CTFTraceCallsitePerformanceTest
{
24 private static final int NUMBER_OF_SEEKS
= 100000;
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" };
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" };
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" };
47 Random rnd
= new Random();
48 CTFTrace fTrace
= null;
51 * main, launches the tests.
52 * @param args not read
54 public static void main(String
[] args
) {
55 new org
.junit
.runner
.JUnitCore().run(CTFTraceCallsitePerformanceTest
.class);
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
66 public void setup() throws CTFReaderException
, SecurityException
,
67 IllegalArgumentException
{
68 assumeTrue(TestParams
.tracesExist());
69 fTrace
= new CTFTrace(TestParams
.getTraceFile().getParentFile());
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);
83 private String
getRandomElement(String
[] array
) {
84 return array
[rnd
.nextInt(array
.length
)];
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);
96 /* performance test */
97 long start
= System
.nanoTime();
99 long end
= System
.nanoTime();
100 long diff
= end
- start
;
101 assertTrue(diff
> 0);
106 * @param callsiteSize
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$
114 private void perfTest() {
115 for (int i
= 0; i
< NUMBER_OF_SEEKS
; i
++) {
116 fTrace
.getCallsite((((long) rnd
.nextInt()) << 16L));
121 * Test seeks with 1000 callsites
124 public void test1KCallsites() {
129 * Test seeks with 2000 callsites
132 public void test2KCallsites() {
137 * Test seeks with 5000 callsites
140 public void test5KCallsites() {
145 * Test seeks with 10000 callsites
148 public void test10KCallsites() {
153 * Test seeks with 20000 callsites
156 public void test20KCallsites() {
161 * Test seeks with 50000 callsites
164 public void test50KCallsites() {
169 * Test seeks with 100000 callsites
172 public void test100KCallsites() {
177 * Test seeks with 1000000 callsites
180 public void test1MCallsites() {
185 * Test seeks with 2000000 callsites
188 public void test2MCallsites() {