Blob Blame History Raw
From bbd5a5c1f5db3bde04628e75396155260333e53e Mon Sep 17 00:00:00 2001
From: Kazuhito Hagio <k-hagio-ab@nec.com>
Date: Wed, 19 Jan 2022 16:24:49 +0900
Subject: [PATCH 08/11] Remove ptype command from "ps -t" option to reduce
 memory and time

With some vmlinux e.g. RHEL9 ones, the first execution of the gdb ptype
command heavily consumes memory and time.  The "ps -t" option uses it in
start_time_timespec(), and it can be replaced with the crash macros.

This can reduce about 1.4 GB memory and 6 seconds time comsumption in
the following test:

  $ echo "ps -t" | time crash vmlinux vmcore

  Without the patch:
  11.60user 0.43system 0:11.94elapsed 100%CPU (0avgtext+0avgdata 1837964maxresident)k
  0inputs+400outputs (0major+413636minor)pagefaults 0swaps

  With the patch:
  5.40user 0.16system 0:05.46elapsed 101%CPU (0avgtext+0avgdata 417896maxresident)k
  0inputs+384outputs (0major+41528minor)pagefaults 0swaps

Although the ptype command and similar ones cannot be fully removed,
but removing some of them will make the use of crash safer, especially
for an automatic crash reporter.

Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
---
 task.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/task.c b/task.c
index 263a8344dd94..a79ed0d96fb5 100644
--- a/task.c
+++ b/task.c
@@ -4662,8 +4662,6 @@ show_task_times(struct task_context *tcp, ulong flags)
 static int
 start_time_timespec(void)
 {
-        char buf[BUFSIZE];
-
 	switch(tt->flags & (TIMESPEC | NO_TIMESPEC | START_TIME_NSECS))
 	{
 	case TIMESPEC:
@@ -4677,24 +4675,11 @@ start_time_timespec(void)
 
 	tt->flags |= NO_TIMESPEC;
 
-        open_tmpfile();
-        sprintf(buf, "ptype struct task_struct");
-        if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) {
-                close_tmpfile();
-                return FALSE;
-        }
-
-        rewind(pc->tmpfile);
-        while (fgets(buf, BUFSIZE, pc->tmpfile)) {
-                if (strstr(buf, "start_time;")) {
-			if (strstr(buf, "struct timespec")) {
-				tt->flags &= ~NO_TIMESPEC;
-				tt->flags |= TIMESPEC;
-			}
-		}
-        }
-
-        close_tmpfile();
+	if (VALID_MEMBER(task_struct_start_time) &&
+	    STREQ(MEMBER_TYPE_NAME("task_struct", "start_time"), "timespec")) {
+			tt->flags &= ~NO_TIMESPEC;
+			tt->flags |= TIMESPEC;
+	}
 
 	if ((tt->flags & NO_TIMESPEC) && (SIZE(task_struct_start_time) == 8)) {
 		tt->flags &= ~NO_TIMESPEC;
-- 
2.20.1