Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 371285 | Differences between
and this patch

Collapse All | Expand All

(-)a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/model/PMSymbolMatcher.java (-1 / +132 lines)
Added Link Here
0
- 
1
package org.eclipse.linuxtools.internal.perf.model;
2
3
import java.util.ArrayList;
4
5
import org.eclipse.core.resources.IFile;
6
import org.eclipse.debug.core.ILaunchConfiguration;
7
import org.eclipse.linuxtools.internal.perf.PerfCore;
8
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
9
import org.eclipse.linuxtools.internal.perf.launch.PerfDefaultLaunchConfig;
10
11
public class PMSymbolMatcher {
12
13
	/**
14
	 * Get PMSymbol's from report of file
15
	 * 
16
	 * @param file
17
	 *            the file to be reported
18
	 * @return array of PMSymbol's
19
	 */
20
	private static ArrayList<PMSymbol> getSymbols(IFile file) {
21
		String projectName = file.getProject().getName();
22
23
		PerfDefaultLaunchConfig perfConfig = new PerfDefaultLaunchConfig();
24
		ILaunchConfiguration config = perfConfig
25
				.createDefaultConfiguration(projectName);
26
27
		PerfCore.Report(config, null, null, null, file.getLocation()
28
				.toOSString(), null);
29
30
		// get model from reported perf data file
31
		TreeParent invisibleRoot = PerfPlugin.getDefault().getModelRoot();
32
33
		if (invisibleRoot.getChildren().length == 0) {
34
			return null;
35
		}
36
37
		ArrayList<PMSymbol> symbols = new ArrayList<PMSymbol>();
38
39
		// get all PMSymbols
40
		for (TreeParent event : invisibleRoot.getChildren()) {
41
			for (TreeParent cmd : event.getChildren()) {
42
				for (TreeParent dso : cmd.getChildren()) {
43
					for (TreeParent dsoFile : dso.getChildren()) {
44
						for (TreeParent sym : dsoFile.getChildren()) {
45
							symbols.add((PMSymbol) sym);
46
						}
47
					}
48
				}
49
			}
50
		}
51
		return symbols;
52
	}
53
54
	/**
55
	 * Get PMSymbol's matches from the two given PMSymbol arrays
56
	 * 
57
	 * @param stale
58
	 *            PMSymbol array of older PMSymbol's
59
	 * @param fresh
60
	 *            PMSymbol array of newer PMSymbol's
61
	 * @return array of PMSymbolMatch's, each containing a PMSymbol match pair
62
	 */
63
	private static ArrayList<PMSymbolMatch> buildMatches(
64
			ArrayList<PMSymbol> stale, ArrayList<PMSymbol> fresh) {
65
		ArrayList<PMSymbolMatch> result = new ArrayList<PMSymbolMatch>();
66
67
		ArrayList<PMSymbol> staleNoMatch = (ArrayList<PMSymbol>) stale.clone();
68
69
		// Gather all matches/non-matches of the fresh dsos against the stale.
70
		boolean added = false;
71
		for (PMSymbol freshElement : fresh) {
72
			added = true;
73
			for (PMSymbol staleElement : stale) {
74
				if (equals(freshElement, staleElement)) {
75
					result.add(new PMSymbolMatch(freshElement, staleElement));
76
					staleNoMatch.remove(staleElement);
77
					added = false;
78
					break;
79
				}
80
			}
81
			// New dso with no match in the stale list
82
			if (added) {
83
				result.add(new PMSymbolMatch((PMSymbol) freshElement, null));
84
			}
85
		}
86
		// Gather stale dsos with no match in the fresh list
87
		for (PMSymbol staleElement : staleNoMatch) {
88
			result.add(new PMSymbolMatch(null, (PMSymbol) staleElement));
89
		}
90
		return result;
91
	}
92
93
	/**
94
	 * Build matches given two files
95
	 * 
96
	 * @param staleData
97
	 *            older data file
98
	 * @param freshData
99
	 *            newer data file
100
	 * @return array of PMSymbolMatch's, each containing a PMSymbol match pair
101
	 */
102
	public static ArrayList<PMSymbolMatch> buildResults(IFile staleData,
103
			IFile freshData) {
104
		ArrayList<PMSymbol> staleDsos = getSymbols(staleData);
105
		ArrayList<PMSymbol> freshDsos = getSymbols(freshData);
106
		if (staleDsos == null || freshDsos == null) {
107
			return null;
108
		}
109
		ArrayList<PMSymbolMatch> result = buildMatches(staleDsos, freshDsos);
110
		return result;
111
	}
112
113
	/**
114
	 * Check TreeParent's are equal (i.e. have the same ancestors)
115
	 * 
116
	 * @param t1
117
	 *            TreeParent element
118
	 * @param t2
119
	 *            TreeParent element
120
	 * @return TreeParent's equality
121
	 */
122
	public static boolean equals(TreeParent t1, TreeParent t2) {
123
		// base case (invisible root)
124
		if ("".equals(t1.getName()) && "".equals(t2.getName())) {
125
			return true;
126
		} else if (t1.equals(t2.getName())) {
127
			return equals(t1.getParent(), t2.getParent());
128
		} else {
129
			return false;
130
		}
131
	}
132
}

Return to bug 371285