]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/perf/builtin-record.c
perf record: Fix crash in pipe mode
[linux.git] / tools / perf / builtin-record.c
index 65681a1a292a5457c712e8780107903e191472c8..12230ddb650690e5c434a20527f5022897b909d7 100644 (file)
@@ -45,6 +45,7 @@
 
 #include <errno.h>
 #include <inttypes.h>
+#include <locale.h>
 #include <poll.h>
 #include <unistd.h>
 #include <sched.h>
@@ -881,6 +882,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
                }
        }
 
+       /*
+        * If we have just single event and are sending data
+        * through pipe, we need to force the ids allocation,
+        * because we synthesize event name through the pipe
+        * and need the id for that.
+        */
+       if (data->is_pipe && rec->evlist->nr_entries == 1)
+               rec->opts.sample_id = true;
+
        if (record__open(rec) != 0) {
                err = -1;
                goto out_child;
@@ -1542,7 +1552,11 @@ static struct option __record_options[] = {
        OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
                    "synthesize non-sample events at the end of output"),
        OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
-       OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
+       OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
+                   "Fail if the specified frequency can't be used"),
+       OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
+                    "profile at this frequency",
+                     record__parse_freq),
        OPT_CALLBACK('m', "mmap-pages", &record.opts, "pages[,pages]",
                     "number of mmap data pages and AUX area tracing mmap pages",
                     record__parse_mmap_pages),
@@ -1566,7 +1580,8 @@ static struct option __record_options[] = {
        OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
                        &record.opts.sample_time_set,
                        "Record the sample timestamps"),
-       OPT_BOOLEAN('P', "period", &record.opts.period, "Record the sample period"),
+       OPT_BOOLEAN_SET('P', "period", &record.opts.period, &record.opts.period_set,
+                       "Record the sample period"),
        OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples,
                    "don't sample"),
        OPT_BOOLEAN_SET('N', "no-buildid-cache", &record.no_buildid_cache,
@@ -1650,6 +1665,8 @@ int cmd_record(int argc, const char **argv)
        struct record *rec = &record;
        char errbuf[BUFSIZ];
 
+       setlocale(LC_ALL, "");
+
 #ifndef HAVE_LIBBPF_SUPPORT
 # define set_nobuild(s, l, c) set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c)
        set_nobuild('\0', "clang-path", true);
@@ -1802,7 +1819,7 @@ int cmd_record(int argc, const char **argv)
        err = target__validate(&rec->opts.target);
        if (err) {
                target__strerror(&rec->opts.target, err, errbuf, BUFSIZ);
-               ui__warning("%s", errbuf);
+               ui__warning("%s\n", errbuf);
        }
 
        err = target__parse_uid(&rec->opts.target);