use of java.lang.management.ThreadInfo 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);
}
}
use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.
the class ThreadStackSampler method prime.
public void prime() {
ThreadInfo[] ti = threading.dumpAllThreads(false, false);
long[] tids = new long[ti.length];
int n = 0;
for (ThreadInfo t : ti) {
long tid = t.getThreadId();
String name = t.getThreadName();
if (threadFilter == null || threadFilter.matcher(name).matches()) {
tids[n++] = tid;
}
}
tids = Arrays.copyOf(tids, n);
threadSet = tids;
}
use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.
the class ThreadStackSampler method collect.
public void collect() {
long timestamp = System.currentTimeMillis();
ThreadInfo[] dump = threading.getThreadInfo(threadSet, Integer.MAX_VALUE);
for (ThreadInfo ti : dump) {
Trace trace = newTrace(timestamp, ti);
if (trace != null) {
traces.add(trace);
}
}
}
use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.
the class ThreadDumpSampler method compactThreads.
private ThreadInfo[] compactThreads(ThreadInfo[] dumpAllThreads) {
int n = 0;
for (int i = 0; i != dumpAllThreads.length; ++i) {
if (dumpAllThreads[i] != null) {
++n;
}
}
if (n == dumpAllThreads.length) {
return dumpAllThreads;
} else {
ThreadInfo[] result = new ThreadInfo[n];
n = 0;
for (ThreadInfo ti : dumpAllThreads) {
if (ti != null) {
result[n++] = ti;
}
}
return result;
}
}
use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.
the class ThreadDumpSampler method filterThreads.
private ThreadInfo[] filterThreads(ThreadInfo[] dumpAllThreads) {
if (threadFilter == null) {
return compactThreads(dumpAllThreads);
} else {
Matcher m = threadFilter.matcher("");
int n = 0;
for (int i = 0; i != dumpAllThreads.length; ++i) {
if (dumpAllThreads[i] != null) {
m.reset(dumpAllThreads[i].getThreadName());
if (m.matches()) {
++n;
} else {
dumpAllThreads[i] = null;
}
}
}
if (n == dumpAllThreads.length) {
return dumpAllThreads;
} else {
ThreadInfo[] result = new ThreadInfo[n];
n = 0;
for (ThreadInfo ti : dumpAllThreads) {
if (ti != null) {
result[n++] = ti;
}
}
return result;
}
}
}
Aggregations