[1/2] perf trace: Use pr_debug() instead of fprintf() for logging

Message ID 20190617091140.24372-1-leo.yan@linaro.org
State New
Headers show
Series
  • [1/2] perf trace: Use pr_debug() instead of fprintf() for logging
Related show

Commit Message

Leo Yan June 17, 2019, 9:11 a.m.
In the function trace__syscall_info(), it explicitly checks verbose
level and print out log with fprintf().  Actually, we can use
pr_debug() to do the same thing for debug logging.

This patch uses pr_debug() instead of fprintf() for debug logging; it
includes a minor fixing for 'space before tab in indent', which
dismisses git warning when apply it.

Signed-off-by: Leo Yan <leo.yan@linaro.org>

---
 tools/perf/builtin-trace.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

-- 
2.17.1

Comments

Arnaldo Carvalho de Melo June 17, 2019, 3:24 p.m. | #1
Em Mon, Jun 17, 2019 at 05:11:39PM +0800, Leo Yan escreveu:
> In the function trace__syscall_info(), it explicitly checks verbose

> level and print out log with fprintf().  Actually, we can use

> pr_debug() to do the same thing for debug logging.

> 

> This patch uses pr_debug() instead of fprintf() for debug logging; it

> includes a minor fixing for 'space before tab in indent', which

> dismisses git warning when apply it.


But those are not fprintf(stdout,), they explicitely redirect to the
output file that the user may have specified using 'perf trace --output
filename.trace' :-)

- Arnaldo
 
> Signed-off-by: Leo Yan <leo.yan@linaro.org>

> ---

>  tools/perf/builtin-trace.c | 21 +++++++++------------

>  1 file changed, 9 insertions(+), 12 deletions(-)

> 

> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c

> index bd1f00e7a2eb..5cd74651db4c 100644

> --- a/tools/perf/builtin-trace.c

> +++ b/tools/perf/builtin-trace.c

> @@ -1760,12 +1760,11 @@ static struct syscall *trace__syscall_info(struct trace *trace,

>  		 * grep "NR -1 " /t/trace_pipe

>  		 *

>  		 * After generating some load on the machine.

> - 		 */

> -		if (verbose > 1) {

> -			static u64 n;

> -			fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",

> -				id, perf_evsel__name(evsel), ++n);

> -		}

> +		 */

> +		static u64 n;

> +

> +		pr_debug("Invalid syscall %d id, skipping (%s, %" PRIu64 ")\n",

> +			 id, perf_evsel__name(evsel), ++n);

>  		return NULL;

>  	}

>  

> @@ -1779,12 +1778,10 @@ static struct syscall *trace__syscall_info(struct trace *trace,

>  	return &trace->syscalls.table[id];

>  

>  out_cant_read:

> -	if (verbose > 0) {

> -		fprintf(trace->output, "Problems reading syscall %d", id);

> -		if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)

> -			fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);

> -		fputs(" information\n", trace->output);

> -	}

> +	pr_debug("Problems reading syscall %d", id);

> +	if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)

> +		pr_debug("(%s)", trace->syscalls.table[id].name);

> +	pr_debug(" information\n");

>  	return NULL;

>  }

>  

> -- 

> 2.17.1


-- 

- Arnaldo
Leo Yan June 18, 2019, 6:24 a.m. | #2
On Mon, Jun 17, 2019 at 12:24:12PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jun 17, 2019 at 05:11:39PM +0800, Leo Yan escreveu:

> > In the function trace__syscall_info(), it explicitly checks verbose

> > level and print out log with fprintf().  Actually, we can use

> > pr_debug() to do the same thing for debug logging.

> > 

> > This patch uses pr_debug() instead of fprintf() for debug logging; it

> > includes a minor fixing for 'space before tab in indent', which

> > dismisses git warning when apply it.

> 

> But those are not fprintf(stdout,), they explicitely redirect to the

> output file that the user may have specified using 'perf trace --output

> filename.trace' :-)


Thanks for pointing out, sorry for noise. Please drop this patch.

Thanks,
Leo Yan

> > Signed-off-by: Leo Yan <leo.yan@linaro.org>

> > ---

> >  tools/perf/builtin-trace.c | 21 +++++++++------------

> >  1 file changed, 9 insertions(+), 12 deletions(-)

> > 

> > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c

> > index bd1f00e7a2eb..5cd74651db4c 100644

> > --- a/tools/perf/builtin-trace.c

> > +++ b/tools/perf/builtin-trace.c

> > @@ -1760,12 +1760,11 @@ static struct syscall *trace__syscall_info(struct trace *trace,

> >  		 * grep "NR -1 " /t/trace_pipe

> >  		 *

> >  		 * After generating some load on the machine.

> > - 		 */

> > -		if (verbose > 1) {

> > -			static u64 n;

> > -			fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",

> > -				id, perf_evsel__name(evsel), ++n);

> > -		}

> > +		 */

> > +		static u64 n;

> > +

> > +		pr_debug("Invalid syscall %d id, skipping (%s, %" PRIu64 ")\n",

> > +			 id, perf_evsel__name(evsel), ++n);

> >  		return NULL;

> >  	}

> >  

> > @@ -1779,12 +1778,10 @@ static struct syscall *trace__syscall_info(struct trace *trace,

> >  	return &trace->syscalls.table[id];

> >  

> >  out_cant_read:

> > -	if (verbose > 0) {

> > -		fprintf(trace->output, "Problems reading syscall %d", id);

> > -		if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)

> > -			fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);

> > -		fputs(" information\n", trace->output);

> > -	}

> > +	pr_debug("Problems reading syscall %d", id);

> > +	if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)

> > +		pr_debug("(%s)", trace->syscalls.table[id].name);

> > +	pr_debug(" information\n");

> >  	return NULL;

> >  }

> >  

> > -- 

> > 2.17.1

> 

> -- 

> 

> - Arnaldo

Patch

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index bd1f00e7a2eb..5cd74651db4c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1760,12 +1760,11 @@  static struct syscall *trace__syscall_info(struct trace *trace,
 		 * grep "NR -1 " /t/trace_pipe
 		 *
 		 * After generating some load on the machine.
- 		 */
-		if (verbose > 1) {
-			static u64 n;
-			fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
-				id, perf_evsel__name(evsel), ++n);
-		}
+		 */
+		static u64 n;
+
+		pr_debug("Invalid syscall %d id, skipping (%s, %" PRIu64 ")\n",
+			 id, perf_evsel__name(evsel), ++n);
 		return NULL;
 	}
 
@@ -1779,12 +1778,10 @@  static struct syscall *trace__syscall_info(struct trace *trace,
 	return &trace->syscalls.table[id];
 
 out_cant_read:
-	if (verbose > 0) {
-		fprintf(trace->output, "Problems reading syscall %d", id);
-		if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)
-			fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
-		fputs(" information\n", trace->output);
-	}
+	pr_debug("Problems reading syscall %d", id);
+	if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL)
+		pr_debug("(%s)", trace->syscalls.table[id].name);
+	pr_debug(" information\n");
 	return NULL;
 }