Timing: Fix call stack state value bug in CallGraphAnalysis
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / CalledFunctionFactory.java
CommitLineData
2d8d933f
SF
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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 *******************************************************************************/
9
10package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph;
11
12import org.eclipse.jdt.annotation.Nullable;
13import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
14
15/**
16 * Factory to create {@link ICalledFunction}s.
17 *
18 * @author Matthew Khouzam
19 */
20public class CalledFunctionFactory {
21
22 private static final String SEPARATOR = ": "; //$NON-NLS-1$
23 private static final String ERROR_MSG = "Cannot create a called function of type : "; //$NON-NLS-1$
24
25 private CalledFunctionFactory() {
26 // do nothing
27 }
28
29 /**
30 * Factory Method for a state value mapped called function
31 *
32 * @param start
33 * the start time
34 * @param end
35 * the end time
36 * @param depth
37 * the depth
38 * @param stateValue
39 * the symbol
40 * @param parent
41 * the parent node
42 * @return an ICalledFunction with the specified propertiess
43 */
44 public static AbstractCalledFunction create(long start, long end, int depth, ITmfStateValue stateValue, @Nullable ICalledFunction parent) {
45 switch (stateValue.getType()) {
46 case CUSTOM:
47 throw new IllegalArgumentException(ERROR_MSG + stateValue.getType() + SEPARATOR + stateValue.toString());
48 case DOUBLE:
49 throw new IllegalArgumentException(ERROR_MSG + stateValue.getType() + SEPARATOR + stateValue.toString());
50 case INTEGER:
51 return create(start, end, depth, stateValue.unboxInt(), parent);
52 case LONG:
53 return create(start, end, depth, stateValue.unboxLong(), parent);
54 case NULL:
55 throw new IllegalArgumentException(ERROR_MSG + stateValue.getType() + SEPARATOR + stateValue.toString());
56 case STRING:
57 return create(start, end, depth, stateValue.unboxStr(), parent);
58 default:
59 throw new IllegalArgumentException(ERROR_MSG + stateValue.getType() + SEPARATOR + stateValue.toString());
60 }
61 }
62
63 /**
64 * Factory method to create a called function with a symbol that is a long
65 * integer
66 *
67 * @param start
68 * the start time
69 * @param end
70 * the end time
71 * @param depth
72 * the depth
73 * @param value
74 * the symbol
75 * @param parent
76 * the parent node
77 * @return an ICalledFunction with the specified propertiess
78 */
79 private static CalledFunction create(long start, long end, int depth, long value, @Nullable ICalledFunction parent) {
80 if (start > end) {
81 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
82 }
83 return new CalledFunction(start, end, value, depth, parent);
84 }
85
86 /**
87 * Factory method to create a called function with a symbol that is a
88 * {@link String}
89 *
90 * @param start
91 * the start time
92 * @param end
93 * the end time
94 * @param depth
95 * the depth
96 * @param value
97 * the symbol
98 * @param parent
99 * the parent node
100 * @return an ICalledFunction with the specified propertiess
101 */
102 private static CalledStringFunction create(long start, long end, int depth, String value, @Nullable ICalledFunction parent) {
103 if (start > end) {
104 throw new IllegalArgumentException(Messages.TimeError + '[' + start + ',' + end + ']');
105 }
106 return new CalledStringFunction(start, end, value, depth, parent);
107 }
108}
This page took 0.033223 seconds and 5 git commands to generate.