output deuglification, etc

Sebastian Kuzminsky seb at highlab.com
Tue May 15 10:05:54 PDT 2007


This patch improves the display output when there are 100 or more
wakeups/second from the same source.

Also improves string handling in a couple of places.


Index: powertop.c
===================================================================
--- powertop.c	(revision 35)
+++ powertop.c	(working copy)
@@ -115,9 +115,8 @@
 	interrupts[firstfree].active = 1;
 	interrupts[firstfree].count = count;
 	interrupts[firstfree].number = irq;
-	strcpy(interrupts[firstfree].description, name);
-	if (strlen(name) > 40)
-		interrupts[firstfree].description[40] = 0;
+	strncpy(interrupts[firstfree].description, name, sizeof(interrupts[firstfree].description));
+	interrupts[firstfree].description[sizeof(interrupts[firstfree].description)-1] = (char)NULL;
 	return count;
 }
 
@@ -134,8 +133,8 @@
 		char *c;
 		int nr = -1;
 		uint64_t count = 0;
-		memset(line, 0, sizeof(line));
 		fgets(line, 1024, file);
+                line[sizeof(line)-1] = (char)NULL;
 		c = strchr(line, ':');
 		if (!c)
 			continue;
@@ -490,7 +489,7 @@
 			printf("\nTop causes for wakeups:\n");
 			for (i = 0; i < linehead; i++)
 				if (lines[i].count > 0 && counter++ < 10)
-					printf(" %5.1f%% (%4.1f)   %s \n", lines[i].count * 100.0 / linectotal,
+					printf(" %5.1f%% (%5.1f)  %s \n", lines[i].count * 100.0 / linectotal,
 							lines[i].count * 1.0 / ticktime, 
 							lines[i].string);
 			fflush(stdout);


-- 
Sebastian Kuzminsky



More information about the Power mailing list