Skip to content

Commit b38d346

Browse files
acmelIngo Molnar
authored andcommitted
perf record: Rename perf.data to perf.data.old if --force/-f is used
Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1260828571-3613-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent c8829c7 commit b38d346

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎tools/perf/builtin-record.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,19 @@ static int __cmd_record(int argc, const char **argv)
421421
signal(SIGINT, sig_handler);
422422

423423
if (!stat(output_name, &st) && st.st_size) {
424-
if (!force && !append_file) {
425-
fprintf(stderr, "Error, output file %s exists, use -A to append or -f to overwrite.\n",
426-
output_name);
427-
exit(-1);
424+
if (!force) {
425+
if (!append_file) {
426+
pr_err("Error, output file %s exists, use -A "
427+
"to append or -f to overwrite.\n",
428+
output_name);
429+
exit(-1);
430+
}
431+
} else {
432+
char oldname[PATH_MAX];
433+
snprintf(oldname, sizeof(oldname), "%s.old",
434+
output_name);
435+
unlink(oldname);
436+
rename(output_name, oldname);
428437
}
429438
} else {
430439
append_file = 0;

0 commit comments

Comments
 (0)