Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191198
b: refs/heads/master
c: 7865e81
h: refs/heads/master
v: v3
  • Loading branch information
Frederic Weisbecker committed Apr 15, 2010
1 parent 5489f71 commit 2fd343a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a1e2f60e3efc812bf66a2be0d8530ee175003f6d
refs/heads/master: 7865e817e9b4b378ac57ab7f16183100b95466ce
2 changes: 1 addition & 1 deletion trunk/tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ OPTIONS

-f::
--force::
Overwrite existing data file.
Overwrite existing data file. (deprecated)

-c::
--count=::
Expand Down
40 changes: 25 additions & 15 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include <unistd.h>
#include <sched.h>

enum write_mode_t {
WRITE_FORCE,
WRITE_APPEND
};

static int *fd[MAX_NR_CPUS][MAX_COUNTERS];

static long default_interval = 0;
Expand All @@ -47,8 +52,7 @@ static pid_t *all_tids = NULL;
static int thread_num = 0;
static pid_t child_pid = -1;
static bool inherit = true;
static bool force = false;
static bool append_file = false;
static enum write_mode_t write_mode = WRITE_FORCE;
static bool call_graph = false;
static bool inherit_stat = false;
static bool no_samples = false;
Expand Down Expand Up @@ -450,26 +454,19 @@ static int __cmd_record(int argc, const char **argv)
}

if (!stat(output_name, &st) && st.st_size) {
if (!force) {
if (!append_file) {
pr_err("Error, output file %s exists, use -A "
"to append or -f to overwrite.\n",
output_name);
exit(-1);
}
} else {
if (write_mode == WRITE_FORCE) {
char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old",
output_name);
unlink(oldname);
rename(output_name, oldname);
}
} else {
append_file = false;
} else if (write_mode == WRITE_APPEND) {
write_mode = WRITE_FORCE;
}

flags = O_CREAT|O_RDWR;
if (append_file)
if (write_mode == WRITE_APPEND)
file_new = 0;
else
flags |= O_TRUNC;
Expand All @@ -480,7 +477,8 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}

session = perf_session__new(output_name, O_WRONLY, force);
session = perf_session__new(output_name, O_WRONLY,
write_mode == WRITE_FORCE);
if (session == NULL) {
pr_err("Not enough memory for reading perf file header\n");
return -1;
Expand Down Expand Up @@ -667,6 +665,8 @@ static const char * const record_usage[] = {
NULL
};

static bool force, append_file;

static const struct option options[] = {
OPT_CALLBACK('e', "event", NULL, "event",
"event selector. use 'perf list' to list available events",
Expand All @@ -688,7 +688,7 @@ static const struct option options[] = {
OPT_INTEGER('C', "profile_cpu", &profile_cpu,
"CPU to profile on"),
OPT_BOOLEAN('f', "force", &force,
"overwrite existing data file"),
"overwrite existing data file (deprecated)"),
OPT_LONG('c', "count", &default_interval,
"event period to sample"),
OPT_STRING('o', "output", &output_name, "file",
Expand Down Expand Up @@ -725,6 +725,16 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
!system_wide && profile_cpu == -1)
usage_with_options(record_usage, options);

if (force && append_file) {
fprintf(stderr, "Can't overwrite and append at the same time."
" You need to choose between -f and -A");
usage_with_options(record_usage, options);
} else if (append_file) {
write_mode = WRITE_APPEND;
} else {
write_mode = WRITE_FORCE;
}

symbol__init();

if (!nr_counters) {
Expand Down

0 comments on commit 2fd343a

Please sign in to comment.