01: /*
02: * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.management;
27:
28: import java.util.Map;
29: import java.util.HashMap;
30: import sun.management.counter.Counter;
31:
32: /**
33: * Implementation class of HotspotThreadMBean interface.
34: *
35: * Internal, uncommitted management interface for Hotspot threading
36: * system.
37: */
38: class HotspotThread implements HotspotThreadMBean {
39:
40: private VMManagement jvm;
41:
42: /**
43: * Constructor of HotspotThread class.
44: */
45: HotspotThread(VMManagement vm) {
46: jvm = vm;
47: }
48:
49: public native int getInternalThreadCount();
50:
51: public Map<String, Long> getInternalThreadCpuTimes() {
52: int count = getInternalThreadCount();
53: if (count == 0) {
54: return java.util.Collections.emptyMap();
55: }
56: String[] names = new String[count];
57: long[] times = new long[count];
58: int numThreads = getInternalThreadTimes0(names, times);
59: Map<String, Long> result = new HashMap<String, Long>(numThreads);
60: for (int i = 0; i < numThreads; i++) {
61: result.put(names[i], new Long(times[i]));
62: }
63: return result;
64: }
65:
66: public native int getInternalThreadTimes0(String[] names,
67: long[] times);
68:
69: // Performance counter support
70: private static final String JAVA_THREADS = "java.threads.";
71: private static final String COM_SUN_THREADS = "com.sun.threads.";
72: private static final String SUN_THREADS = "sun.threads.";
73: private static final String THREADS_COUNTER_NAME_PATTERN = JAVA_THREADS
74: + "|" + COM_SUN_THREADS + "|" + SUN_THREADS;
75:
76: public java.util.List<Counter> getInternalThreadingCounters() {
77: return jvm.getInternalCounters(THREADS_COUNTER_NAME_PATTERN);
78: }
79: }
|