Skip to content

Commit

Permalink
7506: Incorrect numeric formatting of PID by JMC
Browse files Browse the repository at this point in the history
Co-authored-by: Marcus Hirt <hirt@openjdk.org>
Reviewed-by: bdutheil, vpurnam, hirt
  • Loading branch information
Suchita Chaturvedi and thegreystone committed Jun 14, 2024
1 parent b4afd6d commit 992333a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -234,7 +234,7 @@ private class JVMInformationUi implements IPageUI {
infoViewer = new ItemAggregateViewer(jvmInfSection, toolkit);
infoViewer.addAggregate(JdkAggregators.JVM_START_TIME);
infoViewer.addAggregate(JdkAggregators.JVM_NAME);
infoViewer.addAggregate(JdkAggregators.JVM_PID);
infoViewer.addAggregate(JdkAggregators.PID);
infoViewer.addAggregate(JdkAggregators.JVM_VERSION);
infoViewer.addAggregate(JdkAggregators.JVM_ARGUMENTS);
infoViewer.addAggregate(JdkAggregators.JAVA_ARGUMENTS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -1093,6 +1093,31 @@ public V2 getValue(final Iterator<C> consumers) {
};
}

public static <T> IAggregator<IQuantity, ?> getJvmPid(String typeId, IAttribute<T> attribute) {
IAggregator<Set<T>, ?> aggregator = Aggregators.distinct(attribute);
aggregator = filter(aggregator, ItemFilters.type(typeId));
return Aggregators.valueBuilderAggregator(aggregator, new IValueBuilder<IQuantity, Set<T>>() {
@Override
public IType<? super IQuantity> getValueType() {
return UnitLookup.NUMBER;
}

@Override
public IQuantity getValue(Set<T> source) {
Long value = 0L;
if (source.isEmpty()) {
return null;
} else {
Iterator<?> itr = source.iterator();
while (itr.hasNext()) {
value = Long.valueOf((String) itr.next());
}
return UnitLookup.NUMBER_UNITY.quantity(value);
}
}
}, attribute.getName(), attribute.getDescription());
}

public static <T> IAggregator<IQuantity, ?> countDistinct(
String name, String description, IAccessorFactory<T> attribute) {
return new SetAggregator<IQuantity, T>(name, description, attribute, UnitLookup.NUMBER) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -115,8 +115,9 @@ public final class JdkAggregators {

// VM Info
public static final IAggregator<String, ?> JVM_NAME = distinctAsString(VM_INFO, JdkAttributes.JVM_NAME);
public static final IAggregator<IQuantity, ?> JVM_PID = min(JdkAttributes.JVM_PID.getName(), null, VM_INFO,
JdkAttributes.JVM_PID);
@Deprecated
public static final IAggregator<IQuantity, ?> JVM_PID = Aggregators.getJvmPid(VM_INFO, JdkAttributes.PID);
public static final IAggregator<String, ?> PID = distinctAsString(VM_INFO, JdkAttributes.PID);
public static final IAggregator<IQuantity, ?> JVM_START_TIME = min(JdkAttributes.JVM_START_TIME.getName(), null,
VM_INFO, JdkAttributes.JVM_START_TIME);
public static final IAggregator<String, ?> JVM_VERSION = distinctAsString(VM_INFO, JdkAttributes.JVM_VERSION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -46,6 +46,7 @@
import org.openjdk.jmc.common.IMCStackTrace;
import org.openjdk.jmc.common.IMCThread;
import org.openjdk.jmc.common.item.IAttribute;
import org.openjdk.jmc.common.unit.IQuantity;
import org.openjdk.jmc.common.unit.UnitLookup;
import org.openjdk.jmc.common.util.LabeledIdentifier;
import org.openjdk.jmc.flightrecorder.JfrAttributes;
Expand Down Expand Up @@ -169,6 +170,23 @@ private boolean isError(IMCFrame frame) {
IEventSink moduleExportSink = new ModuleExportSink(subSink, packageIndex);
return moduleExportSink;
}
} else if (JdkTypeIDs.VM_INFO.equals(identifier)) {
// Adding a String pid, as that is what is used in the jdk.SystemProcess event.
int packageIndex = -1;
for (int i = 0; i < dataStructure.size(); i++) {
ValueField vf = dataStructure.get(i);
if (vf.matches(JdkAttributes.JVM_PID)) {
packageIndex = i;
break;
}
}
if (packageIndex != -1) {
List<ValueField> newDataStructure = new ArrayList<>(dataStructure);
newDataStructure.set(packageIndex, new ValueField(JdkAttributes.PID));
IEventSink subSink = sf.create(identifier, label, category, description, newDataStructure);
IEventSink moduleExportSink = new LongAsStringSink(subSink, packageIndex);
return moduleExportSink;
}
}
return sf.create(identifier, label, category, description, dataStructure);
}
Expand Down Expand Up @@ -212,4 +230,26 @@ public void addEvent(Object[] values) {
}
}
}

private static class LongAsStringSink implements IEventSink {
private final IEventSink subSink;
private final int pidIndex;

public LongAsStringSink(IEventSink subSink, int pidIndex) {
this.subSink = subSink;
this.pidIndex = pidIndex;
}

@Override
public void addEvent(Object[] values) {
IQuantity longPid = (IQuantity) values[pidIndex];
if (longPid != null && values != null && values.length > 0) {
String pid = String.valueOf(longPid.longValue());
Object[] newValues = new Object[values.length];
System.arraycopy(values, 0, newValues, 0, values.length - 1);
newValues[pidIndex] = pid;
subSink.addEvent(newValues);
}
}
}
}

0 comments on commit 992333a

Please sign in to comment.