2022-09-26 03:21:49

by Chen Zhongjin

[permalink] [raw]
Subject: [PATCH -next 3/5] perf: Remove duplicate errbuf

char errbuf[BUFSIZ] is defined twice in trace__run.

However out_error_open is not cross to other out_error path, they can
share one errbuf together.

Define the errbuf[BUFSIZ] at the beginning of function, and remove the
redefinations of them for code cleaning.

Signed-off-by: Chen Zhongjin <[email protected]>
---
tools/perf/builtin-trace.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 7ecd76428440..5660c0ee3507 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3937,6 +3937,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
unsigned long before;
const bool forks = argc > 0;
bool draining = false;
+ char errbuf[BUFSIZ];

trace->live = true;

@@ -4027,8 +4028,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)

err = bpf__apply_obj_config();
if (err) {
- char errbuf[BUFSIZ];
-
bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf));
pr_err("ERROR: Apply config to BPF failed: %s\n",
errbuf);
@@ -4185,8 +4184,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
trace->evlist = NULL;
trace->live = false;
return err;
-{
- char errbuf[BUFSIZ];

out_error_sched_stat_runtime:
tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime");
@@ -4213,7 +4210,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
evsel->filter, evsel__name(evsel), errno,
str_error_r(errno, errbuf, sizeof(errbuf)));
goto out_delete_evlist;
-}
+
out_error_mem:
fprintf(trace->output, "Not enough memory to run!\n");
goto out_delete_evlist;
--
2.17.1


2022-09-26 20:10:02

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH -next 3/5] perf: Remove duplicate errbuf

Em Mon, Sep 26, 2022 at 11:14:38AM +0800, Chen Zhongjin escreveu:
> char errbuf[BUFSIZ] is defined twice in trace__run.
>
> However out_error_open is not cross to other out_error path, they can
> share one errbuf together.
>
> Define the errbuf[BUFSIZ] at the beginning of function, and remove the
> redefinations of them for code cleaning.

Have you looked at the end result in the generated code? Just out of
curiosity.

- Arnaldo

> Signed-off-by: Chen Zhongjin <[email protected]>
> ---
> tools/perf/builtin-trace.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 7ecd76428440..5660c0ee3507 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -3937,6 +3937,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> unsigned long before;
> const bool forks = argc > 0;
> bool draining = false;
> + char errbuf[BUFSIZ];
>
> trace->live = true;
>
> @@ -4027,8 +4028,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
>
> err = bpf__apply_obj_config();
> if (err) {
> - char errbuf[BUFSIZ];
> -
> bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf));
> pr_err("ERROR: Apply config to BPF failed: %s\n",
> errbuf);
> @@ -4185,8 +4184,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> trace->evlist = NULL;
> trace->live = false;
> return err;
> -{
> - char errbuf[BUFSIZ];
>
> out_error_sched_stat_runtime:
> tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime");
> @@ -4213,7 +4210,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> evsel->filter, evsel__name(evsel), errno,
> str_error_r(errno, errbuf, sizeof(errbuf)));
> goto out_delete_evlist;
> -}
> +
> out_error_mem:
> fprintf(trace->output, "Not enough memory to run!\n");
> goto out_delete_evlist;
> --
> 2.17.1

--

- Arnaldo

2022-09-27 01:50:09

by Chen Zhongjin

[permalink] [raw]
Subject: Re: [PATCH -next 3/5] perf: Remove duplicate errbuf

Hi,

On 2022/9/27 3:54, Arnaldo Carvalho de Melo wrote:
> Em Mon, Sep 26, 2022 at 11:14:38AM +0800, Chen Zhongjin escreveu:
>> char errbuf[BUFSIZ] is defined twice in trace__run.
>>
>> However out_error_open is not cross to other out_error path, they can
>> share one errbuf together.
>>
>> Define the errbuf[BUFSIZ] at the beginning of function, and remove the
>> redefinations of them for code cleaning.
> Have you looked at the end result in the generated code? Just out of
> curiosity.

Good question. Because it is an auto reported warning of clang I didn't
try it.

Just tried and found no different for 'objdump -d perf' on two version.


Best,

Chen

>
> - Arnaldo
>
>> Signed-off-by: Chen Zhongjin <[email protected]>
>> ---
>> tools/perf/builtin-trace.c | 7 ++-----
>> 1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
>> index 7ecd76428440..5660c0ee3507 100644
>> --- a/tools/perf/builtin-trace.c
>> +++ b/tools/perf/builtin-trace.c
>> @@ -3937,6 +3937,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
>> unsigned long before;
>> const bool forks = argc > 0;
>> bool draining = false;
>> + char errbuf[BUFSIZ];
>>
>> trace->live = true;
>>
>> @@ -4027,8 +4028,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
>>
>> err = bpf__apply_obj_config();
>> if (err) {
>> - char errbuf[BUFSIZ];
>> -
>> bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf));
>> pr_err("ERROR: Apply config to BPF failed: %s\n",
>> errbuf);
>> @@ -4185,8 +4184,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
>> trace->evlist = NULL;
>> trace->live = false;
>> return err;
>> -{
>> - char errbuf[BUFSIZ];
>>
>> out_error_sched_stat_runtime:
>> tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime");
>> @@ -4213,7 +4210,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
>> evsel->filter, evsel__name(evsel), errno,
>> str_error_r(errno, errbuf, sizeof(errbuf)));
>> goto out_delete_evlist;
>> -}
>> +
>> out_error_mem:
>> fprintf(trace->output, "Not enough memory to run!\n");
>> goto out_delete_evlist;
>> --
>> 2.17.1