Skip to main content
summaryrefslogtreecommitdiffstats
blob: f536b6242f6b0f76e1d31856d88cb2d25348b612 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
 * 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.view;

import java.util.LinkedList;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.linuxtools.gprof.parser.GmonDecoder;
import org.eclipse.linuxtools.gprof.view.histogram.CGCategory;
import org.eclipse.linuxtools.gprof.view.histogram.HistFunction;
import org.eclipse.linuxtools.gprof.view.histogram.HistRoot;
import org.eclipse.linuxtools.gprof.view.histogram.TreeElement;


/**
 * Tree content provider on charge of displaying call graph
 * 
 * HistRoot => HistFunction => CGCategory (parent/children) => CGArc
 * 
 * @author Xavier Raynaud <xavier.raynaud@st.com>
 */
public class CallGraphContentProvider implements ITreeContentProvider {

	public static final CallGraphContentProvider sharedInstance = new CallGraphContentProvider();
	
	/**
	 * Constructor
	 */
	private CallGraphContentProvider() {
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
	 */
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof HistRoot) {
			HistRoot root = (HistRoot) parentElement;
			LinkedList<? extends TreeElement> ret = getFunctionChildrenList(root);
			return ret.toArray();
		}
		if (parentElement instanceof HistFunction) {
			HistFunction function = (HistFunction) parentElement;
			CGCategory parents  = function.getParentsFunctions();
			CGCategory children = function.getChildrenFunctions();
			if (parents == null) {
				if (children == null) return new Object[0];
				return new Object[] {children};
			} else if (children == null) {
				return new Object[] {parents};
			} else {
				return new Object[] {
					parents,
					children
				};
			}
		}
		if (parentElement instanceof CGCategory) {
			CGCategory cat = (CGCategory) parentElement;
			return cat.getChildren().toArray();
		}
		return null;
	}

	protected LinkedList<? extends TreeElement> getFunctionChildrenList(HistRoot root) {
		LinkedList<TreeElement> ret = new LinkedList<TreeElement>();
		LinkedList<? extends TreeElement> list = root.getChildren();
		for (TreeElement histTreeElem : list) {
			LinkedList<? extends TreeElement> partialList = histTreeElem.getChildren();
			ret.addAll(partialList);
		}
		return ret;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
	 */
	public Object getParent(Object element) {
		TreeElement cge = (TreeElement) element;
		if (cge instanceof HistFunction) {
			return cge.getParent().getParent();
		}
		return cge.getParent();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
	 */
	public boolean hasChildren(Object element) {
		TreeElement cge = (TreeElement) element;
		return cge.hasChildren();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 */
	public Object[] getElements(Object inputElement) {
		if (inputElement == null) return new Object[0];
		GmonDecoder obj = (GmonDecoder) inputElement;
		HistRoot root   = obj.getRootNode();
		return new Object[] { root };
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
	 */
	public void dispose() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}
	
	

}

Back to the top