mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
tools/xentop: Fix cpu% sort order
In compare_cpu_pct(), there is a double -> unsigned long long converion when
calling compare(). In C, this discards the fractional part, resulting in an
out-of order sorting such as:
NAME STATE CPU(sec) CPU(%)
xendd --b--- 4020 5.7
icecream --b--- 2600 3.8
Domain-0 -----r 1060 1.5
neon --b--- 827 1.1
cheese --b--- 225 0.7
pizza --b--- 359 0.5
cassini --b--- 490 0.4
fusilli --b--- 159 0.2
bob --b--- 502 0.2
blender --b--- 121 0.2
bread --b--- 69 0.1
chickpea --b--- 67 0.1
lentil --b--- 67 0.1
Introduce compare_dbl() function and update compare_cpu_pct() to call it.
Fixes: 49839b535b ("Add xenstat framework.")
Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
master commit: e27fc7d15e
master date: 2024-05-15 19:59:52 +0100
This commit is contained in:
1 parent
e31e8ed53e
commit
cd3f405b68
1 file changed
+12
-1
+12
-1
@@ -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 long long i2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compares two double precision numbers, returning -1,0,1 for <,=,> */
|
||||
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 **domain2)
|
||||
@@ -523,7 +534,7 @@ static double get_cpu_pct(xenstat_domain *domain)
|
||||
|
||||
static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2)
|
||||
{
|
||||
return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2));
|
||||
return -compare_dbl(get_cpu_pct(domain1), get_cpu_pct(domain2));
|
||||
}
|
||||
|
||||
/* Prints cpu percentage statistic */
|
||||
|
||||