changeset 20:391245b793a0

Improve time graph resolution.
author shade
date Sat, 04 Feb 2017 15:49:51 +0100
parents f9c3416370ee
children d36d1debfbf5
files src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java	Wed Feb 01 11:54:26 2017 +0100
+++ b/src/main/java/org/openjdk/shenandoah/ShenandoahVisualizer.java	Sat Feb 04 15:49:51 2017 +0100
@@ -151,18 +151,22 @@
         // Draw graph
         {
             int Y_SIZE = PAD_TOP - PAD;
-            int X_SIZE = fieldWidth;
+            int X_SIZE = Math.min(lastSnapshots.size(), fieldWidth);
 
             g.setColor(Color.BLACK);
             g.fillRect(PAD, PAD, X_SIZE, Y_SIZE);
 
+            while (lastSnapshots.size() > X_SIZE) {
+                lastSnapshots.removeFirst();
+            }
+
             if (lastSnapshots.size() > 2) {
                 double stepY = 1D * Y_SIZE / snapshot.total();
                 long firstTime = lastSnapshots.getFirst().time();
                 long lastTime = lastSnapshots.getLast().time();
                 double stepX = 1D * X_SIZE / (lastTime - firstTime);
                 for (SnapshotView s : lastSnapshots) {
-                    int x = (int) (PAD + (s.time() - firstTime) * stepX);
+                    int x = (int) Math.round(PAD + (s.time() - firstTime) * stepX);
 
                     if (s.isMarking()) {
                         g.setColor(new Color(100, 100, 0));
@@ -175,15 +179,15 @@
                     }
 
                     g.setColor(Colors.USED);
-                    g.drawRect(x, PAD + (int) (Y_SIZE - s.used() * stepY), 1, 1);
+                    g.drawRect(x, PAD + (int) Math.round(Y_SIZE - s.used() * stepY), 1, 1);
                     g.setColor(Colors.USED_ALLOC);
-                    g.drawRect(x, PAD + (int) (Y_SIZE - s.recentlyAllocated() * stepY), 1, 1);
+                    g.drawRect(x, PAD + (int) Math.round(Y_SIZE - s.recentlyAllocated() * stepY), 1, 1);
                     g.setColor(Colors.HUMONGOUS);
-                    g.drawRect(x, PAD + (int) (Y_SIZE - s.humongous() * stepY), 1, 1);
+                    g.drawRect(x, PAD + (int) Math.round(Y_SIZE - s.humongous() * stepY), 1, 1);
                     g.setColor(Colors.LIVE);
-                    g.drawRect(x, PAD + (int) (Y_SIZE - s.live() * stepY), 1, 1);
+                    g.drawRect(x, PAD + (int) Math.round(Y_SIZE - s.live() * stepY), 1, 1);
                     g.setColor(Colors.CSET);
-                    g.drawRect(x, PAD + (int) (Y_SIZE - s.collectionSet() * stepY), 1, 1);
+                    g.drawRect(x, PAD + (int) Math.round(Y_SIZE - s.collectionSet() * stepY), 1, 1);
 
                 }
             }