use of gnu.trove.TLongLongHashMap in project intellij-community by JetBrains.
the class CpuUsageData method measureCpuUsage.
public static <E extends Throwable> CpuUsageData measureCpuUsage(ThrowableRunnable<E> runnable) throws E {
FreeMemorySnapshot memStart = new FreeMemorySnapshot();
TObjectLongHashMap<GarbageCollectorMXBean> gcTimes = new TObjectLongHashMap<>();
for (GarbageCollectorMXBean bean : ourGcBeans) {
gcTimes.put(bean, bean.getCollectionTime());
}
TLongLongHashMap threadTimes = new TLongLongHashMap();
for (long id : ourThreadMXBean.getAllThreadIds()) {
threadTimes.put(id, ourThreadMXBean.getThreadUserTime(id));
}
long compStart = ourCompilationMXBean.getTotalCompilationTime();
long start = System.currentTimeMillis();
runnable.run();
long duration = System.currentTimeMillis() - start;
long compTime = ourCompilationMXBean.getTotalCompilationTime() - compStart;
FreeMemorySnapshot memEnd = new FreeMemorySnapshot();
for (long id : ourThreadMXBean.getAllThreadIds()) {
threadTimes.put(id, ourThreadMXBean.getThreadUserTime(id) - threadTimes.get(id));
}
for (GarbageCollectorMXBean bean : ourGcBeans) {
gcTimes.put(bean, bean.getCollectionTime() - gcTimes.get(bean));
}
return new CpuUsageData(duration, gcTimes, threadTimes, compTime, memStart, memEnd);
}
Aggregations