1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.ctf
.core
.tests
.perf
.trace
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assume
.assumeTrue
;
17 import java
.util
.Random
;
18 import java
.util
.TreeSet
;
20 import org
.eclipse
.test
.performance
.Dimension
;
21 import org
.eclipse
.test
.performance
.Performance
;
22 import org
.eclipse
.test
.performance
.PerformanceMeter
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFCallsite
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTrace
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
31 * Test the performance of the callsite storage in the CTF trace.
33 * @author Matthew Khouzam
35 public class CTFTraceCallsitePerformanceTest
{
37 private static final String TEST_SUITE_NAME
= "CTF Callsite Benchmark";
38 private static final String TEST_ID
= "org.eclipse.linuxtools#" + TEST_SUITE_NAME
;
40 private static final CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
42 private static final int NUMBER_OF_SEEKS
= 100000;
44 private final String
[] callsites
= { "Alligator", "Bunny", "Cat",
45 "Dolphin", "Echidna", "Gazelle", "Heron", "Ibex", "Jackalope",
46 "Koala", "Lynx", "Meerkat", "Narwhal", "Ocelot", "Pangolin",
47 "Quetzal", "Ringtail", "Sandpiper", "Tiger", "Urchin", "Vulture",
48 "Walrus", "X-Ray Tetra", "Zonkey" };
50 private final String
[] functions
= { "sentence", "together", "children",
51 "mountain", "chipmunk", "crashing", "drinking", "insisted",
52 "insulted", "invented", "squinted", "standing", "swishing",
53 "talented", "whiplash", "complain", "granddad", "sprinkle",
54 "surprise", "umbrella", "anything", "anywhere", "baseball",
55 "birthday", "bluebird", "cheerful", "colorful", "daylight",
56 "doghouse", "driveway", "everyone" };
58 private final String
[] files
= { "Adult.java", "Aeroplane.java",
59 "Air.java", "Airforce.java", "Airport.java", "Album.java",
60 "Alphabet.java", "Apple.java", "Arm.java", "Army.java", "Babby.java" };
62 Random rnd
= new Random();
63 CTFTrace fTrace
= null;
66 * main, launches the tests.
71 public static void main(String
[] args
) {
72 new org
.junit
.runner
.JUnitCore().run(CTFTraceCallsitePerformanceTest
.class);
76 * sets up the test by making a new trace.
78 * @throws CTFException
79 * an exception from the reader
80 * @throws SecurityException
81 * an exception from accessing files illegally
82 * @throws IllegalArgumentException
83 * an exception for passing bad values
86 public void setup() throws CTFException
, SecurityException
,
87 IllegalArgumentException
{
88 assumeTrue(testTrace
.exists());
89 fTrace
= new CTFTrace(testTrace
.getPath());
92 private void addCallsites(int numCallsites
) {
93 long stepSize
= (Long
.MAX_VALUE
/ (numCallsites
+ 1));
94 int jitter
= (int) Math
.min(stepSize
, Integer
.MAX_VALUE
);
95 for (int i
= 0; i
< numCallsites
; i
++) {
96 final long ip
= ((i
)) * stepSize
+ rnd
.nextInt(jitter
);
97 fTrace
.addCallsite(getRandomElement(callsites
),
98 getRandomElement(functions
), ip
, getRandomElement(files
),
99 (ip
/ 1000000) * 100);
103 private String
getRandomElement(String
[] array
) {
104 return array
[rnd
.nextInt(array
.length
)];
107 private void testMain(PerformanceMeter pm
) {
108 TreeSet
<CTFCallsite
> l
= fTrace
.getCallsiteCandidates(callsites
[0]);
109 CTFCallsite cs
= fTrace
.getCallsite(1);
110 CTFCallsite cs1
= fTrace
.getCallsite(callsites
[0]);
111 CTFCallsite cs2
= fTrace
.getCallsite(callsites
[0], 1);
116 /* performance test */
123 * @param callsiteSize
125 private void test(int callsiteSize
) {
126 String testName
= "Test" + callsiteSize
+ " callsites";
127 addCallsites(callsiteSize
);
128 Performance perf
= Performance
.getDefault();
129 PerformanceMeter pm
= perf
.createPerformanceMeter(TEST_ID
+ '#' + testName
);
130 perf
.tagAsSummary(pm
, TEST_SUITE_NAME
+ ':' + callsiteSize
+ " callsites", Dimension
.CPU_TIME
);
135 private void perfTest() {
136 for (int i
= 0; i
< NUMBER_OF_SEEKS
; i
++) {
137 fTrace
.getCallsite((((long) rnd
.nextInt()) << 16L));
142 * Test seeks with 1000 callsites
145 public void test1KCallsites() {
151 * Test seeks with 2000 callsites
154 public void test2KCallsites() {
159 * Test seeks with 5000 callsites
162 public void test5KCallsites() {
167 * Test seeks with 10000 callsites
170 public void test10KCallsites() {
175 * Test seeks with 20000 callsites
178 public void test20KCallsites() {
183 * Test seeks with 50000 callsites
186 public void test50KCallsites() {
191 * Test seeks with 100000 callsites
194 public void test100KCallsites() {
199 * Test seeks with 1000000 callsites
202 public void test1MCallsites() {
207 * Test seeks with 2000000 callsites
210 public void test2MCallsites() {