implement TerraPlugin#getProfier

This commit is contained in:
dfsek
2021-04-12 00:05:53 -07:00
parent 168c0ced13
commit eb4bf74cc6
7 changed files with 56 additions and 22 deletions
@@ -3,8 +3,6 @@ package com.dfsek.terra.profiler;
import java.util.Map;
public interface Profiler {
ProfilerImpl INSTANCE = new ProfilerImpl();
void push(String frame);
void pop(String frame);
@@ -13,10 +13,12 @@ public class ProfilerImpl implements Profiler {
private static final ThreadLocal<Map<String, List<Long>>> TIMINGS = ThreadLocal.withInitial(HashMap::new);
private final List<Map<String, List<Long>>> accessibleThreadMaps = new ArrayList<>();
private volatile boolean running = false;
private static boolean instantiated = false;
public ProfilerImpl() {
if(instantiated) throw new IllegalStateException("Only one instance of Profiler may exist!");
instantiated = true;
}
@Override
@@ -64,16 +66,14 @@ public class ProfilerImpl implements Profiler {
@Override
public Map<String, Timings> getTimings() {
Map<String, Timings> map = new HashMap<>();
accessibleThreadMaps.forEach(smap -> {
smap.forEach((key, list) -> {
String[] keys = key.split("\\.");
Timings timings = map.computeIfAbsent(keys[0], id -> new Timings());
for(int i = 1; i < keys.length; i++) {
timings = timings.getSubItem(keys[i]);
}
list.forEach(timings::addTime);
});
});
accessibleThreadMaps.forEach(smap -> smap.forEach((key, list) -> {
String[] keys = key.split("\\.");
Timings timings = map.computeIfAbsent(keys[0], id -> new Timings());
for(int i = 1; i < keys.length; i++) {
timings = timings.getSubItem(keys[i]);
}
list.forEach(timings::addTime);
}));
return map;
}
}