Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1adceee213fcca432ac2c82ed06b6ab85554b59b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*******************************************************************************
 * Copyright (c) 2009 STMicroelectronics.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.gprof.symbolManager;

import java.util.LinkedList;

import org.eclipse.cdt.core.IBinaryParser.ISymbol;

/**
 * This class represents a node of a call graph
 * 
 * @author Xavier Raynaud <xavier.raynaud@st.com>
 */
public class CallGraphNode {

	private final ISymbol symbol;
	private final LinkedList<CallGraphArc> parents = new LinkedList<CallGraphArc>();
	private final LinkedList<CallGraphArc> children = new LinkedList<CallGraphArc>();
	
	/**
	 * Constructor
	 * @param symbol 
	 */
	public CallGraphNode(ISymbol symbol) {
		this.symbol = symbol;
	}
	
	/**
	 * @param parent
	 * @return the input arc caming from the given parent, if any.
	 */
	public CallGraphArc getInputArc(CallGraphNode parent) {
		for (CallGraphArc inputArc : parents) {
			if (inputArc.parent == parent) return inputArc;
		}
		return null;
	}
	
	/**
	 * 
	 * @param child
	 * @return the arc to the given child, if any.
	 */
	public CallGraphArc getOutputArc(CallGraphNode child) {
		for (CallGraphArc outputArc : children) {
			if (outputArc.child == child) return outputArc;
		}
		return null;
	}

	/**
	 * @return the symbol
	 */
	public ISymbol getSymbol() {
		return symbol;
	}

	/**
	 * @return the parents
	 */
	public LinkedList<CallGraphArc> getParents() {
		return parents;
	}

	/**
	 * @return the children
	 */
	public LinkedList<CallGraphArc> getChildren() {
		return children;
	}

	/**
	 * Print on System.out, for debugging purpose
	 */
	public void print() {
		System.out.println(this.symbol.getName());
		System.out.println(" -- parents --");
		for (CallGraphArc arc : this.parents) {
			arc.print();
		}
		System.out.println(" -- children --");
		for (CallGraphArc arc : this.children) {
			arc.print();
		}
	}
	
	/**
	 * @return the total calls for this function
	 */
	public int getCalls() {
		int ret = 0;
		for (CallGraphArc arc : this.parents) {
			ret += arc.getCount();
		}
		return ret;
	}
	
}

Back to the top