1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.tests
.flamegraph
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertTrue
;
16 import java
.util
.Collections
;
17 import java
.util
.List
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.jdt
.annotation
.Nullable
;
23 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
24 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
.AggregatedCalledFunction
;
25 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
.CallGraphAnalysis
;
26 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
.ThreadNode
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemFactory
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.backend
.IStateHistoryBackend
;
31 import org
.eclipse
.tracecompass
.statesystem
.core
.backend
.StateHistoryBackendFactory
;
32 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.segment
.ISegmentAspect
;
34 import org
.junit
.Test
;
37 * Test the CallGraphAnalysis.This creates a virtual state system in each test
38 * and tests the aggregation tree returned by the CallGraphAnalysis.
40 * @author Sonia Farrah
43 public class AggregationTreeTest
{
45 private static final @NonNull String PROCESS_PATH
= "Processes";
46 private static final @NonNull String THREAD_PATH
= "Thread";
47 private static final @NonNull String CALLSTACK_PATH
= "CallStack";
48 private static final String QUARK_0
= "0";
49 private static final String QUARK_1
= "1";
50 private static final String QUARK_2
= "2";
51 private static final String QUARK_3
= "3";
52 private static final Integer SMALL_AMOUNT_OF_SEGMENT
= 3;
53 private static final int LARGE_AMOUNT_OF_SEGMENTS
= 1000;
54 private static final String
@NonNull [] CSP
= { CALLSTACK_PATH
};
55 private static final String
@NonNull [] PP
= { PROCESS_PATH
};
56 private static final String
@NonNull [] TP
= { THREAD_PATH
};
59 * This class is used to make the CallGraphAnalysis's method
60 * iterateOverStateSystem() visible to test
62 private class CGAnalysis
extends CallGraphAnalysis
{
65 protected boolean iterateOverStateSystem(@Nullable ITmfStateSystem ss
, String
[] threadsPattern
, String
[] processesPattern
, String
[] callStackPath
, IProgressMonitor monitor
) {
66 return super.iterateOverStateSystem(ss
, threadsPattern
, processesPattern
, callStackPath
, monitor
);
70 public @NonNull Iterable
<@NonNull ISegmentAspect
> getSegmentAspects() {
71 return Collections
.EMPTY_LIST
;
76 private static ITmfStateSystemBuilder
createFixture() {
77 IStateHistoryBackend backend
;
78 backend
= StateHistoryBackendFactory
.createInMemoryBackend("Test", 0L);
79 ITmfStateSystemBuilder fixture
= StateSystemFactory
.newStateSystem(backend
);
84 * Test an empty state system.
87 public void emptyStateSystemTest() {
88 ITmfStateSystemBuilder fixture
= createFixture();
89 fixture
.closeHistory(1002);
90 CGAnalysis cga
= new CGAnalysis();
91 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
92 List
<ThreadNode
> threads
= cga
.getThreadNodes();
93 assertNotNull(threads
);
94 assertEquals("Number of threads found", 0, threads
.size());
98 * Test cascade state system. The call stack's structure used in this test
109 public void cascadeTest() {
110 ITmfStateSystemBuilder fixture
= createFixture();
111 // Build the state system
114 int threadQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
);
115 int parentQuark
= fixture
.getQuarkRelativeAndAdd(threadQuark
, CALLSTACK_PATH
);
116 fixture
.updateOngoingState(TmfStateValue
.newValueLong(100), threadQuark
);
117 for (int i
= 1; i
<= SMALL_AMOUNT_OF_SEGMENT
; i
++) {
118 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, Integer
.toString(i
));
119 TmfStateValue statev
= TmfStateValue
.newValueLong(i
);
120 fixture
.modifyAttribute(start
, TmfStateValue
.nullValue(), quark
);
121 fixture
.modifyAttribute(start
+ i
, statev
, quark
);
122 fixture
.modifyAttribute(end
- i
, TmfStateValue
.nullValue(), quark
);
125 fixture
.closeHistory(1002);
126 // Execute the CallGraphAnalysis
127 CGAnalysis cga
= new CGAnalysis();
128 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
130 List
<ThreadNode
> threads
= cga
.getThreadNodes();
131 // Test the threads generated by the analysis
132 assertNotNull(threads
);
133 assertEquals("Number of thread nodes Found", 1, threads
.size());
134 assertEquals("Number of root functions ", 1, threads
.get(0).getChildren().size());
135 assertEquals("Thread id", 100, threads
.get(0).getId());
136 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
137 Object
[] children
= threads
.get(0).getChildren().toArray();
138 AggregatedCalledFunction firstFunction
= (AggregatedCalledFunction
) children
[0];
139 assertEquals("Children number: First function", 1, firstFunction
.getChildren().size());
140 Object
@NonNull [] firstFunctionChildren
= firstFunction
.getChildren().toArray();
141 AggregatedCalledFunction secondFunction
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
142 assertEquals("Children number: Second function", 1, secondFunction
.getChildren().size());
143 Object
@NonNull [] secondFunctionChildren
= secondFunction
.getChildren().toArray();
144 AggregatedCalledFunction thirdFunction
= (AggregatedCalledFunction
) secondFunctionChildren
[0];
145 assertEquals("Children number: Third function", 0, thirdFunction
.getChildren().size());
147 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(secondFunction
.getParent()).getSymbol(), firstFunction
.getSymbol());
148 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(thirdFunction
.getParent()).getSymbol(), secondFunction
.getSymbol());
150 assertEquals("Test first function's duration", 998, firstFunction
.getDuration());
151 assertEquals("Test second function's duration", 996, secondFunction
.getDuration());
152 assertEquals("Test third function's duration", 994, thirdFunction
.getDuration());
154 assertEquals("Test first function's self time", 2, firstFunction
.getSelfTime());
155 assertEquals("Test second function's self time", 2, secondFunction
.getSelfTime());
156 assertEquals("Test third function's self time", 994, thirdFunction
.getSelfTime());
158 assertEquals("Test first function's depth", 0, firstFunction
.getDepth());
159 assertEquals("Test second function's depth", 1, secondFunction
.getDepth());
160 assertEquals("Test third function's depth", 2, thirdFunction
.getDepth());
161 // Test number of calls
162 assertEquals("Test first function's nombre of calls", 1, firstFunction
.getNbCalls());
163 assertEquals("Test second function's nombre of calls", 1, secondFunction
.getNbCalls());
164 assertEquals("Test third function's nombre of calls", 1, thirdFunction
.getNbCalls());
168 * Test a state system with a two calls for the same function. The call
169 * stack's structure used in this test is shown below:
173 * ___ main___ ___ main___
179 public void treeTest() {
180 ITmfStateSystemBuilder fixture
= createFixture();
181 // Build the state system
182 int threadQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
);
183 int parentQuark
= fixture
.getQuarkRelativeAndAdd(threadQuark
, CALLSTACK_PATH
);
184 fixture
.updateOngoingState(TmfStateValue
.newValueDouble(0.001), threadQuark
);
185 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_0
);
186 TmfStateValue statev
= TmfStateValue
.newValueLong(0);
187 fixture
.modifyAttribute(0, statev
, quark
);
188 fixture
.modifyAttribute(100, TmfStateValue
.nullValue(), quark
);
190 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_1
);
191 statev
= TmfStateValue
.newValueLong(1);
192 fixture
.modifyAttribute(0, statev
, quark
);
193 fixture
.modifyAttribute(50, TmfStateValue
.nullValue(), quark
);
194 fixture
.modifyAttribute(60, statev
, quark
);
195 fixture
.modifyAttribute(90, TmfStateValue
.nullValue(), quark
);
197 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_2
);
198 fixture
.modifyAttribute(0, statev
, quark
);
199 fixture
.modifyAttribute(30, TmfStateValue
.nullValue(), quark
);
200 fixture
.closeHistory(102);
202 // Execute the CallGraphAnalysis
203 CGAnalysis cga
= new CGAnalysis();
204 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
206 List
<ThreadNode
> threads
= cga
.getThreadNodes();
207 // Test the threads generated by the analysis
208 assertNotNull(threads
);
209 assertEquals("Number of thread nodes Found", 1, threads
.size());
210 assertEquals("Thread id", -1, threads
.get(0).getId());
211 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
212 Object
[] children
= threads
.get(0).getChildren().toArray();
213 AggregatedCalledFunction firstFunction
= (AggregatedCalledFunction
) children
[0];
214 assertEquals("Children number: First function", 1, firstFunction
.getChildren().size());
215 Object
[] firstFunctionChildren
= firstFunction
.getChildren().toArray();
216 AggregatedCalledFunction secondFunction
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
217 assertEquals("Children number: Second function", 1, secondFunction
.getChildren().size());
218 Object
[] secondFunctionChildren
= secondFunction
.getChildren().toArray();
219 AggregatedCalledFunction thirdFunction
= (AggregatedCalledFunction
) secondFunctionChildren
[0];
220 assertEquals("Children number: Third function", 0, thirdFunction
.getChildren().size());
222 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(secondFunction
.getParent()).getSymbol(), firstFunction
.getSymbol());
223 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(thirdFunction
.getParent()).getSymbol(), secondFunction
.getSymbol());
225 assertEquals("Test first function's duration", 100, firstFunction
.getDuration());
226 assertEquals("Test second function's duration", 80, secondFunction
.getDuration());
227 assertEquals("Test third function's duration", 30, thirdFunction
.getDuration());
229 assertEquals("Test first function's self time", 20, firstFunction
.getSelfTime());
230 assertEquals("Test second function's self time", 50, secondFunction
.getSelfTime());
231 assertEquals("Test third function's self time", 30, thirdFunction
.getSelfTime());
233 assertEquals("Test first function's depth", 0, firstFunction
.getDepth());
234 assertEquals("Test second function's depth", 1, secondFunction
.getDepth());
235 assertEquals("Test third function's depth", 2, thirdFunction
.getDepth());
236 // Test number of calls
237 assertEquals("Test first function's number of calls", 1, firstFunction
.getNbCalls());
238 assertEquals("Test second function's number of calls", 2, secondFunction
.getNbCalls());
239 assertEquals("Test third function's number of calls", 1, thirdFunction
.getNbCalls());
243 * Test the callees merge. The call stack's structure used in this test is
248 * ___ main___ ___ main___
254 public void mergeFirstLevelCalleesTest() {
255 ITmfStateSystemBuilder fixture
= createFixture();
256 // Build the state system
257 int threadQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, "123");
258 int parentQuark
= fixture
.getQuarkRelativeAndAdd(threadQuark
, CALLSTACK_PATH
);
259 fixture
.updateOngoingState(TmfStateValue
.newValueDouble(0.001), threadQuark
);
260 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_0
);
261 TmfStateValue statev
= TmfStateValue
.newValueLong(0);
262 fixture
.modifyAttribute(0, statev
, quark
);
263 fixture
.modifyAttribute(100, TmfStateValue
.nullValue(), quark
);
265 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_1
);
266 statev
= TmfStateValue
.newValueLong(1);
267 fixture
.modifyAttribute(0, statev
, quark
);
268 fixture
.modifyAttribute(50, TmfStateValue
.nullValue(), quark
);
269 fixture
.modifyAttribute(60, statev
, quark
);
270 fixture
.modifyAttribute(90, TmfStateValue
.nullValue(), quark
);
272 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_2
);
273 statev
= TmfStateValue
.newValueLong(2);
274 fixture
.modifyAttribute(0, statev
, quark
);
275 fixture
.modifyAttribute(30, TmfStateValue
.nullValue(), quark
);
276 statev
= TmfStateValue
.newValueLong(3);
277 fixture
.modifyAttribute(60, statev
, quark
);
278 fixture
.modifyAttribute(80, TmfStateValue
.nullValue(), quark
);
279 fixture
.closeHistory(102);
281 // Execute the CallGraphAnalysis
282 CGAnalysis cga
= new CGAnalysis();
283 String
@NonNull [] tp
= { "123" };
284 assertTrue(cga
.iterateOverStateSystem(fixture
, tp
, PP
, CSP
, new NullProgressMonitor()));
285 List
<ThreadNode
> threads
= cga
.getThreadNodes();
286 // Test the threads generated by the analysis
287 assertNotNull(threads
);
288 assertEquals("Number of thread nodes Found", 1, threads
.size());
289 assertEquals("Thread id", 123, threads
.get(0).getId());
290 assertEquals("Thread name", "123", threads
.get(0).getSymbol());
291 assertEquals("Number of root functions ", 1, threads
.get(0).getChildren().size());
292 Object
[] children
= threads
.get(0).getChildren().toArray();
294 AggregatedCalledFunction firstFunction
= (AggregatedCalledFunction
) children
[0];
295 assertEquals("Children number: First function", 1, firstFunction
.getChildren().size());
296 Object
[] firstFunctionChildren
= firstFunction
.getChildren().toArray();
297 AggregatedCalledFunction secondFunction
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
298 assertEquals("Children number: Second function", 2, secondFunction
.getChildren().size());
299 Object
[] secondFunctionChildren
= secondFunction
.getChildren().toArray();
300 AggregatedCalledFunction leaf1
= (AggregatedCalledFunction
) secondFunctionChildren
[0];
301 AggregatedCalledFunction leaf2
= (AggregatedCalledFunction
) secondFunctionChildren
[1];
302 assertEquals("Children number: First leaf function", 0, leaf1
.getChildren().size());
303 assertEquals("Children number: Second leaf function", 0, leaf2
.getChildren().size());
305 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(secondFunction
.getParent()).getSymbol(), firstFunction
.getSymbol());
306 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(leaf1
.getParent()).getSymbol(), secondFunction
.getSymbol());
307 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(leaf2
.getParent()).getSymbol(), secondFunction
.getSymbol());
309 assertEquals("Test first function's duration", 100, firstFunction
.getDuration());
310 assertEquals("Test second function's duration", 80, secondFunction
.getDuration());
311 assertEquals("Test first leaf's duration", 30, leaf1
.getDuration());
312 assertEquals("Test second leaf's duration", 20, leaf2
.getDuration());
314 assertEquals("Test first function's self time", 20, firstFunction
.getSelfTime());
315 assertEquals("Test second function's self time", 30, secondFunction
.getSelfTime());
316 assertEquals("Test first leaf's self time", 30, leaf1
.getSelfTime());
317 assertEquals("Test second leaf's self time", 20, leaf2
.getSelfTime());
319 assertEquals("Test first function's depth", 0, firstFunction
.getDepth());
320 assertEquals("Test second function's depth", 1, secondFunction
.getDepth());
321 assertEquals("Test first leaf's depth", 2, leaf1
.getDepth());
322 assertEquals("Test second leaf's depth", 2, leaf2
.getDepth());
323 // Test number of calls
324 assertEquals("Test first function's number of calls", 1, firstFunction
.getNbCalls());
325 assertEquals("Test second function's number of calls", 2, secondFunction
.getNbCalls());
326 assertEquals("Test first leaf's number of calls", 1, leaf1
.getNbCalls());
327 assertEquals("Test second leaf's number of calls", 1, leaf2
.getNbCalls());
331 * Build a call stack example.This call stack's structure is shown below :
340 private static void buildCallStack(ITmfStateSystemBuilder fixture
) {
341 int parentQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
, CALLSTACK_PATH
);
342 // Create the first function
343 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_0
);
344 TmfStateValue statev
= TmfStateValue
.newValueLong(0);
345 fixture
.modifyAttribute(0, statev
, quark
);
346 fixture
.modifyAttribute(100, TmfStateValue
.nullValue(), quark
);
347 // Create the first level functions
348 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_1
);
349 statev
= TmfStateValue
.newValueLong(1);
350 fixture
.modifyAttribute(0, statev
, quark
);
351 fixture
.modifyAttribute(50, TmfStateValue
.nullValue(), quark
);
352 fixture
.modifyAttribute(60, statev
, quark
);
353 fixture
.modifyAttribute(100, TmfStateValue
.nullValue(), quark
);
354 // Create the third function
355 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_2
);
356 statev
= TmfStateValue
.newValueLong(2);
357 fixture
.modifyAttribute(0, statev
, quark
);
358 fixture
.modifyAttribute(10, TmfStateValue
.nullValue(), quark
);
360 statev
= TmfStateValue
.newValueLong(3);
361 fixture
.modifyAttribute(20, statev
, quark
);
362 fixture
.modifyAttribute(30, TmfStateValue
.nullValue(), quark
);
364 statev
= TmfStateValue
.newValueLong(2);
365 fixture
.modifyAttribute(60, statev
, quark
);
366 fixture
.modifyAttribute(90, TmfStateValue
.nullValue(), quark
);
368 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_3
);
369 statev
= TmfStateValue
.newValueLong(4);
370 fixture
.modifyAttribute(0, statev
, quark
);
371 fixture
.modifyAttribute(10, TmfStateValue
.nullValue(), quark
);
373 fixture
.modifyAttribute(60, statev
, quark
);
374 fixture
.modifyAttribute(80, TmfStateValue
.nullValue(), quark
);
375 fixture
.closeHistory(102);
379 * Test the merge of The callees children. The call stack's structure used
380 * in this test is shown below:
384 * ___ main____ ____ main____
386 * _2_ _3_ _2_ => _2_ _3_
391 public void mergeSecondLevelCalleesTest() {
392 ITmfStateSystemBuilder fixture
= createFixture();
393 buildCallStack(fixture
);
394 // Execute the CallGraphAnalysis
395 CGAnalysis cga
= new CGAnalysis();
396 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
397 List
<ThreadNode
> threads
= cga
.getThreadNodes();
398 // Test the threads generated by the analysis
399 assertNotNull(threads
);
400 assertEquals("Number of thread nodes Found", 1, threads
.size());
401 assertEquals("Thread id", -1, threads
.get(0).getId());
402 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
403 assertEquals("Number of root functions ", 1, threads
.get(0).getChildren().size());
404 Object
[] children
= threads
.get(0).getChildren().toArray();
405 AggregatedCalledFunction main
= (AggregatedCalledFunction
) children
[0];
406 assertEquals("Children number: main", 1, main
.getChildren().size());
407 Object
[] mainChildren
= main
.getChildren().toArray();
408 AggregatedCalledFunction function1
= (AggregatedCalledFunction
) mainChildren
[0];
409 assertEquals("Children number: first function", 2, function1
.getChildren().size());
410 Object
[] firstFunctionChildren
= function1
.getChildren().toArray();
411 AggregatedCalledFunction function2
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
412 AggregatedCalledFunction function3
= (AggregatedCalledFunction
) firstFunctionChildren
[1];
413 assertEquals("Children number: First child", 1, function2
.getChildren().size());
414 assertEquals("Children number: Second child", 0, function3
.getChildren().size());
415 Object
[] firstChildCallee
= function2
.getChildren().toArray();
416 AggregatedCalledFunction function4
= (AggregatedCalledFunction
) firstChildCallee
[0];
417 assertEquals("Children number: leaf function", 0, function4
.getChildren().size());
419 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function1
.getParent()).getSymbol(), main
.getSymbol());
420 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function2
.getParent()).getSymbol(), function1
.getSymbol());
421 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function3
.getParent()).getSymbol(), function1
.getSymbol());
422 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function4
.getParent()).getSymbol(), function2
.getSymbol());
424 assertEquals("Test main's duration", 100, main
.getDuration());
425 assertEquals("Test first function's duration", 90, function1
.getDuration());
426 assertEquals("Test first child's duration", 40, function2
.getDuration());
427 assertEquals("Test second child's duration", 10, function3
.getDuration());
428 assertEquals("Test leaf's duration", 30, function4
.getDuration());
430 assertEquals("Test main's self time", 10, main
.getSelfTime());
431 assertEquals("Test first function's self time", 40, function1
.getSelfTime());
432 assertEquals("Test first child's self time", 10,
433 function2
.getSelfTime());
434 assertEquals("Test second child's self time", 10, function3
.getSelfTime());
435 assertEquals("Test leaf's self time", 30, function4
.getSelfTime());
437 assertEquals("Test main function's depth", 0, main
.getDepth());
438 assertEquals("Test first function's depth", 1, function1
.getDepth());
439 assertEquals("Test first child's depth", 2, function2
.getDepth());
440 assertEquals("Test second child's depth", 2, function3
.getDepth());
441 assertEquals("Test leaf's depth", 3, function4
.getDepth());
442 // Test number of calls
443 assertEquals("Test main's number of calls", 1, main
.getNbCalls());
444 assertEquals("Test first function's number of calls", 2, function1
.getNbCalls());
445 assertEquals("Test first child's number of calls", 2, function2
.getNbCalls());
446 assertEquals("Test second child's number of calls", 1, function3
.getNbCalls());
447 assertEquals("Test leaf's number of calls", 2, function4
.getNbCalls());
451 * Test state system with a large amount of segments. All segments have the
452 * same length. The call stack's structure used in this test is shown below:
462 public void largeTest() {
463 ITmfStateSystemBuilder fixture
= createFixture();
464 int parentQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
, CALLSTACK_PATH
);
465 for (int i
= 0; i
< LARGE_AMOUNT_OF_SEGMENTS
; i
++) {
466 TmfStateValue statev
= TmfStateValue
.newValueLong(i
);
467 fixture
.pushAttribute(0, statev
, parentQuark
);
469 for (int i
= 0; i
< LARGE_AMOUNT_OF_SEGMENTS
; i
++) {
470 fixture
.popAttribute(10, parentQuark
);
472 fixture
.closeHistory(11);
473 // Execute the callGraphAnalysis
474 CGAnalysis cga
= new CGAnalysis();
475 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
476 List
<ThreadNode
> threads
= cga
.getThreadNodes();
477 // Test the threads generated by the analysis
478 assertNotNull(threads
);
479 assertEquals("Thread id", -1, threads
.get(0).getId());
480 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
481 Object
[] children
= threads
.get(0).getChildren().toArray();
482 AggregatedCalledFunction parent
= (AggregatedCalledFunction
) children
[0];
483 for (int i
= 1; i
< LARGE_AMOUNT_OF_SEGMENTS
; i
++) {
484 children
= parent
.getChildren().toArray();
485 AggregatedCalledFunction child
= (AggregatedCalledFunction
) children
[0];
486 assertEquals("Test parenthood", NonNullUtils
.checkNotNull(child
.getParent()).getSymbol(), NonNullUtils
.checkNotNull(parent
.getSymbol()));
492 * Test mutliRoots state system.This tests if a root function called twice
493 * will be merged into one function or not. The call stack's structure used
494 * in this test is shown below:
503 public void multiFunctionRootsTest() {
504 ITmfStateSystemBuilder fixture
= createFixture();
505 int parentQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
, CALLSTACK_PATH
);
506 // Create the first root function
507 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_0
);
508 TmfStateValue statev
= TmfStateValue
.newValueLong(1);
509 fixture
.modifyAttribute(0, statev
, quark
);
510 fixture
.modifyAttribute(20, TmfStateValue
.nullValue(), quark
);
511 // Create the second root function
512 fixture
.modifyAttribute(30, statev
, quark
);
513 fixture
.modifyAttribute(50, TmfStateValue
.nullValue(), quark
);
514 // Create the first root function's callee
515 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_1
);
516 statev
= TmfStateValue
.newValueLong(2);
517 fixture
.modifyAttribute(0, statev
, quark
);
518 fixture
.modifyAttribute(10, TmfStateValue
.nullValue(), quark
);
519 // Create the second root function's callee
520 statev
= TmfStateValue
.newValueLong(3);
521 fixture
.modifyAttribute(30, statev
, quark
);
522 fixture
.modifyAttribute(40, TmfStateValue
.nullValue(), quark
);
523 fixture
.closeHistory(51);
525 // Execute the callGraphAnalysis
526 CGAnalysis cga
= new CGAnalysis();
527 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
528 List
<ThreadNode
> threads
= cga
.getThreadNodes();
529 // Test the threads generated by the analysis
530 assertNotNull(threads
);
531 assertEquals("Number of thread nodes Found", 1, threads
.size());
532 assertEquals("Thread id", -1, threads
.get(0).getId());
533 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
534 assertEquals("Number of root functions ", 1, threads
.get(0).getChildren().size());
535 Object
[] children
= threads
.get(0).getChildren().toArray();
536 AggregatedCalledFunction firstFunction
= (AggregatedCalledFunction
) children
[0];
537 assertEquals("Children number: First function", 2, firstFunction
.getChildren().size());
538 Object
[] firstFunctionChildren
= firstFunction
.getChildren().toArray();
539 AggregatedCalledFunction function2
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
540 AggregatedCalledFunction function3
= (AggregatedCalledFunction
) firstFunctionChildren
[1];
541 assertEquals("Children number: Second function", 0, function2
.getChildren().size());
542 assertEquals("Children number: Third function", 0, function3
.getChildren().size());
544 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function2
.getParent()).getSymbol(), firstFunction
.getSymbol());
545 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function3
.getParent()).getSymbol(), firstFunction
.getSymbol());
547 assertEquals("Test first function's duration", 40, firstFunction
.getDuration());
548 assertEquals("Test second function's duration", 10, function2
.getDuration());
549 assertEquals("Test third function's duration", 10, function3
.getDuration());
551 assertEquals("Test first function's self time", 20, firstFunction
.getSelfTime());
552 assertEquals("Test second function's self time", 10, function2
.getSelfTime());
553 assertEquals("Test third function's self time", 10, function2
.getSelfTime());
555 assertEquals("Test first function's depth", 0, firstFunction
.getDepth());
556 assertEquals("Test second function's depth", 1, function2
.getDepth());
557 assertEquals("Test third function's depth", 1, function3
.getDepth());
558 // Test number of calls
559 assertEquals("Test first function's number of calls", 2, firstFunction
.getNbCalls());
560 assertEquals("Test second function's number of calls", 1, function2
.getNbCalls());
561 assertEquals("Test third function's number of calls", 1, function3
.getNbCalls());
566 * Test mutliRoots state system. The call stack's structure used in this
567 * test is shown below:
577 public void multiFunctionRootsSecondTest() {
578 ITmfStateSystemBuilder fixture
= createFixture();
579 int parentQuark
= fixture
.getQuarkAbsoluteAndAdd(PROCESS_PATH
, THREAD_PATH
, CALLSTACK_PATH
);
580 // Create the first root function
581 int quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_0
);
582 TmfStateValue statev
= TmfStateValue
.newValueLong(0);
583 fixture
.modifyAttribute(0, statev
, quark
);
584 fixture
.modifyAttribute(20, TmfStateValue
.nullValue(), quark
);
585 // Create the second root function
586 statev
= TmfStateValue
.newValueLong(1);
587 fixture
.modifyAttribute(30, statev
, quark
);
588 fixture
.modifyAttribute(50, TmfStateValue
.nullValue(), quark
);
589 // Create the first root function's callee
590 quark
= fixture
.getQuarkRelativeAndAdd(parentQuark
, QUARK_1
);
591 statev
= TmfStateValue
.newValueLong(2);
592 fixture
.modifyAttribute(0, statev
, quark
);
593 fixture
.modifyAttribute(10, TmfStateValue
.nullValue(), quark
);
594 // Create the second root function's callee
595 fixture
.modifyAttribute(30, statev
, quark
);
596 fixture
.modifyAttribute(40, TmfStateValue
.nullValue(), quark
);
597 fixture
.closeHistory(51);
599 // Execute the callGraphAnalysis
600 CGAnalysis cga
= new CGAnalysis();
601 assertTrue(cga
.iterateOverStateSystem(fixture
, TP
, PP
, CSP
, new NullProgressMonitor()));
602 List
<ThreadNode
> threads
= cga
.getThreadNodes();
603 // Test the threads generated by the analysis
604 assertNotNull(threads
);
605 assertEquals("Number of thread nodes Found", 1, threads
.size());
606 assertEquals("Thread id", -1, threads
.get(0).getId());
607 assertEquals("Thread name", "Thread", threads
.get(0).getSymbol());
608 assertEquals("Number of root functions ", 2, threads
.get(0).getChildren().size());
609 Object
[] children
= threads
.get(0).getChildren().toArray();
610 AggregatedCalledFunction firstFunction
= (AggregatedCalledFunction
) children
[0];
611 AggregatedCalledFunction secondFunction
= (AggregatedCalledFunction
) children
[1];
613 assertEquals("Children number: First function", 1, firstFunction
.getChildren().size());
614 assertEquals("Children number: Second function", 1, secondFunction
.getChildren().size());
615 Object
[] firstFunctionChildren
= firstFunction
.getChildren().toArray();
616 Object
[] secondFunctionChildren
= secondFunction
.getChildren().toArray();
617 AggregatedCalledFunction function3
= (AggregatedCalledFunction
) firstFunctionChildren
[0];
618 AggregatedCalledFunction function4
= (AggregatedCalledFunction
) secondFunctionChildren
[0];
620 assertEquals("Children number: third function", 0, function3
.getChildren().size());
621 assertEquals("Children number: fourth function", 0, function4
.getChildren().size());
623 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function3
.getParent()).getSymbol(), firstFunction
.getSymbol());
624 assertEquals("Test parenthood ", NonNullUtils
.checkNotNull(function4
.getParent()).getSymbol(), secondFunction
.getSymbol());
626 assertEquals("Test second function's duration", 20, firstFunction
.getDuration());
627 assertEquals("Test second function's duration", 20, secondFunction
.getDuration());
628 assertEquals("Test first leaf's duration", 10, function3
.getDuration());
629 assertEquals("Test second leaf's duration", 10, function4
.getDuration());
631 assertEquals("Test first function's self time", 10, firstFunction
.getSelfTime());
632 assertEquals("Test second function's duration", 10, secondFunction
.getSelfTime());
633 assertEquals("Test second function's self time", 10, function3
.getSelfTime());
634 assertEquals("Test second function's self time", 10, function4
.getSelfTime());
636 assertEquals("Test first function's depth", 0, firstFunction
.getDepth());
637 assertEquals("Test first function's depth", 0, secondFunction
.getDepth());
638 assertEquals("Test third function's depth", 1, function3
.getDepth());
639 assertEquals("Test third function's depth", 1, function4
.getDepth());
640 // Test number of calls
641 assertEquals("Test first function's number of calls", 1, firstFunction
.getNbCalls());
642 assertEquals("Test first function's number of calls", 1, secondFunction
.getNbCalls());
643 assertEquals("Test third function's number of calls", 1, function3
.getNbCalls());
644 assertEquals("Test third function's number of calls", 1, function4
.getNbCalls());