aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2016-10-07 12:47:10 -0400
committerSteven Rostedt <rostedt@goodmis.org>2016-10-28 15:30:00 -0400
commit0b4a964bcacf7db16f95eccb80d5452b1a6191ab (patch)
tree20371bf85cd87493ca99c42cdb4c5094eef25ca9
parent693ecdc486a50e1ed2a9f5542a4c70aa4d0ccaff (diff)
downloadtrace-cmd-0b4a964bcacf7db16f95eccb80d5452b1a6191ab.tar.gz
trace-cmd record: refactor set_mask()
This commit does the following: 1. Move the code that treats "-M -1" out of set_mask() 2. Drop uneeded checks from set_mask() 3. Make instance->cpumask point to dynamic memory This is a preparation for supporting the "--cpu-list" option in the next commit. Link: http://lkml.kernel.org/r/1475858831-32687-3-git-send-email-lcapitulino@redhat.com Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-local.h2
-rw-r--r--trace-record.c53
2 files changed, 34 insertions, 21 deletions
diff --git a/trace-local.h b/trace-local.h
index 62363d0f..0ac39bfa 100644
--- a/trace-local.h
+++ b/trace-local.h
@@ -143,7 +143,7 @@ struct func_list {
struct buffer_instance {
struct buffer_instance *next;
const char *name;
- const char *cpumask;
+ char *cpumask;
struct event_list *events;
struct event_list **event_next;
diff --git a/trace-record.c b/trace-record.c
index 22b6835c..b0429936 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -2078,27 +2078,25 @@ static void update_pid_event_filters(struct buffer_instance *instance)
update_event_filters(instance);
}
-static void set_mask(struct buffer_instance *instance)
-{
- const char *mask = instance->cpumask;
- struct stat st;
- char cpumask[4096]; /* Don't expect more than 32768 CPUS */
- char *path;
- int fd;
- int ret;
+#define MASK_STR_MAX 4096 /* Don't expect more than 32768 CPUS */
- if (!mask)
- return;
+static char *alloc_mask_from_hex(const char *str)
+{
+ char *cpumask;
- if (strcmp(mask, "-1") == 0) {
+ if (strcmp(str, "-1") == 0) {
/* set all CPUs */
int bytes = (cpu_count + 7) / 8;
int last = cpu_count % 8;
int i;
- if (bytes > 4095) {
+ cpumask = malloc(MASK_STR_MAX);
+ if (!cpumask)
+ die("can't allocate cpumask");
+
+ if (bytes > (MASK_STR_MAX-1)) {
warning("cpumask can't handle more than 32768 CPUS!");
- bytes = 4095;
+ bytes = MASK_STR_MAX-1;
}
sprintf(cpumask, "%x", (1 << last) - 1);
@@ -2107,18 +2105,32 @@ static void set_mask(struct buffer_instance *instance)
cpumask[i] = 'f';
cpumask[i+1] = 0;
-
- mask = cpumask;
+ } else {
+ cpumask = strdup(str);
+ if (!cpumask)
+ die("can't allocate cpumask");
}
+ return cpumask;
+}
+
+static void set_mask(struct buffer_instance *instance)
+{
+ struct stat st;
+ char *path;
+ int fd;
+ int ret;
+
+ if (!instance->cpumask)
+ return;
+
path = get_instance_file(instance, "tracing_cpumask");
if (!path)
die("could not allocate path");
ret = stat(path, &st);
if (ret < 0) {
- if (mask)
- warning("%s not found", path);
+ warning("%s not found", path);
goto out;
}
@@ -2126,12 +2138,13 @@ static void set_mask(struct buffer_instance *instance)
if (fd < 0)
die("could not open %s\n", path);
- if (mask)
- write(fd, mask, strlen(mask));
+ write(fd, instance->cpumask, strlen(instance->cpumask));
close(fd);
out:
tracecmd_put_tracing_file(path);
+ free(instance->cpumask);
+ instance->cpumask = NULL;
}
static void enable_events(struct buffer_instance *instance)
@@ -4530,7 +4543,7 @@ void trace_record (int argc, char **argv)
max_kb = atoi(optarg);
break;
case 'M':
- instance->cpumask = optarg;
+ instance->cpumask = alloc_mask_from_hex(optarg);
break;
case 't':
if (extract)