8232231: Remove invalid JFR thread CPU load test case
Reviewed-by: mseledtsov, egahlin
This commit is contained in:
parent
bb4dafe4bf
commit
3fe949b2f4
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package jdk.jfr.event.runtime;
|
package jdk.jfr.event.runtime;
|
||||||
|
|
||||||
import com.sun.management.ThreadMXBean;
|
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.RecordedEvent;
|
import jdk.jfr.consumer.RecordedEvent;
|
||||||
import jdk.jfr.consumer.RecordedThread;
|
import jdk.jfr.consumer.RecordedThread;
|
||||||
@ -60,7 +59,6 @@ public class TestThreadCpuTimeEvent {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
testSimple();
|
testSimple();
|
||||||
testCompareWithMXBean();
|
|
||||||
testEventAtThreadExit();
|
testEventAtThreadExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,32 +133,6 @@ public class TestThreadCpuTimeEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Duration getAccumulatedTime(List<RecordedEvent> events, String threadName, String fieldName) {
|
|
||||||
List<RecordedEvent> filteredEvents = events.stream()
|
|
||||||
.filter(e -> e.getThread().getJavaName().equals(threadName))
|
|
||||||
.sorted(Comparator.comparing(RecordedEvent::getStartTime))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
int numCpus = Runtime.getRuntime().availableProcessors();
|
|
||||||
Iterator<RecordedEvent> i = filteredEvents.iterator();
|
|
||||||
RecordedEvent cur = i.next();
|
|
||||||
Duration totalTime = Duration.ZERO;
|
|
||||||
while (i.hasNext()) {
|
|
||||||
RecordedEvent prev = cur;
|
|
||||||
cur = i.next();
|
|
||||||
|
|
||||||
Duration sampleTime = Duration.between(prev.getStartTime(), cur.getStartTime());
|
|
||||||
Float load = (Float)cur.getValue(fieldName);
|
|
||||||
|
|
||||||
// Adjust load to be thread-relative (fully loaded thread would give 100%)
|
|
||||||
Float totalLoadForThread = load * numCpus;
|
|
||||||
Duration threadTime = Duration.ofMillis((long) (sampleTime.toMillis() * totalLoadForThread));
|
|
||||||
totalTime = totalTime.plus(threadTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<RecordedEvent> generateEvents(int minimumEventCount, CyclicBarrier barrier) throws Throwable {
|
static List<RecordedEvent> generateEvents(int minimumEventCount, CyclicBarrier barrier) throws Throwable {
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
|
|
||||||
@ -209,39 +181,6 @@ public class TestThreadCpuTimeEvent {
|
|||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testCompareWithMXBean() throws Throwable {
|
|
||||||
Duration testRunTime = Duration.ofMillis(eventPeriodMillis * cpuConsumerRunFactor);
|
|
||||||
CyclicBarrier barrier = new CyclicBarrier(2);
|
|
||||||
CpuConsumingThread thread = new CpuConsumingThread(testRunTime, barrier);
|
|
||||||
thread.start();
|
|
||||||
|
|
||||||
List<RecordedEvent> beforeEvents = generateEvents(2, barrier);
|
|
||||||
verifyPerThreadInvariant(beforeEvents, cpuConsumerThreadName);
|
|
||||||
|
|
||||||
// Run a second single pass
|
|
||||||
barrier.await();
|
|
||||||
barrier.await();
|
|
||||||
|
|
||||||
ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean();
|
|
||||||
Duration cpuTime = Duration.ofNanos(bean.getThreadCpuTime(thread.getId()));
|
|
||||||
Duration userTime = Duration.ofNanos(bean.getThreadUserTime(thread.getId()));
|
|
||||||
|
|
||||||
// Check something that should hold even in the presence of unfortunate scheduling
|
|
||||||
Asserts.assertGreaterThanOrEqual(cpuTime.toMillis(), eventPeriodMillis);
|
|
||||||
Asserts.assertGreaterThanOrEqual(userTime.toMillis(), eventPeriodMillis);
|
|
||||||
|
|
||||||
Duration systemTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "system");
|
|
||||||
Duration userTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "user");
|
|
||||||
Duration cpuTimeBefore = userTimeBefore.plus(systemTimeBefore);
|
|
||||||
|
|
||||||
Asserts.assertLessThan(cpuTimeBefore, cpuTime);
|
|
||||||
Asserts.assertLessThan(userTimeBefore, userTime);
|
|
||||||
Asserts.assertGreaterThan(cpuTimeBefore, Duration.ZERO);
|
|
||||||
|
|
||||||
thread.interrupt();
|
|
||||||
thread.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void testEventAtThreadExit() throws Throwable {
|
static void testEventAtThreadExit() throws Throwable {
|
||||||
Recording recording = new Recording();
|
Recording recording = new Recording();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user