Skip to content

Commit bb8bc52

Browse files
ramymdscacmel
authored andcommitted
perf stat: Refactor __run_perf_stat() common code
This extracts common code from the branches of the forks if-then-else. enable_counters(), which was at the beginning of both branches of the conditional, is now unconditional; evlist__start_workload() is extracted to a different if, which enables making the common clocking code unconditional. Reviewed-by: Leo Yan <[email protected]> Signed-off-by: Adrián Herrera Arcila <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6d499a6 commit bb8bc52

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

tools/perf/builtin-stat.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -967,18 +967,18 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
967967
return err;
968968
}
969969

970-
/*
971-
* Enable counters and exec the command:
972-
*/
973-
if (forks) {
974-
err = enable_counters();
975-
if (err)
976-
return -1;
970+
err = enable_counters();
971+
if (err)
972+
return -1;
973+
974+
/* Exec the command, if any */
975+
if (forks)
977976
evlist__start_workload(evsel_list);
978977

979-
t0 = rdclock();
980-
clock_gettime(CLOCK_MONOTONIC, &ref_time);
978+
t0 = rdclock();
979+
clock_gettime(CLOCK_MONOTONIC, &ref_time);
981980

981+
if (forks) {
982982
if (interval || timeout || evlist__ctlfd_initialized(evsel_list))
983983
status = dispatch_events(forks, timeout, interval, &times);
984984
if (child_pid != -1) {
@@ -996,13 +996,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
996996
if (WIFSIGNALED(status))
997997
psignal(WTERMSIG(status), argv[0]);
998998
} else {
999-
err = enable_counters();
1000-
if (err)
1001-
return -1;
1002-
1003-
t0 = rdclock();
1004-
clock_gettime(CLOCK_MONOTONIC, &ref_time);
1005-
1006999
status = dispatch_events(forks, timeout, interval, &times);
10071000
}
10081001

0 commit comments

Comments
 (0)