struct blkio_stats io_serviced;
};
-struct ct {
+struct container_stats {
struct lxc_container *c;
struct stats *stats;
};
static char sort_by = 'n';
static int sort_reverse = 0;
static struct termios oldtios;
-static struct ct *ct = NULL;
+static struct container_stats *container_stats = NULL;
static int ct_alloc_cnt = 0;
static int my_parser(struct lxc_arguments *args, int c, char *arg)
return;
}
-static void stats_get(struct lxc_container *c, struct ct *ct, struct stats *total)
+static void stats_get(struct lxc_container *c, struct container_stats *ct, struct stats *total)
{
ct->c = c;
ct->stats->mem_used = stat_get_int(c, "memory.usage_in_bytes");
static int cmp_name(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return strncmp(ct2->c->name, ct1->c->name, strlen(ct2->c->name));
static int cmp_cpuuse(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return ct2->stats->cpu_use_nanos < ct1->stats->cpu_use_nanos;
static int cmp_blkio(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return ct2->stats->io_service_bytes.total < ct1->stats->io_service_bytes.total;
static int cmp_memory(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return ct2->stats->mem_used < ct1->stats->mem_used;
static int cmp_memorysw(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return ct2->stats->memsw_used < ct1->stats->memsw_used;
static int cmp_kmemory(const void *sct1, const void *sct2)
{
- const struct ct *ct1 = sct1;
- const struct ct *ct2 = sct2;
+ const struct container_stats *ct1 = sct1;
+ const struct container_stats *ct2 = sct2;
if (sort_reverse)
return ct2->stats->kmem_used < ct1->stats->kmem_used;
case 'k': cmp_func = cmp_kmemory; break;
}
- qsort(ct, active, sizeof(*ct), (int (*)(const void *,const void *))cmp_func);
+ qsort(container_stats, active, sizeof(*container_stats), (int (*)(const void *,const void *))cmp_func);
}
static void ct_free(void)
int i;
for (i = 0; i < ct_alloc_cnt; i++) {
- if (ct[i].c) {
- lxc_container_put(ct[i].c);
- ct[i].c = NULL;
+ if (container_stats[i].c) {
+ lxc_container_put(container_stats[i].c);
+ container_stats[i].c = NULL;
}
- free(ct[i].stats);
- ct[i].stats = NULL;
+ free(container_stats[i].stats);
+ container_stats[i].stats = NULL;
}
}
ct_free();
- ct = realloc(ct, sizeof(*ct) * active_cnt);
- if (!ct) {
+ container_stats = realloc(container_stats, sizeof(*container_stats) * active_cnt);
+ if (!container_stats) {
fprintf(stderr, "Cannot alloc mem\n");
exit(EXIT_FAILURE);
}
for (i = 0; i < active_cnt; i++) {
- ct[i].stats = malloc(sizeof(*ct[0].stats));
- if (!ct[i].stats) {
+ container_stats[i].stats = malloc(sizeof(*container_stats[0].stats));
+ if (!container_stats[i].stats) {
fprintf(stderr, "Cannot alloc mem\n");
exit(EXIT_FAILURE);
}
memset(&total, 0, sizeof(total));
for (i = 0; i < active_cnt; i++)
- stats_get(active[i], &ct[i], &total);
+ stats_get(active[i], &container_stats[i], &total);
ct_sort(active_cnt);
}
for (i = 0; i < active_cnt && i < ct_print_cnt; i++) {
- stats_print(ct[i].c->name, ct[i].stats, &total);
+ stats_print(container_stats[i].c->name, container_stats[i].stats, &total);
printf("\n");
}
fflush(stdout);
for (i = 0; i < active_cnt; i++) {
- lxc_container_put(ct[i].c);
- ct[i].c = NULL;
+ lxc_container_put(container_stats[i].c);
+ container_stats[i].c = NULL;
}
in_char = '\0';