]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf trace: Allocate syscall stats only if summary is on
authorNamhyung Kim <namhyung@kernel.org>
Wed, 5 Feb 2025 20:54:40 +0000 (12:54 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 13 Feb 2025 03:44:10 +0000 (19:44 -0800)
The syscall stats are used only when summary is requested.  Let's avoid
unnecessary operations.  While at it, let's pass 'trace' pointer
directly instead of passing 'output' file pointer and 'summary' option
in the 'trace' separately.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250205205443.1986408-2-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-trace.c

index 06356217adebdb79679e9f7f5482c117330f3a8d..682d39f54978055cd54614e8b078bad6f33cb58b 100644 (file)
@@ -1522,13 +1522,14 @@ struct thread_trace {
        struct intlist *syscall_stats;
 };
 
-static struct thread_trace *thread_trace__new(void)
+static struct thread_trace *thread_trace__new(struct trace *trace)
 {
        struct thread_trace *ttrace =  zalloc(sizeof(struct thread_trace));
 
        if (ttrace) {
                ttrace->files.max = -1;
-               ttrace->syscall_stats = intlist__new(NULL);
+               if (trace->summary)
+                       ttrace->syscall_stats = intlist__new(NULL);
        }
 
        return ttrace;
@@ -1550,7 +1551,7 @@ static void thread_trace__delete(void *pttrace)
        free(ttrace);
 }
 
-static struct thread_trace *thread__trace(struct thread *thread, FILE *fp)
+static struct thread_trace *thread__trace(struct thread *thread, struct trace *trace)
 {
        struct thread_trace *ttrace;
 
@@ -1558,7 +1559,7 @@ static struct thread_trace *thread__trace(struct thread *thread, FILE *fp)
                goto fail;
 
        if (thread__priv(thread) == NULL)
-               thread__set_priv(thread, thread_trace__new());
+               thread__set_priv(thread, thread_trace__new(trace));
 
        if (thread__priv(thread) == NULL)
                goto fail;
@@ -1568,7 +1569,7 @@ static struct thread_trace *thread__trace(struct thread *thread, FILE *fp)
 
        return ttrace;
 fail:
-       color_fprintf(fp, PERF_COLOR_RED,
+       color_fprintf(trace->output, PERF_COLOR_RED,
                      "WARNING: not enough memory, dropping samples!\n");
        return NULL;
 }
@@ -2626,7 +2627,7 @@ static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
                return -1;
 
        thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
-       ttrace = thread__trace(thread, trace->output);
+       ttrace = thread__trace(thread, trace);
        if (ttrace == NULL)
                goto out_put;
 
@@ -2703,7 +2704,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel,
                return -1;
 
        thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
-       ttrace = thread__trace(thread, trace->output);
+       ttrace = thread__trace(thread, trace);
        /*
         * We need to get ttrace just to make sure it is there when syscall__scnprintf_args()
         * and the rest of the beautifiers accessing it via struct syscall_arg touches it.
@@ -2775,7 +2776,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
                return -1;
 
        thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
-       ttrace = thread__trace(thread, trace->output);
+       ttrace = thread__trace(thread, trace);
        if (ttrace == NULL)
                goto out_put;
 
@@ -2964,7 +2965,7 @@ static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel,
        struct thread *thread = machine__findnew_thread(trace->host,
                                                        sample->pid,
                                                        sample->tid);
-       struct thread_trace *ttrace = thread__trace(thread, trace->output);
+       struct thread_trace *ttrace = thread__trace(thread, trace);
 
        if (ttrace == NULL)
                goto out_dump;
@@ -3218,7 +3219,7 @@ static int trace__pgfault(struct trace *trace,
                }
        }
 
-       ttrace = thread__trace(thread, trace->output);
+       ttrace = thread__trace(thread, trace);
        if (ttrace == NULL)
                goto out_put;