ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFCallsite.java
CommitLineData
4c9d2941 1/*******************************************************************************
11252342 2 * Copyright (c) 2012, 2013 Ericsson
4c9d2941
MK
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
14package 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 */
23public class CTFCallsite implements Comparable<CTFCallsite> {
4c9d2941 24
0594c61c
AM
25 private static final long MASK32 = 0x00000000ffffffffL;
26
4c9d2941
MK
27 /**
28 * The event name
29 */
a0b72d7b 30 private final String fEventName;
0594c61c 31
4c9d2941
MK
32 /**
33 * the file name of the callsite
34 */
a0b72d7b 35 private final String fFileName;
0594c61c 36
4c9d2941
MK
37 /**
38 * the instruction pointer
39 */
a0b72d7b 40 private final long fIp;
0594c61c 41
4c9d2941
MK
42 /**
43 * the function name
44 */
a0b72d7b 45 private final String fFunctionName;
0594c61c 46
4c9d2941
MK
47 /**
48 * the line number of the callsite
49 */
a0b72d7b 50 private final long fLineNumber;
0594c61c
AM
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) {
a0b72d7b
MK
67 fEventName = en;
68 fFileName = fn;
69 fFunctionName = func;
70 fIp = ip;
71 fLineNumber = line;
0594c61c 72 }
4c9d2941 73
4c9d2941
MK
74 /**
75 * @return the eventName
76 */
77 public String getEventName() {
a0b72d7b 78 return fEventName;
4c9d2941
MK
79 }
80
81 /**
82 * @return the fileName
83 */
84 public String getFileName() {
a0b72d7b 85 return fFileName;
4c9d2941
MK
86 }
87
88 /**
89 * @return the ip
90 */
91 public long getIp() {
a0b72d7b 92 return fIp;
4c9d2941
MK
93 }
94
95 /**
96 * @return the functionName
97 */
98 public String getFunctionName() {
a0b72d7b 99 return fFunctionName;
4c9d2941
MK
100 }
101
102 /**
103 * @return the lineNumber
104 */
105 public long getLineNumber() {
a0b72d7b 106 return fLineNumber;
4c9d2941
MK
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
a0b72d7b 122 long other = o.fIp;
4c9d2941
MK
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;
a0b72d7b
MK
131 long ownHigh = (fIp >> 32) & MASK32;
132 long ownLow = fIp & MASK32;
4c9d2941
MK
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
4c9d2941
MK
151 @Override
152 public String toString() {
a0b72d7b 153 return fFileName + "/" + fFunctionName + ":" + fLineNumber; //$NON-NLS-1$ //$NON-NLS-2$
4c9d2941
MK
154 }
155}
This page took 0.0399 seconds and 5 git commands to generate.