ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFCallsite.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.ctf.core.event;
15
16 /**
17 * Callsite information to help with cdt integration
18 *
19 * @author Matthew Khouzam
20 *
21 * @since 1.2
22 */
23 public class CTFCallsite implements Comparable<CTFCallsite> {
24
25 private static final long MASK32 = 0x00000000ffffffffL;
26
27 /**
28 * The event name
29 */
30 private final String fEventName;
31
32 /**
33 * the file name of the callsite
34 */
35 private final String fFileName;
36
37 /**
38 * the instruction pointer
39 */
40 private final long fIp;
41
42 /**
43 * the function name
44 */
45 private final String fFunctionName;
46
47 /**
48 * the line number of the callsite
49 */
50 private final long fLineNumber;
51
52 /**
53 * The callsite constructor
54 *
55 * @param en
56 * The event name
57 * @param func
58 * the function name
59 * @param ip
60 * the instruction pointer of the callsite
61 * @param fn
62 * the file name of the callsite
63 * @param line
64 * the line number of the callsite
65 */
66 public CTFCallsite(String en, String func, long ip, String fn, long line) {
67 fEventName = en;
68 fFileName = fn;
69 fFunctionName = func;
70 fIp = ip;
71 fLineNumber = line;
72 }
73
74 /**
75 * @return the eventName
76 */
77 public String getEventName() {
78 return fEventName;
79 }
80
81 /**
82 * @return the fileName
83 */
84 public String getFileName() {
85 return fFileName;
86 }
87
88 /**
89 * @return the ip
90 */
91 public long getIp() {
92 return fIp;
93 }
94
95 /**
96 * @return the functionName
97 */
98 public String getFunctionName() {
99 return fFunctionName;
100 }
101
102 /**
103 * @return the lineNumber
104 */
105 public long getLineNumber() {
106 return fLineNumber;
107 }
108
109 /*
110 * The callsites will be sorted by calling addresses. To do this we take IPs
111 * (instruction pointers) and compare them. Java only supports signed
112 * operation and since memory addresses are unsigned, we will convert the
113 * longs into integers that contain the high and low bytes and compare them.
114 */
115 @Override
116 public int compareTo(CTFCallsite o) {
117 /*
118 * mask32 is 32 zeros followed by 32 ones, when we bitwise and this it
119 * will return the lower 32 bits
120 */
121
122 long other = o.fIp;
123 /*
124 * To get a high int: we downshift by 32 and bitwise and with the mask
125 * to get rid of the sign
126 *
127 * To get the low int: we bitwise and with the mask.
128 */
129 long otherHigh = (other >> 32) & MASK32;
130 long otherLow = other & MASK32;
131 long ownHigh = (fIp >> 32) & MASK32;
132 long ownLow = fIp & MASK32;
133 /* are the high values different, if so ignore the lower values */
134 if (ownHigh > otherHigh) {
135 return 1;
136 }
137 if (ownHigh < otherHigh ) {
138 return -1;
139 }
140 /* the high values are the same, compare the lower values */
141 if (ownLow > otherLow) {
142 return 1;
143 }
144 if (ownLow < otherLow) {
145 return -1;
146 }
147 /* the values are identical */
148 return 0;
149 }
150
151 @Override
152 public int hashCode() {
153 final int prime = 31;
154 int result = 1;
155 result = prime * result + ((fEventName == null) ? 0 : fEventName.hashCode());
156 result = prime * result + ((fFileName == null) ? 0 : fFileName.hashCode());
157 result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode());
158 result = prime * result + (int) (fIp ^ (fIp >>> 32));
159 result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32));
160 return result;
161 }
162
163
164 @Override
165 public boolean equals(Object obj) {
166 if (this == obj) {
167 return true;
168 }
169 if (obj == null) {
170 return false;
171 }
172 if (getClass() != obj.getClass()) {
173 return false;
174 }
175 CTFCallsite other = (CTFCallsite) obj;
176 if (fEventName == null) {
177 if (other.fEventName != null) {
178 return false;
179 }
180 } else if (!fEventName.equals(other.fEventName)) {
181 return false;
182 }
183 if (fFileName == null) {
184 if (other.fFileName != null) {
185 return false;
186 }
187 } else if (!fFileName.equals(other.fFileName)) {
188 return false;
189 }
190 if (fFunctionName == null) {
191 if (other.fFunctionName != null) {
192 return false;
193 }
194 } else if (!fFunctionName.equals(other.fFunctionName)) {
195 return false;
196 }
197 if (fIp != other.fIp) {
198 return false;
199 }
200 if (fLineNumber != other.fLineNumber) {
201 return false;
202 }
203 return true;
204 }
205
206 @Override
207 public String toString() {
208 return fFileName + "/" + fFunctionName + ":" + fLineNumber; //$NON-NLS-1$ //$NON-NLS-2$
209 }
210 }
This page took 0.055471 seconds and 5 git commands to generate.