aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2009-06-02 09:52:24 -0400
committerIngo Molnar <mingo@elte.hu>2009-06-02 10:16:26 -0400
commit97124d5e2df5b9eaa5bb684bb1e8ebc7e29d0f5d (patch)
tree3fcfeacdaefe0b268984a49ebf018b6c8ebbfe0d
parentf70e87d7a6d9c5a23d5f43ed0a0c224c157ef597 (diff)
perf_counter: tools: Better handle existing data files
Provide an argument (-f) to overwrite existing data files. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: John Kacur <jkacur@redhat.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--Documentation/perf_counter/builtin-record.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/Documentation/perf_counter/builtin-record.c b/Documentation/perf_counter/builtin-record.c
index 810fc275ca65..bace7a8edf80 100644
--- a/Documentation/perf_counter/builtin-record.c
+++ b/Documentation/perf_counter/builtin-record.c
@@ -7,6 +7,7 @@
7#include "util/parse-events.h" 7#include "util/parse-events.h"
8#include "util/string.h" 8#include "util/string.h"
9 9
10#include <unistd.h>
10#include <sched.h> 11#include <sched.h>
11 12
12#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) 13#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
@@ -26,7 +27,7 @@ static unsigned int realtime_prio = 0;
26static int system_wide = 0; 27static int system_wide = 0;
27static pid_t target_pid = -1; 28static pid_t target_pid = -1;
28static int inherit = 1; 29static int inherit = 1;
29static int nmi = 1; 30static int force = 0;
30 31
31const unsigned int default_count[] = { 32const unsigned int default_count[] = {
32 1000000, 33 1000000,
@@ -337,7 +338,6 @@ static void open_counters(int cpu, pid_t pid)
337 hw_event.config = event_id[counter]; 338 hw_event.config = event_id[counter];
338 hw_event.irq_period = event_count[counter]; 339 hw_event.irq_period = event_count[counter];
339 hw_event.record_type = PERF_RECORD_IP | PERF_RECORD_TID; 340 hw_event.record_type = PERF_RECORD_IP | PERF_RECORD_TID;
340 hw_event.nmi = nmi;
341 hw_event.mmap = track; 341 hw_event.mmap = track;
342 hw_event.comm = track; 342 hw_event.comm = track;
343 hw_event.inherit = (cpu < 0) && inherit; 343 hw_event.inherit = (cpu < 0) && inherit;
@@ -387,13 +387,20 @@ static int __cmd_record(int argc, const char **argv)
387 int i, counter; 387 int i, counter;
388 pid_t pid; 388 pid_t pid;
389 int ret; 389 int ret;
390 struct stat st;
390 391
391 page_size = sysconf(_SC_PAGE_SIZE); 392 page_size = sysconf(_SC_PAGE_SIZE);
392 nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); 393 nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
393 assert(nr_cpus <= MAX_NR_CPUS); 394 assert(nr_cpus <= MAX_NR_CPUS);
394 assert(nr_cpus >= 0); 395 assert(nr_cpus >= 0);
395 396
396 output = open(output_name, O_CREAT|O_EXCL|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR); 397 if (!stat(output_name, &st) && !force) {
398 fprintf(stderr, "Error, output file: %s exists, use -f to overwrite.\n",
399 output_name);
400 exit(-1);
401 }
402
403 output = open(output_name, O_CREAT|O_TRUNC|O_RDWR, S_IRUSR|S_IWUSR);
397 if (output < 0) { 404 if (output < 0) {
398 perror("failed to create output file"); 405 perror("failed to create output file");
399 exit(-1); 406 exit(-1);
@@ -473,6 +480,8 @@ static const struct option options[] = {
473 "collect data with this RT SCHED_FIFO priority"), 480 "collect data with this RT SCHED_FIFO priority"),
474 OPT_BOOLEAN('a', "all-cpus", &system_wide, 481 OPT_BOOLEAN('a', "all-cpus", &system_wide,
475 "system-wide collection from all CPUs"), 482 "system-wide collection from all CPUs"),
483 OPT_BOOLEAN('f', "force", &force,
484 "overwrite existing data file"),
476 OPT_END() 485 OPT_END()
477}; 486};
478 487