[git commit] time: fix max resident set size unit

Denys Vlasenko vda.linux at googlemail.com
Sun Dec 31 15:28:53 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=01e80ff9ebaf42f2fb9b4ddddc75d37bc9a403aa
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

The ru_maxrss is already in Kbytes and not pages.

function                                             old     new   delta
ptok                                                  21       -     -21
time_main                                           1261    1217     -44
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-65)             Total: -65 bytes

fixes: https://bugs.busybox.net/show_bug.cgi?id=15751

Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/time.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/miscutils/time.c b/miscutils/time.c
index 5a8fa4c0b..4b1b043c3 100644
--- a/miscutils/time.c
+++ b/miscutils/time.c
@@ -111,6 +111,7 @@ static void printargv(char *const *argv)
 	} while (*++argv);
 }
 
+#ifdef UNUSED
 /* Return the number of kilobytes corresponding to a number of pages PAGES.
    (Actually, we use it to convert pages*ticks into kilobytes*ticks.)
 
@@ -136,6 +137,7 @@ static unsigned long ptok(const unsigned pagesize, const unsigned long pages)
 	return tmp / 1024;      /* then smaller.  */
 }
 #undef pagesize
+#endif /* UNUSED */
 
 /* summarize: Report on the system use of a command.
 
@@ -250,9 +252,13 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
 				printargv(command);
 				break;
 			case 'D':	/* Average unshared data size.  */
+				/* (linux kernel sets ru_idrss/isrss/ixrss to 0,
+				 * docs say the value is in kbytes, so ptok() is wrong) */
 				printf("%lu",
-					(ptok(pagesize, (UL) resp->ru.ru_idrss) +
-					 ptok(pagesize, (UL) resp->ru.ru_isrss)) / cpu_ticks);
+					(/*ptok(pagesize,*/ (UL) resp->ru.ru_idrss +
+						(UL) resp->ru.ru_isrss
+					) / cpu_ticks
+				);
 				break;
 			case 'E': {	/* Elapsed real (wall clock) time.  */
 				unsigned seconds = resp->elapsed_ms / 1000;
@@ -275,13 +281,17 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
 				printf("%lu", resp->ru.ru_inblock);
 				break;
 			case 'K':	/* Average mem usage == data+stack+text.  */
+				/* (linux kernel sets ru_idrss/isrss/ixrss to 0,
+				 * docs say the value is in kbytes, so ptok() is wrong) */
 				printf("%lu",
-					(ptok(pagesize, (UL) resp->ru.ru_idrss) +
-					 ptok(pagesize, (UL) resp->ru.ru_isrss) +
-					 ptok(pagesize, (UL) resp->ru.ru_ixrss)) / cpu_ticks);
+					(/*ptok(pagesize,*/ (UL) resp->ru.ru_idrss +
+						(UL) resp->ru.ru_isrss +
+						(UL) resp->ru.ru_ixrss
+					) / cpu_ticks
+				);
 				break;
 			case 'M':	/* Maximum resident set size.  */
-				printf("%lu", ptok(pagesize, (UL) resp->ru.ru_maxrss));
+				printf("%lu", (UL) resp->ru.ru_maxrss);
 				break;
 			case 'O':	/* Outputs.  */
 				printf("%lu", resp->ru.ru_oublock);
@@ -334,7 +344,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
 				printf("%lu", resp->ru.ru_nswap);
 				break;
 			case 'X':	/* Average shared text size.  */
-				printf("%lu", ptok(pagesize, (UL) resp->ru.ru_ixrss) / cpu_ticks);
+				printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_ixrss / cpu_ticks);
 				break;
 			case 'Z':	/* Page size.  */
 				printf("%u", pagesize);
@@ -351,7 +361,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
 				printf("%lu", resp->ru.ru_nsignals);
 				break;
 			case 'p':	/* Average stack segment.  */
-				printf("%lu", ptok(pagesize, (UL) resp->ru.ru_isrss) / cpu_ticks);
+				printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_isrss / cpu_ticks);
 				break;
 			case 'r':	/* Incoming socket messages received.  */
 				printf("%lu", resp->ru.ru_msgrcv);
@@ -360,7 +370,7 @@ static void summarize(const char *fmt, char **command, resource_t *resp)
 				printf("%lu", resp->ru.ru_msgsnd);
 				break;
 			case 't':	/* Average resident set size.  */
-				printf("%lu", ptok(pagesize, (UL) resp->ru.ru_idrss) / cpu_ticks);
+				printf("%lu", /*ptok(pagesize,*/ (UL) resp->ru.ru_idrss / cpu_ticks);
 				break;
 			case 'w':	/* Voluntary context switches.  */
 				printf("%lu", resp->ru.ru_nvcsw);


More information about the busybox-cvs mailing list