use of org.gridkit.jvmtool.stacktrace.ThreadMXBeanEx in project jvm-tools by aragozin.
the class MBeanCpuUsageReporter method probe.
public void probe() {
try {
long[] ids = mbean.getAllThreadIds();
ThreadInfo[] ti = mbean.getThreadInfo(ids);
Map<Long, ThreadInfo> buf = new HashMap<Long, ThreadInfo>();
for (ThreadInfo t : ti) {
if (t != null) {
buf.put(t.getThreadId(), t);
}
}
for (Long key : threadDump.keySet()) {
ThreadTrac tt = threadDump.get(key);
ThreadInfo t = buf.remove(key);
if (t != null) {
tt.name = t.getThreadName();
tt.lastThreadInfo = t;
} else {
tt.dead = true;
}
}
for (ThreadInfo t : buf.values()) {
ThreadTrac tt = new ThreadTrac();
tt.name = t.getThreadName();
tt.lastThreadInfo = t;
threadDump.put(t.getThreadId(), tt);
}
if (threadAllocatedMemoryEnabled) {
long[] alloc = ((ThreadMXBeanEx) mbean).getThreadAllocatedBytes(ids);
for (int i = 0; i != ids.length; ++i) {
if (threadDump.get(ids[i]) == null) {
continue;
}
threadDump.get(ids[i]).lastAllocatedBytes = alloc[i];
}
}
if (bulkCpuEnabled) {
long[] cpu = ((ThreadMXBeanEx) mbean).getThreadCpuTime(ids);
long[] usr = ((ThreadMXBeanEx) mbean).getThreadUserTime(ids);
for (int i = 0; i != ids.length; ++i) {
if (threadDump.get(ids[i]) == null) {
continue;
}
threadDump.get(ids[i]).lastCpuTime = cpu[i];
threadDump.get(ids[i]).lastUserTime = usr[i];
}
} else {
for (long id : ids) {
if (threadDump.get(id) == null) {
continue;
}
ThreadTrac tt = threadDump.get(id);
tt.lastCpuTime = mbean.getThreadCpuTime(id);
tt.lastUserTime = mbean.getThreadCpuTime(id);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations