Skip to content

Commit

Permalink
TraceEvent: Handle string TIDs
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Khouzam <[email protected]>
  • Loading branch information
MatthewKhouzam committed Dec 4, 2024
1 parent 39e687b commit 7d62fa2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ public boolean isHiddenByDefault() {
@Override
public @Nullable Integer resolve(@NonNull ITmfEvent event) {
if (event instanceof TraceEventEvent) {
return ((TraceEventEvent) event).getField().getTid();
Object tid = ((TraceEventEvent) event).getField().getTid();
if (tid instanceof Integer) {
return (Integer) tid;
}
if (tid != null) {
return tid.hashCode();
}

}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TraceEventField {
private final String fName;
private ITmfEventField fContent;
private final @Nullable Map<String, Object> fArgs;
private final @Nullable Integer fTid;
private final @Nullable Object fTid;
private final @Nullable String fCategory;
private final @Nullable String fId;
private final @Nullable Long fDuration;
Expand Down Expand Up @@ -91,10 +91,7 @@ public class TraceEventField {
}
// We differentiate between the duration exit and the other exits for some reason
String name = String.valueOf(optString(root, ITraceEventConstants.NAME, TraceEventPhases.DURATION_END.equals(phase) ? UNKNOWN_DURATION_EXIT_EVENT : UNKNOWN_EXIT_EVENT));
Integer tid = optInt(root, ITraceEventConstants.TID);
if (tid == Integer.MIN_VALUE) {
tid = null;
}
String tid = optString(root, ITraceEventConstants.TID, null);
JsonElement jsonElement = root.get(ITraceEventConstants.PID);
JsonPrimitive primitive = jsonElement == null ? null : jsonElement.isJsonPrimitive() ? jsonElement.getAsJsonPrimitive() : null;
Object pid = primitive == null ? null : primitive.isNumber() ? primitive.getAsNumber() : primitive.isString() ? primitive.getAsString() : null;
Expand Down Expand Up @@ -143,11 +140,6 @@ private static double optDouble(JsonObject root, String key) {
return jsonElement != null ? jsonElement.getAsDouble() : Double.NaN;
}

private static int optInt(JsonObject root, String key) {
JsonElement jsonElement = root.get(key);
return jsonElement != null ? jsonElement.getAsInt() : Integer.MIN_VALUE;
}

private static @Nullable JsonObject optJSONObject(JsonObject root, String key) {
JsonElement jsonElement = root.get(key);
return jsonElement != null ? jsonElement.getAsJsonObject() : null;
Expand Down Expand Up @@ -184,7 +176,7 @@ private static int optInt(JsonObject root, String key) {
* @param fields
* event fields (arguments)
*/
protected TraceEventField(String name, long ts, String phase, @Nullable Object pid, @Nullable Integer tid, @Nullable String category, @Nullable String id, @Nullable Double duration, Map<String, Object> fields) {
protected TraceEventField(String name, long ts, String phase, @Nullable Object pid, @Nullable Object tid, @Nullable String category, @Nullable String id, @Nullable Double duration, Map<String, Object> fields) {
fName = name;
fPid = pid;
fTid = tid;
Expand Down Expand Up @@ -258,7 +250,7 @@ public char getPhase() {
*
* @return the event TID
*/
public @Nullable Integer getTid() {
public @Nullable Object getTid() {
return fTid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private void parseMetadata(TraceEventField field) {
return;
}
Map<@NonNull String, @NonNull String> properties = fProperties;
Object tid = field.getTid();
switch (name) {
case PROCESS_NAME:
String procName = (String) args.get(NAME_ARG);
Expand All @@ -311,15 +312,17 @@ private void parseMetadata(TraceEventField field) {
break;
case THREAD_NAME:
String threadName = (String) args.get(NAME_ARG);
fTidNames.put(field.getTid(), threadName);
if (tid instanceof Integer) {
fTidNames.put((Integer) tid, threadName);
}
if (threadName != null) {
properties.put(TID_PREFIX + field.getTid(), threadName);
properties.put(TID_PREFIX + tid, threadName);
}
break;
case THREAD_SORT_INDEX:
sortIndex = (String) args.get(SORT_INDEX);
if (sortIndex != null) {
properties.put(name + '-' + field.getTid(), sortIndex);
properties.put(name + '-' + tid, sortIndex);
}
break;
default:
Expand Down Expand Up @@ -355,8 +358,12 @@ public class ThreadNameAspect extends org.eclipse.tracecompass.incubator.analysi
public @Nullable String resolve(@NonNull ITmfEvent event) {
if (event instanceof TraceEventEvent) {
TraceEventField field = ((TraceEventEvent) event).getField();
if (field.getTid() != null) {
return fTidNames.get(field.getTid());
Object tid = field.getTid();
if (tid != null) {
String tidName = fTidNames.get(tid);
if (tidName == null) {
return String.valueOf(tid);
}
}
}
return null;
Expand Down

0 comments on commit 7d62fa2

Please sign in to comment.