public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] fix #4318: ui: qemu/Monitor: rework output retention mechanism
Date: Mon, 31 Oct 2022 13:53:32 +0100	[thread overview]
Message-ID: <20221031125332.3775472-1-d.csapak@proxmox.com> (raw)

instead of saving maximum 500 lines, count commands + lines, and only
if both are over the limit, truncate the command list

this way, at least the last 10 commands + output are always visible, and
no visible output is truncated, while still not letting the log
grow infinitely

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/manager6/qemu/Monitor.js | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/www/manager6/qemu/Monitor.js b/www/manager6/qemu/Monitor.js
index d85018e6..a8ecfe97 100644
--- a/www/manager6/qemu/Monitor.js
+++ b/www/manager6/qemu/Monitor.js
@@ -3,7 +3,10 @@ Ext.define('PVE.qemu.Monitor', {
 
     alias: 'widget.pveQemuMonitor',
 
-    maxLines: 500,
+    // minimum number of commands + output saved
+    commandLimit: 10,
+    // minimum number of lines saved
+    lineLimit: 500,
 
     initComponent: function() {
 	var me = this;
@@ -20,7 +23,7 @@ Ext.define('PVE.qemu.Monitor', {
 
 	var history = [];
 	var histNum = -1;
-	var lines = [];
+	var commands = [];
 
 	var textbox = Ext.createWidget('panel', {
 	    region: 'center',
@@ -45,19 +48,23 @@ Ext.define('PVE.qemu.Monitor', {
 	};
 
 	var refresh = function() {
-	    textbox.update('<pre>' + lines.join('\n') + '</pre>');
+	    textbox.update('<pre>' + commands.flat(2).join('\n') + '</pre>');
 	    scrollToEnd();
 	};
 
-	var addLine = function(line) {
-	    lines.push(line);
-	    if (lines.length > me.maxLines) {
-		lines.shift();
+	var addCommand = function(line) {
+	    commands.push([line]);
+	    while (commands.length > me.commandLimit && commands.flat(2).length > me.lineLimit) {
+		commands.shift();
 	    }
 	};
 
+	var addResponse = function(lines) {
+	    commands[commands.length - 1].push(lines);
+	}
+
 	var executeCmd = function(cmd) {
-	    addLine("# " + Ext.htmlEncode(cmd));
+	    addCommand("# " + Ext.htmlEncode(cmd), true);
 	    if (cmd) {
 		history.unshift(cmd);
 		if (history.length > 20) {
@@ -74,9 +81,7 @@ Ext.define('PVE.qemu.Monitor', {
 		waitMsgTarget: me,
 		success: function(response, opts) {
 		    var res = response.result.data;
-		    Ext.Array.each(res.split('\n'), function(line) {
-			addLine(Ext.htmlEncode(line));
-		    });
+		    addResponse(res.split('\n').map((line) => Ext.htmlEncode(line)));
 		    refresh();
 		},
 		failure: function(response, opts) {
@@ -102,7 +107,7 @@ Ext.define('PVE.qemu.Monitor', {
 		    listeners: {
 			afterrender: function(f) {
 			    f.focus(false);
-			    addLine("Type 'help' for help.");
+			    addCommand("Type 'help' for help.");
 			    refresh();
 			},
 			specialkey: function(f, e) {
-- 
2.30.2





             reply	other threads:[~2022-10-31 12:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 12:53 Dominik Csapak [this message]
2022-11-02 11:00 ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221031125332.3775472-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal