| 1 |
/* Copyright (C) 2022-2025 Free Software Foundation |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License as published by |
| 5 |
the Free Software Foundation, either version 3 of the License, or |
| 6 |
(at your option) any later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program. If not, see <http://www.gnu.org/licenses>. */ |
| 15 |
|
| 16 |
package org.gprofng.mpmt.timeline.events; |
| 17 |
|
| 18 |
import org.gprofng.mpmt.AnAddress; |
| 19 |
import org.gprofng.mpmt.AnInteger; |
| 20 |
import org.gprofng.mpmt.AnLocale; |
| 21 |
import org.gprofng.mpmt.AnLong; |
| 22 |
import org.gprofng.mpmt.AnWindow; |
| 23 |
import org.gprofng.mpmt.IPC; |
| 24 |
import org.gprofng.mpmt.statecolors.StackState; |
| 25 |
import java.util.List; |
| 26 |
|
| 27 |
public final class HWCEvent extends ExtendedEvent { |
| 28 |
private static final String INTERVAL = AnLocale.getString("Interval:"); // NOI18N |
| 29 |
private static final String FREQ = AnLocale.getString("Clock Freq (MHz):"); // NOI18N |
| 30 |
private static final String DATAVADDR = AnLocale.getString("Data Virtual Addr:"); // NOI18N |
| 31 |
private static final String DATAPADDR = AnLocale.getString("Data Physical Addr:"); // NOI18N |
| 32 |
private static final String PCVADDR = AnLocale.getString("PC Virtual Addr:"); // NOI18N |
| 33 |
private static final String PCPADDR = AnLocale.getString("PC Physical Addr:"); // NOI18N |
| 34 |
private static final String DATADESC = AnLocale.getString("Data Descriptor:"); // NOI18N |
| 35 |
private static final String[] LABELS = {INTERVAL}; |
| 36 |
private static final String[] LABELS2 = {INTERVAL, FREQ}; |
| 37 |
|
| 38 |
private static final String[] XLABELS = { |
| 39 |
INTERVAL, DATAVADDR, DATAPADDR, PCVADDR, PCPADDR, DATADESC |
| 40 |
}; |
| 41 |
private static final String[] XLABELS2 = { |
| 42 |
INTERVAL, FREQ, DATAVADDR, DATAPADDR, PCVADDR, PCPADDR, DATADESC |
| 43 |
}; |
| 44 |
|
| 45 |
// ABS encodings must match definitions in ABS.h |
| 46 |
private static final long ABS_NULL = 0x00L; |
| 47 |
private static final long ABS_CODE_RANGE = 0xFFL; |
| 48 |
private static final long ABS_RT_CODEMASK = 0x0FL; |
| 49 |
private static final long ABS_PP_CODEMASK = 0xF0L; |
| 50 |
|
| 51 |
private static final String[] ABS_RT_CODES = { |
| 52 |
"", // NOI18N |
| 53 |
AnLocale.getString("(Internal error)"), // NOI18N |
| 54 |
AnLocale.getString("(Backtracking blocked)"), // NOI18N |
| 55 |
AnLocale.getString("(Backtracking incomplete)"), // NOI18N |
| 56 |
AnLocale.getString("(Register lost)"), // NOI18N |
| 57 |
AnLocale.getString("(Invalid address)"), // NOI18N |
| 58 |
AnLocale.getString("(UNKNOWN)") // NOI18N |
| 59 |
}; |
| 60 |
|
| 61 |
private static final String[] ABS_PP_CODES = { |
| 62 |
"", // NOI18N |
| 63 |
AnLocale.getString("(No Symbolic Information)"), // NOI18N |
| 64 |
AnLocale.getString("(Backtracking failed)"), // NOI18N |
| 65 |
AnLocale.getString("(Blocked by branch target)"), // NOI18N |
| 66 |
AnLocale.getString("(<POST-PROCESSING ERROR>)") // NOI18N |
| 67 |
}; |
| 68 |
|
| 69 |
// passed to constructor |
| 70 |
private final AnWindow m_window; |
| 71 |
private final long interval; |
| 72 |
private final long eventEA, eventPA, eventVPC, eventPPC; |
| 73 |
private final int cpu_freq; |
| 74 |
private final String[] eventSpecificInfo; |
| 75 |
private final String[] eventSpecificLabels; |
| 76 |
|
| 77 |
public HWCEvent( |
| 78 |
final AnWindow awindow, |
| 79 |
int lwpid, |
| 80 |
int thrid, |
| 81 |
int cpuid, // IPC!! |
| 82 |
long ts, |
| 83 |
long stack, |
| 84 |
long func, |
| 85 |
List<StackState> stackStates, |
| 86 |
long interval, |
| 87 |
long eventEA, |
| 88 |
long eventPA, |
| 89 |
long eventVPC, |
| 90 |
long eventPPC, |
| 91 |
int cpu_freq, |
| 92 |
long time_adjust) { |
| 93 |
super(lwpid, thrid, cpuid, ts, stack, func, time_adjust, stackStates); |
| 94 |
|
| 95 |
this.m_window = awindow; |
| 96 |
this.interval = interval; |
| 97 |
this.eventEA = eventEA; |
| 98 |
this.eventPA = eventPA; |
| 99 |
this.eventVPC = eventVPC; |
| 100 |
this.eventPPC = eventPPC; |
| 101 |
this.cpu_freq = cpu_freq; |
| 102 |
this.eventSpecificInfo = ipcInitEventSpecificInfo(); |
| 103 |
this.eventSpecificLabels = initEventSpecificLabels(); |
| 104 |
} |
| 105 |
|
| 106 |
private String ipcGetDataspaceTypeDesc() { |
| 107 |
long stack = super.getStack(); |
| 108 |
return ipcGetDataspaceTypeDesc(stack); |
| 109 |
} |
| 110 |
|
| 111 |
private String getDataAddress() { |
| 112 |
int rt_code, pp_code; |
| 113 |
|
| 114 |
if (0 > eventEA || eventEA > ABS_CODE_RANGE) return AnAddress.toHexString(eventEA); |
| 115 |
else { |
| 116 |
rt_code = (int) (eventEA & ABS_RT_CODEMASK); |
| 117 |
pp_code = (int) (eventEA & ABS_PP_CODEMASK) / 0xF; |
| 118 |
if (rt_code > ABS_RT_CODES.length) rt_code = ABS_RT_CODES.length - 1; |
| 119 |
|
| 120 |
if (pp_code > ABS_PP_CODES.length) pp_code = ABS_PP_CODES.length - 1; |
| 121 |
|
| 122 |
return ABS_PP_CODES[pp_code] + ABS_RT_CODES[rt_code]; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
private String getPhysicalAddress() { |
| 127 |
if (eventPA != ABS_NULL) return AnAddress.toHexString(eventPA); |
| 128 |
else return ""; |
| 129 |
} |
| 130 |
|
| 131 |
private String getVirtualPC() { |
| 132 |
if (eventVPC != ABS_NULL) return AnAddress.toHexString(eventVPC); |
| 133 |
else return ""; |
| 134 |
} |
| 135 |
|
| 136 |
private String getPhysicalPC() { |
| 137 |
if (eventPPC != ABS_NULL) return AnAddress.toHexString(eventPPC); |
| 138 |
else return ""; |
| 139 |
} |
| 140 |
|
| 141 |
public String[] getEventSpecificInfo() { |
| 142 |
String[] rc = eventSpecificInfo.clone(); |
| 143 |
return rc; |
| 144 |
} |
| 145 |
|
| 146 |
// eventEA is only defined for XHWC records |
| 147 |
private String[] ipcInitEventSpecificInfo() { |
| 148 |
if ((cpu_freq == 0) && (eventEA == ABS_NULL)) |
| 149 |
return new String[] {new AnLong(interval).toString()}; |
| 150 |
else if (eventEA == ABS_NULL) |
| 151 |
return new String[] {new AnLong(interval).toString(), new AnInteger(cpu_freq).toString()}; |
| 152 |
else if (cpu_freq == 0) |
| 153 |
return new String[] { |
| 154 |
new AnLong(interval).toString(), |
| 155 |
getDataAddress(), |
| 156 |
getPhysicalAddress(), |
| 157 |
getVirtualPC(), |
| 158 |
getPhysicalPC(), |
| 159 |
ipcGetDataspaceTypeDesc() |
| 160 |
}; |
| 161 |
else |
| 162 |
return new String[] { |
| 163 |
new AnLong(interval).toString(), |
| 164 |
new AnInteger(cpu_freq).toString(), |
| 165 |
getDataAddress(), |
| 166 |
getPhysicalAddress(), |
| 167 |
getVirtualPC(), |
| 168 |
getPhysicalPC(), |
| 169 |
ipcGetDataspaceTypeDesc() |
| 170 |
}; |
| 171 |
} |
| 172 |
|
| 173 |
public String[] getEventSpecificLabels() { |
| 174 |
String[] rc = this.eventSpecificLabels.clone(); |
| 175 |
return rc; |
| 176 |
} |
| 177 |
|
| 178 |
private String[] initEventSpecificLabels() { |
| 179 |
if ((cpu_freq == 0) && (eventEA == ABS_NULL)) return LABELS; |
| 180 |
else if (eventEA == ABS_NULL) return LABELS2; |
| 181 |
else if (cpu_freq == 0) return XLABELS; |
| 182 |
else return XLABELS2; |
| 183 |
} |
| 184 |
|
| 185 |
// Native methods from liber_dbe.so |
| 186 |
private String ipcGetDataspaceTypeDesc(long stack) { |
| 187 |
synchronized (IPC.lock) { |
| 188 |
m_window.IPC().send("getDataspaceTypeDesc"); // NOI18N |
| 189 |
m_window.IPC().send(stack); |
| 190 |
return m_window.IPC().recvString(); |
| 191 |
} |
| 192 |
} |
| 193 |
} |