perf stat: Measure 't0' and 'ref_time' after enable_counters()

Take measurements of 't0' and 'ref_time' after enable_counters(), so
that they only measure the time consumed when the counters are enabled.

Signed-off-by: Song Liu <songliubraving@fb.com>
Acked-by: Andi Kleen <andi@firstfloor.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20210316211837.910506-3-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Song Liu 2021-03-16 14:18:36 -07:00 committed by Arnaldo Carvalho de Melo
parent 7fac83aaf2
commit 435b46ef1d

View File

@ -931,15 +931,15 @@ try_again_reset:
/* /*
* Enable counters and exec the command: * Enable counters and exec the command:
*/ */
t0 = rdclock();
clock_gettime(CLOCK_MONOTONIC, &ref_time);
if (forks) { if (forks) {
evlist__start_workload(evsel_list); evlist__start_workload(evsel_list);
err = enable_counters(); err = enable_counters();
if (err) if (err)
return -1; return -1;
t0 = rdclock();
clock_gettime(CLOCK_MONOTONIC, &ref_time);
if (interval || timeout || evlist__ctlfd_initialized(evsel_list)) if (interval || timeout || evlist__ctlfd_initialized(evsel_list))
status = dispatch_events(forks, timeout, interval, &times); status = dispatch_events(forks, timeout, interval, &times);
if (child_pid != -1) { if (child_pid != -1) {
@ -960,6 +960,10 @@ try_again_reset:
err = enable_counters(); err = enable_counters();
if (err) if (err)
return -1; return -1;
t0 = rdclock();
clock_gettime(CLOCK_MONOTONIC, &ref_time);
status = dispatch_events(forks, timeout, interval, &times); status = dispatch_events(forks, timeout, interval, &times);
} }