Commit | Line | Data |
---|---|---|
4c9d2941 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 | * The callsite constructor | |
26 | * | |
27 | * @param en | |
28 | * The event name | |
29 | * @param func | |
30 | * the function name | |
31 | * @param ip | |
32 | * the instruction pointer of the callsite | |
33 | * @param fn | |
34 | * the file name of the callsite | |
35 | * @param line | |
36 | * the line number of the callsite | |
37 | */ | |
38 | public CTFCallsite(String en, String func, long ip, String fn, long line) { | |
39 | EventName = en; | |
40 | FileName = fn; | |
41 | FunctionName = func; | |
42 | this.ip = ip; | |
43 | this.LineNumber = line; | |
44 | } | |
45 | ||
46 | static private final long MASK32 = 0x00000000ffffffffL; | |
47 | /** | |
48 | * The event name | |
49 | */ | |
50 | private final String EventName; | |
51 | /** | |
52 | * the file name of the callsite | |
53 | */ | |
54 | private final String FileName; | |
55 | /** | |
56 | * the instruction pointer | |
57 | */ | |
58 | private final long ip; | |
59 | /** | |
60 | * the function name | |
61 | */ | |
62 | private final String FunctionName; | |
63 | /** | |
64 | * the line number of the callsite | |
65 | */ | |
66 | private final long LineNumber; | |
67 | ||
68 | /* Getters */ | |
69 | /** | |
70 | * @return the eventName | |
71 | */ | |
72 | public String getEventName() { | |
73 | return EventName; | |
74 | } | |
75 | ||
76 | /** | |
77 | * @return the fileName | |
78 | */ | |
79 | public String getFileName() { | |
80 | return FileName; | |
81 | } | |
82 | ||
83 | /** | |
84 | * @return the ip | |
85 | */ | |
86 | public long getIp() { | |
87 | return ip; | |
88 | } | |
89 | ||
90 | /** | |
91 | * @return the functionName | |
92 | */ | |
93 | public String getFunctionName() { | |
94 | return FunctionName; | |
95 | } | |
96 | ||
97 | /** | |
98 | * @return the lineNumber | |
99 | */ | |
100 | public long getLineNumber() { | |
101 | return LineNumber; | |
102 | } | |
103 | ||
104 | /* | |
105 | * The callsites will be sorted by calling addresses. To do this we take IPs | |
106 | * (instruction pointers) and compare them. Java only supports signed | |
107 | * operation and since memory addresses are unsigned, we will convert the | |
108 | * longs into integers that contain the high and low bytes and compare them. | |
109 | */ | |
110 | @Override | |
111 | public int compareTo(CTFCallsite o) { | |
112 | /* | |
113 | * mask32 is 32 zeros followed by 32 ones, when we bitwise and this it | |
114 | * will return the lower 32 bits | |
115 | */ | |
116 | ||
117 | long other = o.ip; | |
118 | /* | |
119 | * To get a high int: we downshift by 32 and bitwise and with the mask | |
120 | * to get rid of the sign | |
121 | * | |
122 | * To get the low int: we bitwise and with the mask. | |
123 | */ | |
124 | long otherHigh = (other >> 32) & MASK32; | |
125 | long otherLow = other & MASK32; | |
126 | long ownHigh = (ip >> 32) & MASK32; | |
127 | long ownLow = ip & MASK32; | |
128 | /* are the high values different, if so ignore the lower values */ | |
129 | if (ownHigh > otherHigh) { | |
130 | return 1; | |
131 | } | |
132 | if (ownHigh < otherHigh ) { | |
133 | return -1; | |
134 | } | |
135 | /* the high values are the same, compare the lower values */ | |
136 | if (ownLow > otherLow) { | |
137 | return 1; | |
138 | } | |
139 | if (ownLow < otherLow) { | |
140 | return -1; | |
141 | } | |
142 | /* the values are identical */ | |
143 | return 0; | |
144 | } | |
145 | ||
146 | ||
147 | /* | |
148 | * (non-Javadoc) | |
149 | * | |
150 | * @see java.lang.Object#toString() | |
151 | */ | |
152 | @Override | |
153 | public String toString() { | |
154 | return FileName + "/" + FunctionName + ":" + LineNumber; //$NON-NLS-1$ //$NON-NLS-2$ | |
155 | } | |
156 | } |