public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
@ 2014-07-17  8:21 Namhyung Kim
  2014-07-17  8:26 ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Namhyung Kim @ 2014-07-17  8:21 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Paul Mackerras, Namhyung Kim,
	Namhyung Kim, LKML, Jiri Olsa, Minchan Kim

When perf stat runs multiple times via -r option, it's sometimes
useful for a workload to know which run it executing.  So pass new
PERF_STAT_RUN environment variable to the workload for each run
(starting from 1).

Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-stat.c |  8 +++++---
 tools/perf/util/evlist.c  | 10 +++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 65a151e36067..53b3c99be5b3 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -144,6 +144,8 @@ static struct timespec		ref_time;
 static struct cpu_map		*aggr_map;
 static int			(*aggr_get_id)(struct cpu_map *m, int cpu);
 
+int stat_run;
+
 static volatile int done = 0;
 
 struct perf_stat {
@@ -1674,7 +1676,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		"perf stat [<options>] [<command>]",
 		NULL
 	};
-	int status = -EINVAL, run_idx;
+	int status = -EINVAL;
 	const char *mode;
 
 	setlocale(LC_ALL, "");
@@ -1812,10 +1814,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	signal(SIGABRT, skip_signal);
 
 	status = 0;
-	for (run_idx = 0; forever || run_idx < run_count; run_idx++) {
+	for (stat_run = 1; forever || stat_run <= run_count; stat_run++) {
 		if (run_count != 1 && verbose)
 			fprintf(output, "[ perf stat: executing run #%d ... ]\n",
-				run_idx + 1);
+				stat_run);
 
 		status = run_perf_stat(argc, argv);
 		if (forever && status != -1) {
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 59ef2802fcf6..3bd86aeea99d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1031,6 +1031,7 @@ out_err:
 	return err;
 }
 
+extern int stat_run;
 int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *target,
 				  const char *argv[], bool pipe_output,
 				  void (*exec_error)(int signo, siginfo_t *info, void *ucontext))
