ctf: Fix some Sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.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 eventName;
31
32 /**
33 * the file name of the callsite
34 */
35 private final String fileName;
36
37 /**
38 * the instruction pointer
39 */
40 private final long ip;
41
42 /**
43 * the function name
44 */
45 private final String functionName;
46
47 /**
48 * the line number of the callsite
49 */
50 private final long lineNumber;
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 eventName = en;
68 fileName = fn;
69 functionName = func;
70 this.ip = ip;
71 this.lineNumber = line;
72 }
73
74 /**
75 * @return the eventName
76 */
77 public String getEventName() {
78 return eventName;
79 }
80
81 /**
82 * @return the fileName
83 */
84 public String getFileName() {
85 return fileName;
86 }
87
88 /**
89 * @return the ip
90 */
91 public long getIp() {
92 return ip;
93 }
94
95 /**
96 * @return the functionName
97 */
98 public String getFunctionName() {
99 return functionName;
100 }
101
102 /**
103 * @return the lineNumber
104 */
105 public long getLineNumber() {
106 return lineNumber;
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.ip;
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 = (ip >> 32) & MASK32;
132 long ownLow = ip & 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 String toString() {
153 return fileName + "/" + functionName + ":" + lineNumber; //$NON-NLS-1$ //$NON-NLS-2$
154 }
155 }
This page took 0.034184 seconds and 5 git commands to generate.