From nobody Mon Nov 25 04:45:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=solinno.co.uk ARC-Seal: i=1; a=rsa-sha256; t=1715674483; cv=none; d=zohomail.com; s=zohoarc; b=buLjB7E1FnlimeC6rvesiHLtUVmLH3c+JyhdWJ3puDSYKZflmKoLcrANOv2AGGIaVJSUWQJjzYx9a5zFdz1HuYy8oYLMWw2ZW9E23st9K6Ax7wIHYv4bBLFgpK+JjxGXhjvoys9tMCcvuplSvdBvkvuPBs2PReXUCHs0NNEfMDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715674483; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1oxEBtM8t6MRC3l8iYLxNrBqkFiJ6RHZ+4NdvCo3TZM=; b=jXFr1iN3epT/upv4gjv3KhNkLsVLFs/OsUO4vwmxWmAqkXTp8JZJw3vPaI9XNspbcSfHdCNbTnI+60v4p0/i0yWSfz47CevDSs+KTC8pOYvtdhw3aVhi+V8aL/KlZe9EJeI3x1tqhPC+tmK3iQdUp69MjR34SbuqRaKc37bRg38= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1715674482574821.5686942521745; Tue, 14 May 2024 01:14:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.721209.1124422 (Exim 4.92) (envelope-from ) id 1s6nIh-00031y-DJ; Tue, 14 May 2024 08:14:19 +0000 Received: by outflank-mailman (output) from mailman id 721209.1124422; Tue, 14 May 2024 08:14:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6nIh-00031r-Ai; Tue, 14 May 2024 08:14:19 +0000 Received: by outflank-mailman (input) for mailman id 721209; Tue, 14 May 2024 08:14:18 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s6nIf-00031l-Kz for xen-devel@lists.xenproject.org; Tue, 14 May 2024 08:14:18 +0000 Received: from doppler.solinno.uk (doppler.solinno.uk [81.2.106.178]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f4826853-11c9-11ef-909d-e314d9c70b13; Tue, 14 May 2024 10:14:16 +0200 (CEST) Received: from folly.solinno.co.uk (folly.vpn.solinno.co.uk [172.19.84.10]) by doppler.solinno.uk (Postfix) with ESMTPSA id 9BE738006E; Tue, 14 May 2024 09:14:15 +0100 (BST) Received: by folly.solinno.co.uk (Postfix, from userid 1000) id A839A20189; Tue, 14 May 2024 09:14:14 +0100 (BST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f4826853-11c9-11ef-909d-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=solinno.co.uk; s=mail; t=1715674455; bh=w1u90DsNaHSjyLaNrDcHOwtXTjvNeyUuUYKrG7Ev38M=; h=From:To:Cc:Subject:Date:From; b=BMkDFvsMH4xBk09gyB7SCtCwXsJ7ONM3Rn3sFhQ3Yak9AkHN6/+yR17Tt6zKaVD/A /kBOj/KuGJ6HHA+62y1H/pRoVO4/12QZ5Pk7RSrUx0JgNLYXEz6PTxTNWeiXzz9u9l n16u/APhAEFAauZvhbZv6+ghdSqWIqhdxljhA7sI= From: Leigh Brown To: xen-devel@lists.xenproject.org Cc: Andrew Cooper , Leigh Brown Subject: [PATCH] tools/xentop: fix cpu% sort order Date: Tue, 14 May 2024 09:13:44 +0100 Message-Id: <20240514081344.4499-1-leigh@solinno.co.uk> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @solinno.co.uk) X-ZM-MESSAGEID: 1715674484749100001 Content-Type: text/plain; charset="utf-8" Although using integer comparison to compare doubles kind of works, it's annoying to see domains slightly out of order when sorting by cpu%. Add a compare_dbl() function and update compare_cpu_pct() to call it. Signed-off-by: Leigh Brown --- tools/xentop/xentop.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c index 545bd5e96d..99199caec9 100644 --- a/tools/xentop/xentop.c +++ b/tools/xentop/xentop.c @@ -85,6 +85,7 @@ static void set_delay(const char *value); static void set_prompt(const char *new_prompt, void (*func)(const char *)); static int handle_key(int); static int compare(unsigned long long, unsigned long long); +static int compare_dbl(double, double); static int compare_domains(xenstat_domain **, xenstat_domain **); static unsigned long long tot_net_bytes( xenstat_domain *, int); static bool tot_vbd_reqs(xenstat_domain *, int, unsigned long long *); @@ -422,6 +423,16 @@ static int compare(unsigned long long i1, unsigned lon= g long i2) return 0; } =20 +/* Compares two double precision numbers, returning -1,0,1 for <,=3D,> */ +static int compare_dbl(double d1, double d2) +{ + if(d1 < d2) + return -1; + if(d1 > d2) + return 1; + return 0; +} + /* Comparison function for use with qsort. Compares two domains using the * current sort field. */ static int compare_domains(xenstat_domain **domain1, xenstat_domain **doma= in2) @@ -523,7 +534,7 @@ static double get_cpu_pct(xenstat_domain *domain) =20 static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain= 2) { - return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2)); + return -compare_dbl(get_cpu_pct(domain1), get_cpu_pct(domain2)); } =20 /* Prints cpu percentage statistic */ --=20 2.39.2