@@ -1055,6 +1056,8 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
 	}
 
 	if (!evlist->workload.pid) {
+		char buf[32];
+
 		if (pipe_output)
 			dup2(2, 1);
 
@@ -1075,7 +1078,12 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
 		if (read(go_pipe[0], &bf, 1) == -1)
 			perror("unable to read pipe");
 
-		execvp(argv[0], (char **)argv);
+		if (stat_run) {
+			snprintf(buf, sizeof(buf), "%d", stat_run);
+			setenv("PERF_STAT_RUN", buf, 1);
+		}
+
+		execvpe(argv[0], (char **)argv, environ);
 
 		if (exec_error) {
 			union sigval val;
-- 
2.0.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
  2014-07-17  8:21 [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run Namhyung Kim
@ 2014-07-17  8:26 ` Peter Zijlstra
  2014-07-17  8:31   ` Namhyung Kim
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2014-07-17  8:26 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Paul Mackerras,
	Namhyung Kim, LKML, Jiri Olsa, Minchan Kim

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

On Thu, Jul 17, 2014 at 05:21:06PM +0900, Namhyung Kim wrote:
> When perf stat runs multiple times via -r option, it's sometimes
> useful for a workload to know which run it executing.  So pass new
> PERF_STAT_RUN environment variable to the workload for each run
> (starting from 1).

This seems counter intuitive, runs should be _identical_ otherwise
there's no point. That means the workload should very much _not_ know
these things.

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
  2014-07-17  8:26 ` Peter Zijlstra
@ 2014-07-17  8:31   ` Namhyung Kim
  2014-07-17  8:40     ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Namhyung Kim @ 2014-07-17  8:31 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Paul Mackerras,
	Namhyung Kim, LKML, Jiri Olsa, Minchan Kim

Hi Peter,

On Thu, Jul 17, 2014 at 5:26 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Thu, Jul 17, 2014 at 05:21:06PM +0900, Namhyung Kim wrote:
>> When perf stat runs multiple times via -r option, it's sometimes
>> useful for a workload to know which run it executing.  So pass new
>> PERF_STAT_RUN environment variable to the workload for each run
>> (starting from 1).
>
> This seems counter intuitive, runs should be _identical_ otherwise
> there's no point. That means the workload should very much _not_ know
> these things.

But I think it can be useful if a workload wants to save logfiles
based on the iteration number for example.  If it doesn't want, it can
just ignore. :)

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
  2014-07-17  8:31   ` Namhyung Kim
@ 2014-07-17  8:40     ` Peter Zijlstra
  2014-07-17 13:09       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2014-07-17  8:40 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Paul Mackerras,
	Namhyung Kim, LKML, Jiri Olsa, Minchan Kim

[-- Attachment #1: Type: text/plain, Size: 944 bytes --]

On Thu, Jul 17, 2014 at 05:31:14PM +0900, Namhyung Kim wrote:
> Hi Peter,
> 
> On Thu, Jul 17, 2014 at 5:26 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Thu, Jul 17, 2014 at 05:21:06PM +0900, Namhyung Kim wrote:
> >> When perf stat runs multiple times via -r option, it's sometimes
> >> useful for a workload to know which run it executing.  So pass new
> >> PERF_STAT_RUN environment variable to the workload for each run
> >> (starting from 1).
> >
> > This seems counter intuitive, runs should be _identical_ otherwise
> > there's no point. That means the workload should very much _not_ know
> > these things.
> 
> But I think it can be useful if a workload wants to save logfiles
> based on the iteration number for example.  If it doesn't want, it can
> just ignore. :)

That's the wrong way around. Also, there's --pre and --post hooks to
preserve logfiles if you really have to do that kind of thing.



[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
  2014-07-17  8:40     ` Peter Zijlstra
@ 2014-07-17 13:09       ` Arnaldo Carvalho de Melo
  2014-07-18  5:06         ` Namhyung Kim
  0 siblings, 1 reply; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-07-17 13:09 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Namhyung Kim, Ingo Molnar, Paul Mackerras, Namhyung Kim, LKML,
	Jiri Olsa, Minchan Kim

Em Thu, Jul 17, 2014 at 10:40:11AM +0200, Peter Zijlstra escreveu:
> On Thu, Jul 17, 2014 at 05:31:14PM +0900, Namhyung Kim wrote:
> > On Thu, Jul 17, 2014 at 5:26 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> > > On Thu, Jul 17, 2014 at 05:21:06PM +0900, Namhyung Kim wrote:
> > >> When perf stat runs multiple times via -r option, it's sometimes
> > >> useful for a workload to know which run it executing.  So pass new
> > >> PERF_STAT_RUN environment variable to the workload for each run
> > >> (starting from 1).

> > > This seems counter intuitive, runs should be _identical_ otherwise
> > > there's no point. That means the workload should very much _not_ know
> > > these things.

> > But I think it can be useful if a workload wants to save logfiles
> > based on the iteration number for example.  If it doesn't want, it can
> > just ignore. :)

> That's the wrong way around. Also, there's --pre and --post hooks to
> preserve logfiles if you really have to do that kind of thing.

Agreed, one can script this using --pre or --post if needed.

- Arnaldo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run
  2014-07-17 13:09       ` Arnaldo Carvalho de Melo
@ 2014-07-18  5:06         ` Namhyung Kim
  0 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2014-07-18  5:06 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Paul Mackerras, Namhyung Kim, LKML,
	Jiri Olsa, Minchan Kim

Hi Arnaldo and Peter,

On Thu, 17 Jul 2014 10:09:43 -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 17, 2014 at 10:40:11AM +0200, Peter Zijlstra escreveu:
>> On Thu, Jul 17, 2014 at 05:31:14PM +0900, Namhyung Kim wrote:
>> > On Thu, Jul 17, 2014 at 5:26 PM, Peter Zijlstra <peterz@infradead.org> wrote:
>> > > On Thu, Jul 17, 2014 at 05:21:06PM +0900, Namhyung Kim wrote:
>> > >> When perf stat runs multiple times via -r option, it's sometimes
>> > >> useful for a workload to know which run it executing.  So pass new
>> > >> PERF_STAT_RUN environment variable to the workload for each run
>> > >> (starting from 1).
>
>> > > This seems counter intuitive, runs should be _identical_ otherwise
>> > > there's no point. That means the workload should very much _not_ know
>> > > these things.
>
>> > But I think it can be useful if a workload wants to save logfiles
>> > based on the iteration number for example.  If it doesn't want, it can
>> > just ignore. :)
>
>> That's the wrong way around. Also, there's --pre and --post hooks to
>> preserve logfiles if you really have to do that kind of thing.
>
> Agreed, one can script this using --pre or --post if needed.

Hmm... okay, I'll drop this then.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-18  5:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17  8:21 [PATCH] perf stat: Pass PERF_STAT_RUN environment variable for each run Namhyung Kim
2014-07-17  8:26 ` Peter Zijlstra
2014-07-17  8:31   ` Namhyung Kim
2014-07-17  8:40     ` Peter Zijlstra
2014-07-17 13:09       ` Arnaldo Carvalho de Melo
2014-07-18  5:06         ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox