File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
test/jdk/jdk/jfr/event/os Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2013, 2018 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3030import jdk .test .lib .jfr .EventNames ;
3131import jdk .test .lib .jfr .Events ;
3232
33-
3433/**
3534 * @test
3635 * @key jfr
4140public class TestCPULoad {
4241 private final static String EVENT_NAME = EventNames .CPULoad ;
4342
43+ public static boolean isPrime (int num ) {
44+ if (num <= 1 ) return false ;
45+ for (int i = 2 ; i <= Math .sqrt (num ); i ++) {
46+ if (num % i == 0 ) return false ;
47+ }
48+ return true ;
49+ }
50+
51+ public static int burnCpuCycles (int limit ) {
52+ int primeCount = 0 ;
53+ for (int i = 2 ; i < limit ; i ++) {
54+ if (isPrime (i )) {
55+ primeCount ++;
56+ }
57+ }
58+ return primeCount ;
59+ }
60+
4461 public static void main (String [] args ) throws Throwable {
4562 Recording recording = new Recording ();
4663 recording .enable (EVENT_NAME );
4764 recording .start ();
48- // Need to sleep so a time delta can be calculated
49- Thread . sleep ( 100 );
65+ // burn some cycles to check increase of CPU related counters
66+ int pn = burnCpuCycles ( 2500000 );
5067 recording .stop ();
68+ System .out .println ("Found " + pn + " primes while burning cycles" );
5169
5270 List <RecordedEvent > events = Events .fromRecording (recording );
5371 if (events .isEmpty ()) {
You can’t perform that action at this time.
0 commit comments