author | never |
Mon, 25 Nov 2019 11:13:02 -0800 | |
changeset 59260 | b0a649295f25 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
26 |
#include "com_sun_management_internal_OperatingSystemImpl.h" |
12047 | 27 |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
28 |
#include <sys/time.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
29 |
#include <mach/mach.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
30 |
#include <mach/task_info.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
31 |
|
23566
760a74c1b589
8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents:
23010
diff
changeset
|
32 |
#include "jvm.h" |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
33 |
|
12047 | 34 |
JNIEXPORT jdouble JNICALL |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
35 |
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0 |
12047 | 36 |
(JNIEnv *env, jobject dummy) |
37 |
{ |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
38 |
// This code is influenced by the darwin top source |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
39 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
40 |
kern_return_t kr; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
41 |
mach_msg_type_number_t count; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
42 |
host_cpu_load_info_data_t load; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
43 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
44 |
static jlong last_used = 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
45 |
static jlong last_total = 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
46 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
47 |
count = HOST_CPU_LOAD_INFO_COUNT; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
48 |
kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&load, &count); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
49 |
if (kr != KERN_SUCCESS) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
50 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
51 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
52 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
53 |
jlong used = load.cpu_ticks[CPU_STATE_USER] + load.cpu_ticks[CPU_STATE_NICE] + load.cpu_ticks[CPU_STATE_SYSTEM]; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
54 |
jlong total = used + load.cpu_ticks[CPU_STATE_IDLE]; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
55 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
56 |
if (last_used == 0 || last_total == 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
57 |
// First call, just set the last values |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
58 |
last_used = used; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
59 |
last_total = total; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
60 |
// return 0 since we have no data, not -1 which indicates error |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
61 |
return 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
62 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
63 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
64 |
jlong used_delta = used - last_used; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
65 |
jlong total_delta = total - last_total; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
66 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
67 |
jdouble cpu = (jdouble) used_delta / total_delta; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
68 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
69 |
last_used = used; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
70 |
last_total = total; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
71 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
72 |
return cpu; |
12047 | 73 |
} |
74 |
||
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
75 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
76 |
#define TIME_VALUE_TO_TIMEVAL(a, r) do { \ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
77 |
(r)->tv_sec = (a)->seconds; \ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
78 |
(r)->tv_usec = (a)->microseconds; \ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
79 |
} while (0) |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
80 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
81 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
82 |
#define TIME_VALUE_TO_MICROSECONDS(TV) \ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
83 |
((TV).tv_sec * 1000 * 1000 + (TV).tv_usec) |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
84 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
85 |
|
12047 | 86 |
JNIEXPORT jdouble JNICALL |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
87 |
Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0 |
12047 | 88 |
(JNIEnv *env, jobject dummy) |
89 |
{ |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
90 |
// This code is influenced by the darwin top source |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
91 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
92 |
struct task_basic_info_64 task_info_data; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
93 |
struct task_thread_times_info thread_info_data; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
94 |
struct timeval user_timeval, system_timeval, task_timeval; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
95 |
struct timeval now; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
96 |
mach_port_t task = mach_task_self(); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
97 |
kern_return_t kr; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
98 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
99 |
static jlong last_task_time = 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
100 |
static jlong last_time = 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
101 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
102 |
mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
103 |
kr = task_info(task, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
104 |
TASK_THREAD_TIMES_INFO, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
105 |
(task_info_t)&thread_info_data, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
106 |
&thread_info_count); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
107 |
if (kr != KERN_SUCCESS) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
108 |
// Most likely cause: |task| is a zombie. |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
109 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
110 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
111 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
112 |
mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
113 |
kr = task_info(task, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
114 |
TASK_BASIC_INFO_64, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
115 |
(task_info_t)&task_info_data, |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
116 |
&count); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
117 |
if (kr != KERN_SUCCESS) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
118 |
// Most likely cause: |task| is a zombie. |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
119 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
120 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
121 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
122 |
/* Set total_time. */ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
123 |
// thread info contains live time... |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
124 |
TIME_VALUE_TO_TIMEVAL(&thread_info_data.user_time, &user_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
125 |
TIME_VALUE_TO_TIMEVAL(&thread_info_data.system_time, &system_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
126 |
timeradd(&user_timeval, &system_timeval, &task_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
127 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
128 |
// ... task info contains terminated time. |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
129 |
TIME_VALUE_TO_TIMEVAL(&task_info_data.user_time, &user_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
130 |
TIME_VALUE_TO_TIMEVAL(&task_info_data.system_time, &system_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
131 |
timeradd(&user_timeval, &task_timeval, &task_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
132 |
timeradd(&system_timeval, &task_timeval, &task_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
133 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
134 |
if (gettimeofday(&now, NULL) < 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
135 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
136 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
137 |
jint ncpus = JVM_ActiveProcessorCount(); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
138 |
jlong time = TIME_VALUE_TO_MICROSECONDS(now) * ncpus; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
139 |
jlong task_time = TIME_VALUE_TO_MICROSECONDS(task_timeval); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
140 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
141 |
if ((last_task_time == 0) || (last_time == 0)) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
142 |
// First call, just set the last values. |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
143 |
last_task_time = task_time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
144 |
last_time = time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
145 |
// return 0 since we have no data, not -1 which indicates error |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
146 |
return 0; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
147 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
148 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
149 |
jlong task_time_delta = task_time - last_task_time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
150 |
jlong time_delta = time - last_time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
151 |
if (time_delta == 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
152 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
153 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
154 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
155 |
jdouble cpu = (jdouble) task_time_delta / time_delta; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
156 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
157 |
last_task_time = task_time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
158 |
last_time = time; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
159 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
160 |
return cpu; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
161 |
} |