From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
(No client certificate requested)
by lists.proxmox.com (Postfix) with ESMTPS id 2D6988C781
for <pve-devel@lists.proxmox.com>; Wed, 2 Nov 2022 12:29:09 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 0E23222F3F
for <pve-devel@lists.proxmox.com>; Wed, 2 Nov 2022 12:28:39 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[94.136.29.106])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by firstgate.proxmox.com (Proxmox) with ESMTPS
for <pve-devel@lists.proxmox.com>; Wed, 2 Nov 2022 12:28:38 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1389244C56
for <pve-devel@lists.proxmox.com>; Wed, 2 Nov 2022 12:28:38 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 2 Nov 2022 12:28:37 +0100
Message-Id: <20221102112837.2450084-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.066 Adjusted score from AWL reputation of From: address
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH manager v2] fix #4318: ui: qemu/Monitor: rework
output retention mechanism
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 02 Nov 2022 11:29:09 -0000
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>
---
changes from v1:
* adapted to thomas suggestions
* var commands => let commands (since i'm touching the line anyway)
* i adapted the suggest comment from thomas, so it's more clear (imho)
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..7f1626e3 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,
+ // ouput is trimmed when it's over both commandLimit and lineLimit
+ // by removing the first commands and their output
+ commandLimit: 10,
+ lineLimit: 5000,
initComponent: function() {
var me = this;
@@ -20,7 +23,7 @@ Ext.define('PVE.qemu.Monitor', {
var history = [];
var histNum = -1;
- var lines = [];
+ let 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();
+ let recordInput = line => {
+ commands.push([line]);
+
+ // drop oldest commands and their output until we're not over both limits anymore
+ while (commands.length > me.commandLimit && commands.flat(2).length > me.lineLimit) {
+ commands.shift();
}
};
+ let addResponse = lines => commands[commands.length - 1].push(lines);
+
var executeCmd = function(cmd) {
- addLine("# " + Ext.htmlEncode(cmd));
+ recordInput("# " + 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.");
+ recordInput("Type 'help' for help.");
refresh();
},
specialkey: function(f, e) {
--
2.30.2