diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 4d04923..2b438ef 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -336,6 +336,21 @@ public class ECMA48Terminal extends LogicalScreen */ private boolean hasSynchronizedOutput = false; + /** + * The time we last flushed output in flushPhysical(). + */ + private long lastFlushTime; + + /** + * The bytes being written in this second. + */ + private int bytesPerSecond; + + /** + * The bytes per second for the last second. + */ + private int lastBytesPerSecond; + /** * The terminal's input. If an InputStream is not specified in the * constructor, then this InputStreamReader will be bound to System.in @@ -882,6 +897,15 @@ public class ECMA48Terminal extends LogicalScreen } } output.flush(); + + long now = System.currentTimeMillis(); + if ((int) (now / 1000) == (int) (lastFlushTime / 1000)) { + bytesPerSecond += sb.length(); + } else { + lastBytesPerSecond = sb.length(); + bytesPerSecond = 0; + } + lastFlushTime = now; } } @@ -1296,6 +1320,15 @@ public class ECMA48Terminal extends LogicalScreen // ECMA48Terminal --------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Get the bytes per second from the last second. + * + * @return the bytes per second + */ + public int getBytesPerSecond() { + return lastBytesPerSecond; + } + /** * Get the width of a character cell in pixels. * diff --git a/src/jexer/demos/DemoApplication.java b/src/jexer/demos/DemoApplication.java index 20c1628..f8e0b16 100644 --- a/src/jexer/demos/DemoApplication.java +++ b/src/jexer/demos/DemoApplication.java @@ -45,6 +45,7 @@ import jexer.TEditorWindow; import jexer.TWidget; import jexer.TWindow; import jexer.bits.BorderStyle; +import jexer.backend.ECMA48Terminal; import jexer.event.TMenuEvent; import jexer.menu.TMenu; import jexer.menu.TMenuItem; @@ -302,7 +303,27 @@ public class DemoApplication extends TApplication { */ @Override protected void onPreDraw() { - menuTrayText = String.format("FPS %d", getFramesPerSecond()); + if (getScreen() instanceof ECMA48Terminal) { + ECMA48Terminal terminal = (ECMA48Terminal) getScreen(); + int bytes = terminal.getBytesPerSecond(); + String bps = ""; + if (bytes > 1024 * 1024 * 1024) { + bps = String.format("%4.2f GB/s", + ((double) bytes / (1024 * 1024 * 1024))); + } else if (bytes > 1024 * 1024) { + bps = String.format("%4.2f MB/s", + ((double) bytes / (1024 * 1024))); + } else if (bytes > 1024) { + bps = String.format("%4.2f KB/s", + ((double) bytes / 1024)); + } else { + bps = String.format("%d bytes/s", bytes); + } + menuTrayText = String.format("%s FPS %d", bps, + getFramesPerSecond()); + } else { + menuTrayText = String.format("FPS %d", getFramesPerSecond()); + } } // ------------------------------------------------------------------------