@@ -62,7 +62,7 @@ Java_com_sun_management_internal_OperatingSystemImpl_getCpuLoad0
62
62
cpu_total_old = cpu_total ;
63
63
initialized = 1 ;
64
64
last_sample_time = now ;
65
- return -1.0 ; // Not enough data yet
65
+ return -1.0 ;
66
66
}
67
67
68
68
long long user_diff = cpu_total .user - cpu_total_old .user ;
@@ -75,14 +75,7 @@ Java_com_sun_management_internal_OperatingSystemImpl_getCpuLoad0
75
75
return -1.0 ;
76
76
}
77
77
78
- printf ("User diff: %lld\n" , user_diff );
79
- printf ("Sys diff: %lld\n" , sys_diff );
80
- printf ("Idle diff: %lld\n" , idle_diff );
81
- printf ("Wait diff: %lld\n" , wait_diff );
82
-
83
-
84
78
double load = (double )(user_diff + sys_diff ) / total ;
85
- printf ("load:%.4f\n" ,load );
86
79
fflush (stdout );
87
80
last_cpu_load = load ;
88
81
last_sample_time = now ;
@@ -101,36 +94,27 @@ Java_com_sun_management_internal_OperatingSystemImpl_getProcessCpuLoad0
101
94
double user_diff , sys_diff , delta_time ;
102
95
103
96
if (perfstat_process (& id , & curr_stats , sizeof (perfstat_process_t ), 1 ) < 0 ) {
104
- return -1.0 ;
97
+ return -1.0 ;
105
98
}
106
99
if (!initialized ) {
107
100
prev_stats = curr_stats ;
108
101
prev_timebase = curr_stats .last_timebase ;
109
102
initialized = 1 ;
110
103
return -1.0 ;
111
104
}
112
- printf ("initialised done" );
113
105
curr_timebase = curr_stats .last_timebase ;
114
106
timebase_diff = curr_timebase - prev_timebase ;
115
-
116
107
if ((long long )timebase_diff <= 0 || XINTFRAC == 0 ) {
117
108
return -1.0 ;
118
109
}
119
110
120
111
delta_time = HTIC2SEC (timebase_diff );
121
-
122
112
user_diff = (double )(curr_stats .ucpu_time - prev_stats .ucpu_time );
123
113
sys_diff = (double )(curr_stats .scpu_time - prev_stats .scpu_time );
124
-
125
114
prev_stats = curr_stats ;
126
115
prev_timebase = curr_timebase ;
127
-
128
116
double cpu_load = (user_diff + sys_diff ) / delta_time ;
129
-
130
117
return (jdouble )cpu_load ;
131
-
132
-
133
-
134
118
}
135
119
136
120
JNIEXPORT jdouble JNICALL
0 commit comments