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/PMSymbolMatch.java (-1 / +159 lines)
Added Link Here
0
- 
1
/*******************************************************************************
2
 * Copyright (c) 2012 Red Hat, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Camilo Bernal <cabernal@redhat.com> - Initial Implementation.
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.internal.perf.model;
12
13
public class PMSymbolMatch {
14
15
	// Name of matched dsos
16
	private String name;
17
18
	// Path of matched dsos in the tree model
19
	private String path;
20
21
	// Reference to newer dso
22
	private PMSymbol fresh;
23
24
	// Reference to older dso
25
	private PMSymbol stale;
26
27
	// Result
28
	private String result;
29
30
	// Event
31
	private String event;
32
33
	public PMSymbolMatch(PMSymbol fresh, PMSymbol stale) {
34
		this.fresh = fresh;
35
		this.stale = stale;
36
37
		if ((fresh != null && stale == null)) {
38
			name = fresh.getName();
39
			result = "added";
40
			setEvent(true);
41
		} else if ((fresh == null && stale != null)) {
42
			name = stale.getName();
43
			result = "removed";
44
			setEvent(false);
45
		} else if (((fresh != null) && (stale != null))) {
46
			name = fresh.getName();
47
			this.result = String.valueOf(fresh.getPercent()
48
					- stale.getPercent());
49
			setEvent(true);
50
		} else {
51
			name = "";
52
			path = "";
53
			event = "";
54
			result = "";
55
		}
56
	}
57
58
	public void setEvent(boolean freshEvent) {
59
		try {
60
			if (freshEvent) {
61
				event = fresh.getParent().getParent().getParent().getParent()
62
						.getName();
63
			} else {
64
				event = stale.getParent().getParent().getParent().getParent()
65
						.getName();
66
			}
67
		} catch (Exception e) {
68
			e.printStackTrace();
69
			event = "";
70
		}
71
	}
72
73
	public String getResult() {
74
		try {
75
			float res = Float.parseFloat(result);
76
			if (res > 0) {
77
				return "+" + result;
78
			} else {
79
				return result;
80
			}
81
		} catch (Exception e) {
82
			return result;
83
		}
84
	}
85
86
	public String getName() {
87
		return name;
88
	}
89
90
	public String getPath() {
91
		return path;
92
	}
93
94
	public PMSymbol getFresh() {
95
		return fresh;
96
	}
97
98
	public PMSymbol getStale() {
99
		return stale;
100
	}
101
102
	public String getEvent() {
103
		return event;
104
	}
105
106
	/**
107
	 * Compare PMSymbols percentages against our pair
108
	 * 
109
	 * @param p
110
	 *            PMSymbols match
111
	 * @param compFresh
112
	 *            true if fresh symbols are to be compared, false otherwise
113
	 * @return comparison of percentages
114
	 */
115
	public int compareSymbol(PMSymbolMatch p, boolean compFresh) {
116
		PMSymbol thisSym;
117
		PMSymbol otherSym;
118
		int ret = 0;
119
		if (compFresh) {
120
			thisSym = fresh;
121
			otherSym = p.getFresh();
122
		} else {
123
			thisSym = stale;
124
			otherSym = p.getStale();
125
		}
126
127
		if (thisSym == null && otherSym != null) {
128
			ret = -1;
129
		} else if (thisSym != null && otherSym == null) {
130
			ret = 1;
131
		} else if (thisSym == null && otherSym == null) {
132
			ret = 0;
133
		} else {
134
			ret = (thisSym.getPercent() < otherSym.getPercent()) ? -1 : 1;
135
		}
136
		return ret;
137
	}
138
139
	/**
140
	 * Compare result of given PMSymbols against our pair
141
	 * 
142
	 * @param p
143
	 *            PMSymbols match
144
	 * @return comparison of results
145
	 */
146
	public int compareResult(PMSymbolMatch p) {
147
		int ret = 0;
148
		String oldRes1 = result;
149
		String oldRes2 = p.getResult();
150
		try {
151
			float oldRes1f = Float.parseFloat(oldRes1);
152
			float oldRes2f = Float.parseFloat(oldRes2);
153
			ret = (oldRes1f < oldRes2f) ? -1 : 1;
154
		} catch (NumberFormatException e) {
155
			ret = oldRes1.compareTo(oldRes2);
156
		}
157
		return ret;
158
	}
159
}

Return to bug 371285