[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC 4/6] xentop: show CPU load information
From: Andrii Anisov <andrii_anisov@xxxxxxxx> Let xentop request and show information about CPU load (hypervisor, guest and idle information) Signed-off-by: Andrii Anisov <andrii_anisov@xxxxxxxx> --- tools/xenstat/libxenstat/src/xenstat.c | 38 +++++++++++++++++++++++++++++ tools/xenstat/libxenstat/src/xenstat.h | 9 +++++++ tools/xenstat/libxenstat/src/xenstat_priv.h | 3 +++ tools/xenstat/xentop/xentop.c | 30 +++++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/tools/xenstat/libxenstat/src/xenstat.c b/tools/xenstat/libxenstat/src/xenstat.c index bba143e..e4029d2 100644 --- a/tools/xenstat/libxenstat/src/xenstat.c +++ b/tools/xenstat/libxenstat/src/xenstat.c @@ -148,6 +148,9 @@ static inline unsigned long long parse(char *s, char *match) xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) { #define DOMAIN_CHUNK_SIZE 256 + xc_cpuinfo_t *cpuinfo; + int max_cpus, nr_cpus; + xenstat_node *node; xc_physinfo_t physinfo = { 0 }; xc_domaininfo_t domaininfo[DOMAIN_CHUNK_SIZE]; @@ -177,6 +180,26 @@ xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags) * handle->page_size; node->freeable_mb = 0; + + max_cpus = node->num_cpus; + + cpuinfo = calloc(max_cpus, sizeof(xc_cpuinfo_t)); + if (!cpuinfo) + return NULL; + + if (xc_getcpuinfo(handle->xc_handle, max_cpus, cpuinfo, &nr_cpus) < 0) { + free(cpuinfo); + return NULL; + } + + for ( i = 0; i < nr_cpus; i++) { + node->idle_time += cpuinfo[i].idletime; + node->hyp_time += cpuinfo[i].hyptime; + node->guest_time += cpuinfo[i].guesttime; + } + + free(cpuinfo); + /* malloc(0) is not portable, so allocate a single domain. This will * be resized below. */ node->domains = malloc(sizeof(xenstat_domain)); @@ -346,6 +369,21 @@ unsigned long long xenstat_node_cpu_hz(xenstat_node * node) return node->cpu_hz; } +unsigned long long xenstat_node_idle_time(xenstat_node * node) +{ + return node->idle_time; +} + +unsigned long long xenstat_node_guest_time(xenstat_node * node) +{ + return node->guest_time; +} + +unsigned long long xenstat_node_hyp_time(xenstat_node * node) +{ + return node->hyp_time; +} + /* Get the domain ID for this domain */ unsigned xenstat_domain_id(xenstat_domain * domain) { diff --git a/tools/xenstat/libxenstat/src/xenstat.h b/tools/xenstat/libxenstat/src/xenstat.h index 76a660f..5b34461 100644 --- a/tools/xenstat/libxenstat/src/xenstat.h +++ b/tools/xenstat/libxenstat/src/xenstat.h @@ -80,6 +80,15 @@ unsigned int xenstat_node_num_cpus(xenstat_node * node); /* Get information about the CPU speed */ unsigned long long xenstat_node_cpu_hz(xenstat_node * node); +/* Get information about the CPU idle time */ +unsigned long long xenstat_node_idle_time(xenstat_node * node); + +/* Get information about the CPU guest execution time */ +unsigned long long xenstat_node_guest_time(xenstat_node * node); + +/* Get information about the CPU hypervisor execution time */ +unsigned long long xenstat_node_hyp_time(xenstat_node * node); + /* * Domain functions - extract information from a xenstat_domain */ diff --git a/tools/xenstat/libxenstat/src/xenstat_priv.h b/tools/xenstat/libxenstat/src/xenstat_priv.h index 4eb44a8..78ad8c4 100644 --- a/tools/xenstat/libxenstat/src/xenstat_priv.h +++ b/tools/xenstat/libxenstat/src/xenstat_priv.h @@ -45,6 +45,9 @@ struct xenstat_node { unsigned int flags; unsigned long long cpu_hz; unsigned int num_cpus; + unsigned long long hyp_time; + unsigned long long guest_time; + unsigned long long idle_time; unsigned long long tot_mem; unsigned long long free_mem; unsigned int num_domains; diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c index af11ebf..aa6e9b0 100644 --- a/tools/xenstat/xentop/xentop.c +++ b/tools/xenstat/xentop/xentop.c @@ -930,6 +930,34 @@ void adjust_field_widths(xenstat_domain *domain) fields[FIELD_VBD_WSECT-1].default_width = length; } +void do_utilization(void) +{ + double us_elapsed = 0.0, + us_hyp = 0.0, + us_guest = 0.0, + us_idle = 0.0; + + /* Can't calculate CPU percentage without a current and a previous sample.*/ + if(prev_node != NULL && cur_node != NULL) { + + /* Calculate the time elapsed in microseconds */ + us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0 + +(curtime.tv_usec - oldtime.tv_usec)); + + /* In the following, nanoseconds must be multiplied by 1000.0 to + * convert to microseconds, then divided by 100.0 to get a percentage, + * resulting in a multiplication by 10.0 */ + us_idle = ((xenstat_node_idle_time(cur_node) - + xenstat_node_idle_time(prev_node))/10.0)/us_elapsed; + us_guest = ((xenstat_node_guest_time(cur_node) - + xenstat_node_guest_time(prev_node))/10.0)/us_elapsed; + us_hyp = ((xenstat_node_hyp_time(cur_node) - + xenstat_node_hyp_time(prev_node))/10.0)/us_elapsed; + } + + print("%%CPU(s): %6.1f gu, %6.1f hy, %6.1f id \n", + us_guest, us_hyp, us_idle); +} /* Section printing functions */ /* Prints the top summary, above the domain table */ @@ -972,6 +1000,8 @@ void do_summary(void) used = xenstat_node_tot_mem(cur_node); freeable_mb = 0; + do_utilization(); + /* Dump node memory and cpu information */ if ( freeable_mb <= 0 ) print("Mem: %lluk total, %lluk used, %lluk free ", -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |