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
.CtfTestTrace
;
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 CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
37 private static final int NUMBER_OF_SEEKS
= 100000;
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" };
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 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" };
57 Random rnd
= new Random();
58 CTFTrace fTrace
= null;
61 * main, launches the tests.
62 * @param args not read
64 public static void main(String
[] args
) {
65 new org
.junit
.runner
.JUnitCore().run(CTFTraceCallsitePerformanceTest
.class);
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
76 public void setup() throws CTFReaderException
, SecurityException
,
77 IllegalArgumentException
{
78 assumeTrue(testTrace
.exists());
79 fTrace
= new CTFTrace(testTrace
.getPath());
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);
93 private String
getRandomElement(String
[] array
) {
94 return array
[rnd
.nextInt(array
.length
)];
97 private long testMain() {
98 TreeSet
<CTFCallsite
> l
= fTrace
.getCallsiteCandidates(callsites
[0]);
99 CTFCallsite cs
= fTrace
.getCallsite(1);
100 CTFCallsite cs1
= fTrace
.getCallsite(callsites
[0]);
101 CTFCallsite cs2
= fTrace
.getCallsite(callsites
[0], 1);
106 /* performance test */
107 long start
= System
.nanoTime();
109 long end
= System
.nanoTime();
110 long diff
= end
- start
;
111 assertTrue(diff
> 0);
116 * @param callsiteSize
118 private void test(int callsiteSize
) {
119 addCallsites(callsiteSize
);
120 long ns
= testMain();
121 System
.out
.println( "perf ( " + callsiteSize
+ ", " + ns
+ ")");
124 private void perfTest() {
125 for (int i
= 0; i
< NUMBER_OF_SEEKS
; i
++) {
126 fTrace
.getCallsite((((long) rnd
.nextInt()) << 16L));
131 * Test seeks with 1000 callsites
134 public void test1KCallsites() {
139 * Test seeks with 2000 callsites
142 public void test2KCallsites() {
147 * Test seeks with 5000 callsites
150 public void test5KCallsites() {
155 * Test seeks with 10000 callsites
158 public void test10KCallsites() {
163 * Test seeks with 20000 callsites
166 public void test20KCallsites() {
171 * Test seeks with 50000 callsites
174 public void test50KCallsites() {
179 * Test seeks with 100000 callsites
182 public void test100KCallsites() {
187 * Test seeks with 1000000 callsites
190 public void test1MCallsites() {
195 * Test seeks with 2000000 callsites
198 public void test2MCallsites() {