diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2010-04-14 13:42:07 -0400 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2010-04-14 22:12:51 -0400 |
commit | 7865e817e9b4b378ac57ab7f16183100b95466ce (patch) | |
tree | b3fd7772abc44491b884b780f5cac364a2ace563 | |
parent | a1e2f60e3efc812bf66a2be0d8530ee175003f6d (diff) |
perf: Make -f the default for perf record
Force the overwriting mode by default if append mode is not explicit.
Adding -f every time one uses perf on a daily basis quickly becomes a
burden.
Keep the -f among the options though to avoid breaking some random
users scripts.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | tools/perf/Documentation/perf-record.txt | 2 | ||||
-rw-r--r-- | tools/perf/builtin-record.c | 40 |
2 files changed, 26 insertions, 16 deletions
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index fc46c0b40f6e..b29bd2db6a49 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -58,7 +58,7 @@ OPTIONS | |||
58 | 58 | ||
59 | -f:: | 59 | -f:: |
60 | --force:: | 60 | --force:: |
61 | Overwrite existing data file. | 61 | Overwrite existing data file. (deprecated) |
62 | 62 | ||
63 | -c:: | 63 | -c:: |
64 | --count=:: | 64 | --count=:: |
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 9a9513687235..dcda8993082d 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -26,6 +26,11 @@ | |||
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <sched.h> | 27 | #include <sched.h> |
28 | 28 | ||
29 | enum write_mode_t { | ||
30 | WRITE_FORCE, | ||
31 | WRITE_APPEND | ||
32 | }; | ||
33 | |||
29 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; | 34 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
30 | 35 | ||
31 | static long default_interval = 0; | 36 | static long default_interval = 0; |
@@ -47,8 +52,7 @@ static pid_t *all_tids = NULL; | |||
47 | static int thread_num = 0; | 52 | static int thread_num = 0; |
48 | static pid_t child_pid = -1; | 53 | static pid_t child_pid = -1; |
49 | static bool inherit = true; | 54 | static bool inherit = true; |
50 | static bool force = false; | 55 | static enum write_mode_t write_mode = WRITE_FORCE; |
51 | static bool append_file = false; | ||
52 | static bool call_graph = false; | 56 | static bool call_graph = false; |
53 | static bool inherit_stat = false; | 57 | static bool inherit_stat = false; |
54 | static bool no_samples = false; | 58 | static bool no_samples = false; |
@@ -450,26 +454,19 @@ static int __cmd_record(int argc, const char **argv) | |||
450 | } | 454 | } |
451 | 455 | ||
452 | if (!stat(output_name, &st) && st.st_size) { | 456 | if (!stat(output_name, &st) && st.st_size) { |
453 | if (!force) { | 457 | if (write_mode == WRITE_FORCE) { |
454 | if (!append_file) { | ||
455 | pr_err("Error, output file %s exists, use -A " | ||
456 | "to append or -f to overwrite.\n", | ||
457 | output_name); | ||
458 | exit(-1); | ||
459 | } | ||
460 | } else { | ||
461 | char oldname[PATH_MAX]; | 458 | char oldname[PATH_MAX]; |
462 | snprintf(oldname, sizeof(oldname), "%s.old", | 459 | snprintf(oldname, sizeof(oldname), "%s.old", |
463 | output_name); | 460 | output_name); |
464 | unlink(oldname); | 461 | unlink(oldname); |
465 | rename(output_name, oldname); | 462 | rename(output_name, oldname); |
466 | } | 463 | } |
467 | } else { | 464 | } else if (write_mode == WRITE_APPEND) { |
468 | append_file = false; | 465 | write_mode = WRITE_FORCE; |
469 | } | 466 | } |
470 | 467 | ||
471 | flags = O_CREAT|O_RDWR; | 468 | flags = O_CREAT|O_RDWR; |
472 | if (append_file) | 469 | if (write_mode == WRITE_APPEND) |
473 | file_new = 0; | 470 | file_new = 0; |
474 | else | 471 | else |
475 | flags |= O_TRUNC; | 472 | flags |= O_TRUNC; |
@@ -480,7 +477,8 @@ static int __cmd_record(int argc, const char **argv) | |||
480 | exit(-1); | 477 | exit(-1); |
481 | } | 478 | } |
482 | 479 | ||
483 | session = perf_session__new(output_name, O_WRONLY, force); | 480 | session = perf_session__new(output_name, O_WRONLY, |
481 | write_mode == WRITE_FORCE); | ||
484 | if (session == NULL) { | 482 | if (session == NULL) { |
485 | pr_err("Not enough memory for reading perf file header\n"); | 483 | pr_err("Not enough memory for reading perf file header\n"); |
486 | return -1; | 484 | return -1; |
@@ -667,6 +665,8 @@ static const char * const record_usage[] = { | |||
667 | NULL | 665 | NULL |
668 | }; | 666 | }; |
669 | 667 | ||
668 | static bool force, append_file; | ||
669 | |||
670 | static const struct option options[] = { | 670 | static const struct option options[] = { |
671 | OPT_CALLBACK('e', "event", NULL, "event", | 671 | OPT_CALLBACK('e', "event", NULL, "event", |
672 | "event selector. use 'perf list' to list available events", | 672 | "event selector. use 'perf list' to list available events", |
@@ -688,7 +688,7 @@ static const struct option options[] = { | |||
688 | OPT_INTEGER('C', "profile_cpu", &profile_cpu, | 688 | OPT_INTEGER('C', "profile_cpu", &profile_cpu, |
689 | "CPU to profile on"), | 689 | "CPU to profile on"), |
690 | OPT_BOOLEAN('f', "force", &force, | 690 | OPT_BOOLEAN('f', "force", &force, |
691 | "overwrite existing data file"), | 691 | "overwrite existing data file (deprecated)"), |
692 | OPT_LONG('c', "count", &default_interval, | 692 | OPT_LONG('c', "count", &default_interval, |
693 | "event period to sample"), | 693 | "event period to sample"), |
694 | OPT_STRING('o', "output", &output_name, "file", | 694 | OPT_STRING('o', "output", &output_name, "file", |
@@ -725,6 +725,16 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
725 | !system_wide && profile_cpu == -1) | 725 | !system_wide && profile_cpu == -1) |
726 | usage_with_options(record_usage, options); | 726 | usage_with_options(record_usage, options); |
727 | 727 | ||
728 | if (force && append_file) { | ||
729 | fprintf(stderr, "Can't overwrite and append at the same time." | ||
730 | " You need to choose between -f and -A"); | ||
731 | usage_with_options(record_usage, options); | ||
732 | } else if (append_file) { | ||
733 | write_mode = WRITE_APPEND; | ||
734 | } else { | ||
735 | write_mode = WRITE_FORCE; | ||
736 | } | ||
737 | |||
728 | symbol__init(); | 738 | symbol__init(); |
729 | 739 | ||
730 | if (!nr_counters) { | 740 | if (!nr_counters) { |