1 /* |
1 /* |
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
26 #include "logging/log.hpp" |
26 #include "logging/log.hpp" |
27 #include "jfr/jfrEvents.hpp" |
27 #include "jfr/jfrEvents.hpp" |
28 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
28 #include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
29 #include "jfr/support/jfrThreadId.hpp" |
29 #include "jfr/support/jfrThreadId.hpp" |
30 #include "jfr/support/jfrThreadLocal.hpp" |
30 #include "jfr/support/jfrThreadLocal.hpp" |
|
31 #include "jfr/utilities/jfrThreadIterator.hpp" |
31 #include "jfr/utilities/jfrTime.hpp" |
32 #include "jfr/utilities/jfrTime.hpp" |
32 #include "utilities/globalDefinitions.hpp" |
33 #include "utilities/globalDefinitions.hpp" |
33 #include "runtime/os.hpp" |
34 #include "runtime/os.hpp" |
34 #include "runtime/thread.inline.hpp" |
|
35 #include "runtime/threadSMR.inline.hpp" |
|
36 |
35 |
37 jlong JfrThreadCPULoadEvent::get_wallclock_time() { |
36 jlong JfrThreadCPULoadEvent::get_wallclock_time() { |
38 return os::javaTimeNanos(); |
37 return os::javaTimeNanos(); |
39 } |
38 } |
40 |
39 |
113 traceid periodic_thread_id = periodic_thread_tl->thread_id(); |
112 traceid periodic_thread_id = periodic_thread_tl->thread_id(); |
114 const int processor_count = JfrThreadCPULoadEvent::get_processor_count(); |
113 const int processor_count = JfrThreadCPULoadEvent::get_processor_count(); |
115 JfrTicks event_time = JfrTicks::now(); |
114 JfrTicks event_time = JfrTicks::now(); |
116 jlong cur_wallclock_time = JfrThreadCPULoadEvent::get_wallclock_time(); |
115 jlong cur_wallclock_time = JfrThreadCPULoadEvent::get_wallclock_time(); |
117 |
116 |
118 JavaThreadIteratorWithHandle jtiwh; |
117 JfrJavaThreadIterator iter; |
119 while (JavaThread* jt = jtiwh.next()) { |
118 int number_of_threads = 0; |
|
119 while (iter.has_next()) { |
|
120 JavaThread* const jt = iter.next(); |
|
121 assert(jt != NULL, "invariant"); |
|
122 ++number_of_threads; |
120 EventThreadCPULoad event(UNTIMED); |
123 EventThreadCPULoad event(UNTIMED); |
121 if (JfrThreadCPULoadEvent::update_event(event, jt, cur_wallclock_time, processor_count)) { |
124 if (JfrThreadCPULoadEvent::update_event(event, jt, cur_wallclock_time, processor_count)) { |
122 event.set_starttime(event_time); |
125 event.set_starttime(event_time); |
123 if (jt != periodic_thread) { |
126 if (jt != periodic_thread) { |
124 // Commit reads the thread id from this thread's trace data, so put it there temporarily |
127 // Commit reads the thread id from this thread's trace data, so put it there temporarily |
127 periodic_thread_tl->set_thread_id(periodic_thread_id); |
130 periodic_thread_tl->set_thread_id(periodic_thread_id); |
128 } |
131 } |
129 event.commit(); |
132 event.commit(); |
130 } |
133 } |
131 } |
134 } |
132 log_trace(jfr)("Measured CPU usage for %d threads in %.3f milliseconds", jtiwh.length(), |
135 log_trace(jfr)("Measured CPU usage for %d threads in %.3f milliseconds", number_of_threads, |
133 (double)(JfrTicks::now() - event_time).milliseconds()); |
136 (double)(JfrTicks::now() - event_time).milliseconds()); |
134 // Restore this thread's thread id |
137 // Restore this thread's thread id |
135 periodic_thread_tl->set_thread_id(periodic_thread_id); |
138 periodic_thread_tl->set_thread_id(periodic_thread_id); |
136 } |
139 } |
137 |
140 |