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
.Random
;
19 import java
.util
.TreeSet
;
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 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" };
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" };
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" };
55 Random rnd
= new Random();
56 CTFTrace fTrace
= null;
59 * main, launches the tests.
60 * @param args not read
62 public static void main(String
[] args
) {
63 new org
.junit
.runner
.JUnitCore().run(CTFTraceCallsitePerformanceTest
.class);
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
74 public void setup() throws CTFReaderException
, SecurityException
,
75 IllegalArgumentException
{
76 assumeTrue(CtfTestTraces
.tracesExist());
77 fTrace
= new CTFTrace(CtfTestTraces
.getTraceFile().getParentFile());
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);
91 private String
getRandomElement(String
[] array
) {
92 return array
[rnd
.nextInt(array
.length
)];
95 private long testMain() {
96 TreeSet
<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);
104 /* performance test */
105 long start
= System
.nanoTime();
107 long end
= System
.nanoTime();
108 long diff
= end
- start
;
109 assertTrue(diff
> 0);
114 * @param callsiteSize
116 private void test(int callsiteSize
) {
117 addCallsites(callsiteSize
);
118 long ns
= testMain();
119 System
.out
.println( "perf ( " + callsiteSize
+ ", " + ns
+ ")");
122 private void perfTest() {
123 for (int i
= 0; i
< NUMBER_OF_SEEKS
; i
++) {
124 fTrace
.getCallsite((((long) rnd
.nextInt()) << 16L));
129 * Test seeks with 1000 callsites
132 public void test1KCallsites() {
137 * Test seeks with 2000 callsites
140 public void test2KCallsites() {
145 * Test seeks with 5000 callsites
148 public void test5KCallsites() {
153 * Test seeks with 10000 callsites
156 public void test10KCallsites() {
161 * Test seeks with 20000 callsites
164 public void test20KCallsites() {
169 * Test seeks with 50000 callsites
172 public void test50KCallsites() {
177 * Test seeks with 100000 callsites
180 public void test100KCallsites() {
185 * Test seeks with 1000000 callsites
188 public void test1MCallsites() {
193 * Test seeks with 2000000 callsites
196 public void test2MCallsites() {