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
26 #include "sun_management_OperatingSystemImpl.h"
27
28 #include <sys/time.h>
29 #include <mach/mach.h>
30 #include <mach/task_info.h>
31
32
33 JNIEXPORT jdouble JNICALL
34 Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
35 (JNIEnv *env, jobject dummy)
36 {
37 // This code is influenced by the darwin top source
38
39 kern_return_t kr;
40 mach_msg_type_number_t count;
41 host_cpu_load_info_data_t load;
42
43 static jlong last_used = 0;
44 static jlong last_total = 0;
45
46 count = HOST_CPU_LOAD_INFO_COUNT;
47 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&load, &count);
48 if (kr != KERN_SUCCESS) {
49 return -1;
50 }
51
|
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
26 #include "sun_management_OperatingSystemImpl.h"
27
28 #include <sys/time.h>
29 #include <mach/mach.h>
30 #include <mach/task_info.h>
31
32 #include "jvm.h"
33
34 JNIEXPORT jdouble JNICALL
35 Java_sun_management_OperatingSystemImpl_getSystemCpuLoad0
36 (JNIEnv *env, jobject dummy)
37 {
38 // This code is influenced by the darwin top source
39
40 kern_return_t kr;
41 mach_msg_type_number_t count;
42 host_cpu_load_info_data_t load;
43
44 static jlong last_used = 0;
45 static jlong last_total = 0;
46
47 count = HOST_CPU_LOAD_INFO_COUNT;
48 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&load, &count);
49 if (kr != KERN_SUCCESS) {
50 return -1;
51 }
52
|