mirror of
https://gitlab.com/AutumnMeowMeow/jexer
synced 2024-09-19 11:50:19 -06:00
#104 report screen throughput on ECMA48 backend
This commit is contained in:
parent
c6d5d2b6a0
commit
9e824d90b7
2 changed files with 55 additions and 1 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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,8 +303,28 @@ public class DemoApplication extends TApplication {
|
|||
*/
|
||||
@Override
|
||||
protected void onPreDraw() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// DemoApplication --------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue