log render time stats periodically

This commit is contained in:
bancika
2020-04-06 11:40:18 +02:00
parent 3933c4c1b3
commit 4cf840b32a
2 changed files with 42 additions and 0 deletions
@@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
@@ -57,6 +58,7 @@ import org.diylc.core.Project;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
import org.diylc.utils.Pair;
/** /**
* Utility that deals with painting {@link Project} on the {@link Graphics2D} and keeps areas taken * Utility that deals with painting {@link Project} on the {@link Graphics2D} and keeps areas taken
@@ -105,6 +107,11 @@ public class DrawingManager {
private boolean debugComponentAreas; private boolean debugComponentAreas;
private boolean debugContinuityAreas; private boolean debugContinuityAreas;
// rendering stats
private Map<String, Pair<Integer, Long>> renderStatsByType = new HashMap<String, Pair<Integer, Long>>();
private long lastStatsReportedTime = System.currentTimeMillis();
private long statReportFrequencyMs = 1000 * 60;
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) { public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
super(); super();
@@ -277,6 +284,7 @@ public class DrawingManager {
g2d.setComposite(lockedComposite); g2d.setComposite(lockedComposite);
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
long componentStart = System.nanoTime();
try { try {
if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache
@@ -294,6 +302,32 @@ public class DrawingManager {
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error drawing " + component.getName(), e); LOG.error("Error drawing " + component.getName(), e);
failedComponents.add(component); failedComponents.add(component);
} finally {
// record render stats
long componentEnd = System.nanoTime();
Pair<Integer, Long> stats = null;
String key = component.getClass().getCanonicalName();
if (renderStatsByType.containsKey(key)) {
stats = renderStatsByType.get(key);
stats.setFirst(stats.getFirst() + 1);
stats.setSecond(stats.getSecond() + (componentEnd - componentStart));
} else {
stats = new Pair<Integer, Long>(1, componentEnd - componentStart);
renderStatsByType.put(key, stats);
}
// log render time stats periodically
if (System.currentTimeMillis() - lastStatsReportedTime > statReportFrequencyMs) {
lastStatsReportedTime = System.currentTimeMillis();
String mapAsString = renderStatsByType.keySet().stream()
.map(k -> {
Pair<Integer, Long> s = renderStatsByType.get(k);
return k + "=" + s.getFirst() + "x " +
TimeUnit.MILLISECONDS.convert(s.getSecond(), TimeUnit.NANOSECONDS) + "ms ";
})
.collect(Collectors.joining(", ", "{", "}"));
LOG.debug("Render stats: " + mapAsString);
}
} }
ComponentArea area = g2dWrapper.finishedDrawingComponent(); ComponentArea area = g2dWrapper.finishedDrawingComponent();
if (trackArea && area != null && !area.getOutlineArea().isEmpty()) { if (trackArea && area != null && !area.getOutlineArea().isEmpty()) {
@@ -38,5 +38,13 @@ public class Pair<A, B> {
public B getSecond() { public B getSecond() {
return second; return second;
}
public void setFirst(A first) {
this.first = first;
}
public void setSecond(B second) {
this.second = second;
} }
} }