[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] tools/xentop: add option to display dom0 first



commit 03e08d44c8aebc78f1b6ae8235f65d4cbdd75242
Author:     Cyril Rébert <slack@xxxxxxxxx>
AuthorDate: Wed Feb 14 10:41:43 2024 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Feb 14 10:41:43 2024 +0100

    tools/xentop: add option to display dom0 first
    
    Add a command line option to xentop to be able to display dom0 first, on 
top of the list.
    This is unconditional, so sorting domains with the S option will also 
ignore dom0.
    
    Signed-off-by: Cyril Rébert (zithro) <slack@xxxxxxxxx>
    Reviewed-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 docs/man/xentop.1.pod |  6 +++++-
 tools/xentop/xentop.c | 30 +++++++++++++++++++++++++++---
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/docs/man/xentop.1.pod b/docs/man/xentop.1.pod
index 126f43d2f3..593a484ce7 100644
--- a/docs/man/xentop.1.pod
+++ b/docs/man/xentop.1.pod
@@ -5,7 +5,7 @@ xentop - displays real-time information about a Xen system and 
domains
 =head1 SYNOPSIS
 
 B<xentop> [B<-h>] [B<-V>] [B<-d>SECONDS] [B<-n>] [B<-r>] [B<-v>] [B<-f>]
-[B<-b>] [B<-i>ITERATIONS]
+[B<-b>] [B<-i>ITERATIONS] [B<-z>]
 
 =head1 DESCRIPTION
 
@@ -57,6 +57,10 @@ output data in batch mode (to stdout)
 
 maximum number of iterations xentop should produce before ending
 
+=item B<-z>, B<--dom0-first>
+
+display dom0 first, ignoring interactive sorting
+
 =back
 
 =head1 INTERACTIVE COMMANDS
diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c
index 545bd5e96d..0a2fab7f15 100644
--- a/tools/xentop/xentop.c
+++ b/tools/xentop/xentop.c
@@ -211,6 +211,7 @@ int show_networks = 0;
 int show_vbds = 0;
 int repeat_header = 0;
 int show_full_name = 0;
+int dom0_first = 0;
 #define PROMPT_VAL_LEN 80
 const char *prompt = NULL;
 char prompt_val[PROMPT_VAL_LEN];
@@ -240,6 +241,7 @@ static void usage(const char *program)
               "-b, --batch          output in batch mode, no user input 
accepted\n"
               "-i, --iterations     number of iterations before exiting\n"
               "-f, --full-name      output the full domain name (not 
truncated)\n"
+              "-z, --dom0-first     display dom0 first (ignore sorting)\n"
               "\n" XENTOP_BUGSTO,
               program);
        return;
@@ -1163,6 +1165,8 @@ static void top(void)
 {
        xenstat_domain **domains;
        unsigned int i, num_domains = 0;
+       int dom0_index = -1;
+       int sort_start = 0, sort_count = 0;
 
        /* Now get the node information */
        if (prev_node != NULL)
@@ -1183,11 +1187,27 @@ static void top(void)
        if(domains == NULL)
                fail("Failed to allocate memory\n");
 
-       for (i=0; i < num_domains; i++)
+       for (i=0; i < num_domains; i++) {
                domains[i] = xenstat_node_domain_by_index(cur_node, i);
+               if ( strcmp(xenstat_domain_name(domains[i]), "Domain-0") == 0 )
+                       dom0_index = i;
+       }
+
+       /* Handle dom0 position, not for dom0-less */
+       if ( dom0_first == 1 && dom0_index != -1 ){
+               /* if dom0 is not first in domains, swap it there */
+               if ( dom0_index != 0 ){
+                       xenstat_domain *tmp;
+                       tmp = domains[0];
+                       domains[0] = domains[dom0_index];
+                       domains[dom0_index] = tmp;
+               }
+               sort_start = 1;
+               sort_count = 1;
+       }
 
        /* Sort */
-       qsort(domains, num_domains, sizeof(xenstat_domain *),
+       qsort((domains+sort_start), (num_domains-sort_count), 
sizeof(xenstat_domain *),
              (int(*)(const void *, const void *))compare_domains);
 
        if(first_domain_index >= num_domains)
@@ -1242,9 +1262,10 @@ int main(int argc, char **argv)
                { "batch",         no_argument,       NULL, 'b' },
                { "iterations",    required_argument, NULL, 'i' },
                { "full-name",     no_argument,       NULL, 'f' },
+               { "dom0-first",    no_argument,       NULL, 'z' },
                { 0, 0, 0, 0 },
        };
-       const char *sopts = "hVnxrvd:bi:f";
+       const char *sopts = "hVnxrvd:bi:fz";
 
        if (atexit(cleanup) != 0)
                fail("Failed to install cleanup handler.\n");
@@ -1286,6 +1307,9 @@ int main(int argc, char **argv)
                case 'f':
                        show_full_name = 1;
                        break;
+               case 'z':
+                       dom0_first = 1;
+                       break;
                }
        }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.