[lxc-devel] [lxc/master] tools: account for different architectures

brauner on Github lxc-bot at linuxcontainers.org
Tue Dec 6 15:43:14 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161206/69ee23fd/attachment.bin>
-------------- next part --------------
From 9dba726e16290ef7ca79ef0baf341f3ee2907e71 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 6 Dec 2016 16:42:28 +0100
Subject: [PATCH] tools: account for different architectures

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/tools/lxc_top.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
index 3e75dca..593f9f1 100644
--- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c
@@ -21,11 +21,14 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
 #include <errno.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <termios.h>
 #include <unistd.h>
 #include <sys/epoll.h>
@@ -318,11 +321,11 @@ static void stats_print(const char *name, const struct stats *stats,
 	char kmem_used_str[20];
 	struct timeval time_val;
 	unsigned long long time_ms;
-	
+
 	if (!batch) {
 		size_humanize(stats->blkio, blkio_str, sizeof(blkio_str));
 		size_humanize(stats->mem_used, mem_used_str, sizeof(mem_used_str));
-		
+
 		printf("%-18.18s %12.2f %12.2f %12.2f %14s %10s",
 		       name,
 		       (float)stats->cpu_use_nanos / 1000000000,
@@ -335,20 +338,17 @@ static void stats_print(const char *name, const struct stats *stats,
 			printf(" %10s", kmem_used_str);
 		}
 	} else {
-		gettimeofday(&time_val, NULL);  
+		gettimeofday(&time_val, NULL);
 		time_ms = (unsigned long long) (time_val.tv_sec) * 1000 + (unsigned long long) (time_val.tv_usec) / 1000;
-		printf("%llu,%s,%lu,%lu,%lu,%lu,%lu,%lu,%lu",
-		       time_ms,
-		       name,
-		       stats->cpu_use_nanos,
-		       stats->cpu_use_sys,
-		       stats->cpu_use_user,
-		       stats->blkio,
-		       stats->blkio_iops,
-		       stats->mem_used,
-		       stats->kmem_used);
+		printf("%" PRIu64 ",%s,%" PRIu64 ",%" PRIu64 ",%" PRIu64
+		       ",%" PRIu64 ",%" PRIu64 ",%" PRIu64 ",%" PRIu64,
+		       (uint64_t)time_ms, name, (uint64_t)stats->cpu_use_nanos,
+		       (uint64_t)stats->cpu_use_sys,
+		       (uint64_t)stats->cpu_use_user, (uint64_t)stats->blkio,
+		       (uint64_t)stats->blkio_iops, (uint64_t)stats->mem_used,
+		       (uint64_t)stats->kmem_used);
 	}
-  
+
 }
 
 static int cmp_name(const void *sct1, const void *sct2)
@@ -457,7 +457,7 @@ int main(int argc, char *argv[])
 	struct lxc_epoll_descr descr;
 	int ret, ct_print_cnt;
 	char in_char;
-	
+
 	ret = EXIT_FAILURE;
 	if (lxc_arguments_parse(&my_args, argc, argv))
 		goto out;
@@ -491,7 +491,7 @@ int main(int argc, char *argv[])
         if (batch) {
 		printf("time_ms,container,cpu_nanos,cpu_sys_userhz,cpu_user_userhz,blkio_bytes,blkio_iops,mem_used_bytes,kernel_mem_used_bytes\n");
 	}
-	
+
 	for(;;) {
 		struct lxc_container **active;
 		int i, active_cnt;
@@ -520,12 +520,12 @@ int main(int argc, char *argv[])
 			stats_print(total_name, &total, &total);
 		}
 		fflush(stdout);
-		
+
 		for (i = 0; i < active_cnt; i++) {
 			lxc_container_put(ct[i].c);
 			ct[i].c = NULL;
 		}
-		
+
 		in_char = '\0';
 		if (!batch) {
 			ret = lxc_mainloop(&descr, 1000 * delay);
@@ -551,7 +551,7 @@ int main(int argc, char *argv[])
 		}
 	}
 	ret = EXIT_SUCCESS;
-	
+
 err1:
 	lxc_mainloop_close(&descr);
 out:


More information about the lxc-devel mailing list