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
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertTrue
;
16 import static org
.junit
.Assume
.assumeTrue
;
18 import java
.util
.List
;
19 import java
.util
.Random
;
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
;
29 * Test the performance of the callsite storage in the CTF trace.
31 * @author Matthew Khouzam
33 public class CTFTraceCallsitePerformanceTest
{
35 private static final int NUMBER_OF_SEEKS
= 100000;
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" };
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" };
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" };
58 Random rnd
= new Random();
59 CTFTrace fTrace
= null;
62 * main, launches the tests.
63 * @param args not read
65 public static void main(String
[] args
) {
66 new org
.junit
.runner
.JUnitCore().run(CTFTraceCallsitePerformanceTest
.class);
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
77 public void setup() throws CTFReaderException
, SecurityException
,
78 IllegalArgumentException
{
79 assumeTrue(CtfTestTraces
.tracesExist());
80 fTrace
= new CTFTrace(CtfTestTraces
.getTraceFile().getParentFile());
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);
94 private String
getRandomElement(String
[] array
) {
95 return array
[rnd
.nextInt(array
.length
)];
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);
107 /* performance test */
108 long start
= System
.nanoTime();
110 long end
= System
.nanoTime();
111 long diff
= end
- start
;
112 assertTrue(diff
> 0);
117 * @param callsiteSize
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$
125 private void perfTest() {
126 for (int i
= 0; i
< NUMBER_OF_SEEKS
; i
++) {
127 fTrace
.getCallsite((((long) rnd
.nextInt()) << 16L));
132 * Test seeks with 1000 callsites
135 public void test1KCallsites() {
140 * Test seeks with 2000 callsites
143 public void test2KCallsites() {
148 * Test seeks with 5000 callsites
151 public void test5KCallsites() {
156 * Test seeks with 10000 callsites
159 public void test10KCallsites() {
164 * Test seeks with 20000 callsites
167 public void test20KCallsites() {
172 * Test seeks with 50000 callsites
175 public void test50KCallsites() {
180 * Test seeks with 100000 callsites
183 public void test100KCallsites() {
188 * Test seeks with 1000000 callsites
191 public void test1MCallsites() {
196 * Test seeks with 2000000 callsites
199 public void test2MCallsites() {