< prev index next >

test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java

Print this page
rev 56807 : [mq]: 8232684-v2


  90         CpuConsumingThread(Duration runTime, CyclicBarrier barrier) {
  91             this(runTime, barrier, cpuConsumerThreadName);
  92         }
  93 
  94         @Override
  95         public void run() {
  96             try {
  97                 while (true) {
  98                     barrier.await();
  99                     Instant start = Instant.now();
 100                     counter = 0;
 101                     while ((Duration.between(start, Instant.now()).compareTo(runTime) < 0) ||
 102                             (counter < cpuConsumerMinCount)) {
 103                         counter++;
 104                     }
 105                     barrier.await();
 106                 }
 107             } catch (BrokenBarrierException e) {
 108                 // Another thread has been interrupted - wait for us to be interrupted as well
 109                 while (!interrupted()) {
 110                     yield();
 111                 }
 112             } catch (InterruptedException e) {
 113                 // Normal way of stopping the thread
 114             }
 115         }
 116     }
 117 
 118     // For a given thread, check that accumulated processTime >= cpuTime >= userTime.
 119     // This may not hold for a single event instance due to differences in counter resolution
 120     static void verifyPerThreadInvariant(List<RecordedEvent> events, String threadName) {
 121         List<RecordedEvent> filteredEvents = events.stream()
 122                 .filter(e -> e.getThread().getJavaName().equals(threadName))
 123                 .sorted(Comparator.comparing(RecordedEvent::getStartTime))
 124                 .collect(Collectors.toList());
 125 
 126         int numCpus = Runtime.getRuntime().availableProcessors();
 127         Iterator<RecordedEvent> i = filteredEvents.iterator();
 128         while (i.hasNext()) {
 129             RecordedEvent event = i.next();
 130 




  90         CpuConsumingThread(Duration runTime, CyclicBarrier barrier) {
  91             this(runTime, barrier, cpuConsumerThreadName);
  92         }
  93 
  94         @Override
  95         public void run() {
  96             try {
  97                 while (true) {
  98                     barrier.await();
  99                     Instant start = Instant.now();
 100                     counter = 0;
 101                     while ((Duration.between(start, Instant.now()).compareTo(runTime) < 0) ||
 102                             (counter < cpuConsumerMinCount)) {
 103                         counter++;
 104                     }
 105                     barrier.await();
 106                 }
 107             } catch (BrokenBarrierException e) {
 108                 // Another thread has been interrupted - wait for us to be interrupted as well
 109                 while (!interrupted()) {
 110                     Thread.yield();
 111                 }
 112             } catch (InterruptedException e) {
 113                 // Normal way of stopping the thread
 114             }
 115         }
 116     }
 117 
 118     // For a given thread, check that accumulated processTime >= cpuTime >= userTime.
 119     // This may not hold for a single event instance due to differences in counter resolution
 120     static void verifyPerThreadInvariant(List<RecordedEvent> events, String threadName) {
 121         List<RecordedEvent> filteredEvents = events.stream()
 122                 .filter(e -> e.getThread().getJavaName().equals(threadName))
 123                 .sorted(Comparator.comparing(RecordedEvent::getStartTime))
 124                 .collect(Collectors.toList());
 125 
 126         int numCpus = Runtime.getRuntime().availableProcessors();
 127         Iterator<RecordedEvent> i = filteredEvents.iterator();
 128         while (i.hasNext()) {
 129             RecordedEvent event = i.next();
 130 


< prev index next >