//#include #include #include #include #include int main(int argc, char **argv) { int exitcode = 0; long double CPU_LIMIT = 100 * 365 * 86400.0; /* 100 years */ xenstat_handle *xhandle = NULL; xenstat_node *cur_node = NULL; xenstat_domain **domains; xhandle = xenstat_init(); if (xhandle == NULL) { fprintf(stderr, "%s: Failed to initialize xenstat library\n", argv[0]); exitcode = EXIT_FAILURE; goto cleanup; } while (1) { unsigned int i, num_domains = 0; cur_node = xenstat_get_node(xhandle, XENSTAT_ALL); if (cur_node == NULL) { fprintf(stderr, "%s: Failed to retrieve statistics from libxenstat\n", argv[0]); exit(EXIT_FAILURE); } num_domains = xenstat_node_num_domains(cur_node); domains = calloc(num_domains, sizeof(xenstat_domain *)); if (domains == NULL) { fprintf(stderr, "%s: Failed to allocate memory\n", argv[0]); exitcode = EXIT_FAILURE; goto cleanup; } /* Grab info for each domain. */ for (i = 0; i < num_domains; i++) domains[i] = xenstat_node_domain_by_index(cur_node, i); /* Now go through and print the name and CPU time in seconds. */ for (i = 0; i < num_domains; i++) { unsigned long long cpu_ns = xenstat_domain_cpu_ns(domains[i]); long double cpu_s = cpu_ns / 1000000000.0L; if (cpu_s > CPU_LIMIT) { fprintf(stderr, "Got a weird CPU time %Lf >100 years (cpu_ns=%llu)\n", cpu_s, cpu_ns); exitcode = EXIT_FAILURE; goto cleanup; } } free(domains); free(cur_node); } cleanup: if (domains != NULL) free(domains); if (cur_node != NULL) xenstat_free_node(cur_node); if (xhandle != NULL) xenstat_uninit(xhandle); exit(exitcode); }