In an effort to make trace-cmd more easily linked against we need to separate
out the instance handling functionality. I've renamed buffer_instance to
tracecmd_buffer_instance and moved the relevant helper functions into their own
file and moved the definitions into trace-cmd.h. Thanks,
Signed-off-by: Josef Bacik <[email protected]>
---
Makefile | 3 +-
trace-cmd.c | 9 +-
trace-cmd.h | 102 +++++++++++--
trace-instance.c | 185 +++++++++++++++++++++++
trace-local.h | 70 ++-------
trace-record.c | 449 ++++++++++++++++++++-----------------------------------
trace-stat.c | 68 ++++-----
trace-stream.c | 4 +-
8 files changed, 482 insertions(+), 408 deletions(-)
create mode 100644 trace-instance.c
diff --git a/Makefile b/Makefile
index 6b5bd29..d538725 100644
--- a/Makefile
+++ b/Makefile
@@ -336,7 +336,8 @@ PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o
TCMD_LIB_OBJS = $(PEVENT_LIB_OBJS) trace-util.o trace-input.o trace-ftrace.o \
trace-output.o trace-record.o trace-recorder.o \
trace-restore.o trace-usage.o trace-blk-hack.o \
- kbuffer-parse.o event-plugin.o trace-hooks.o
+ kbuffer-parse.o event-plugin.o trace-hooks.o \
+ trace-instance.o
PLUGIN_OBJS =
PLUGIN_OBJS += plugin_jbd2.o
diff --git a/trace-cmd.c b/trace-cmd.c
index 49d3559..f73d541 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -265,11 +265,12 @@ static void show_event_format_re(const char *re)
process_file_re(event_format_write, "available_events", re);
}
-void show_instance_file(struct buffer_instance *instance, const char *name)
+void show_instance_file(struct tracecmd_buffer_instance *instance,
+ const char *name)
{
char *path;
- path = get_instance_file(instance, name);
+ path = tracecmd_get_instance_file(instance, name);
dump_file_content(path);
tracecmd_put_tracing_file(path);
}
@@ -499,7 +500,7 @@ int main (int argc, char **argv)
const char *buffer = NULL;
const char *file = "trace";
const char *cpu = NULL;
- struct buffer_instance *instance = &top_instance;
+ struct tracecmd_buffer_instance *instance = &top_instance;
char cpu_path[128];
char *path;
int snap = 0;
@@ -532,7 +533,7 @@ int main (int argc, char **argv)
if (buffer)
die("Can only show one buffer at a time");
buffer = optarg;
- instance = create_instance(optarg);
+ instance = tracecmd_create_instance(optarg);
break;
case 'c':
if (cpu)
diff --git a/trace-cmd.h b/trace-cmd.h
index 2e59b46..6908b8b 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -296,20 +296,20 @@ void tracecmd_ftrace_load_options(void);
/* event hooks */
struct hook_list {
- struct hook_list *next;
- struct buffer_instance *instance;
- const char *hook;
- char *str;
- char *start_system;
- char *start_event;
- char *start_match;
- char *end_system;
- char *end_event;
- char *end_match;
- char *pid;
- int migrate;
- int global;
- int stack;
+ struct hook_list *next;
+ struct tracecmd_buffer_instance *instance;
+ const char *hook;
+ char *str;
+ char *start_system;
+ char *start_event;
+ char *start_match;
+ char *end_system;
+ char *end_event;
+ char *end_match;
+ char *pid;
+ int migrate;
+ int global;
+ int stack;
};
struct hook_list *tracecmd_create_event_hook(const char *arg);
@@ -327,4 +327,78 @@ void *tracecmd_record_page(struct tracecmd_input *handle,
void *tracecmd_record_offset(struct tracecmd_input *handle,
struct pevent_record *record);
+/* --- instance manipulation --- */
+
+struct tracecmd_func_list {
+ struct tracecmd_func_list *next;
+ const char *func;
+};
+
+struct tracecmd_buffer_instance {
+ struct tracecmd_buffer_instance *next;
+ const char *name;
+ const char *cpumask;
+ struct event_list *events;
+ struct event_list **event_next;
+
+ struct event_list *sched_switch_event;
+ struct event_list *sched_wakeup_event;
+ struct event_list *sched_wakeup_new_event;
+
+ const char *plugin;
+ struct tracecmd_func_list *filter_funcs;
+ struct tracecmd_func_list *notrace_funcs;
+
+ const char *clock;
+
+ struct trace_seq *s_save;
+ struct trace_seq *s_print;
+
+ struct tracecmd_input *handle;
+
+ int tracing_on_init_val;
+ int tracing_on_fd;
+ int keep;
+ int buffer_size;
+ int profile;
+};
+
+static struct tracecmd_buffer_instance top_instance = { .keep = 1 };
+static struct tracecmd_buffer_instance *buffer_instances;
+static struct tracecmd_buffer_instance *first_instance;
+
+#define for_each_instance(i) for (i = buffer_instances; i; i = (i)->next)
+#define for_all_instances(i) for (i = first_instance; i; \
+ i = i == &top_instance ? buffer_instances : (i)->next)
+
+struct tracecmd_buffer_instance *tracecmd_create_instance(const char *name);
+void tracecmd_init_instance(struct tracecmd_buffer_instance *instance);
+void tracecmd_add_instance(struct tracecmd_buffer_instance *instance);
+char *tracecmd_get_instance_file(struct tracecmd_buffer_instance *instance,
+ const char *file);
+char *
+tracecmd_get_instance_dir(struct tracecmd_buffer_instance *instance);
+int tracecmd_num_instances(void);
+void tracecmd_make_instances(void);
+void tracecmd_remove_instances(void);
+static inline int
+tracecmd_is_top_instance(struct tracecmd_buffer_instance *instance)
+{
+ return instance == &top_instance;
+}
+static inline int tracecmd_no_top_instance(void)
+{
+ return first_instance != &top_instance;
+}
+static inline void
+tracecmd_update_first_instance(struct tracecmd_buffer_instance *instance,
+ int topt)
+{
+ if (topt || instance == &top_instance)
+ first_instance = &top_instance;
+ else
+ first_instance = buffer_instances;
+}
+
+
#endif /* _TRACE_CMD_H */
diff --git a/trace-instance.c b/trace-instance.c
new file mode 100644
index 0000000..a5a1cb3
--- /dev/null
+++ b/trace-instance.c
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2015, Josef Bacik <[email protected]>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "trace-local.h"
+
+static int buffers = 1;
+
+/**
+ * tracecmd_init_instance - init the buffer instance.
+ * @instance: the buffer instance to initialize.
+ */
+void tracecmd_init_instance(struct tracecmd_buffer_instance *instance)
+{
+ instance->event_next = &instance->events;
+}
+
+/**
+ * create_instance - allocate a new buffer instance
+ * @name: The name of the instance (instance will point to this)
+ *
+ * Returns a newly allocated instance. Note that @name will not be
+ * copied, and the instance buffer will point to the string itself.
+ */
+struct tracecmd_buffer_instance *tracecmd_create_instance(const char *name)
+{
+ struct tracecmd_buffer_instance *instance;
+
+ instance = malloc_or_die(sizeof(*instance));
+ memset(instance, 0, sizeof(*instance));
+ instance->name = name;
+
+ return instance;
+}
+
+/**
+ * tracecmd_add_instance - add a buffer instance to the internal list
+ * @instance: The buffer instance to add
+ */
+void tracecmd_add_instance(struct tracecmd_buffer_instance *instance)
+{
+ tracecmd_init_instance(instance);
+ instance->next = buffer_instances;
+ if (first_instance == buffer_instances)
+ first_instance = instance;
+ buffer_instances = instance;
+ buffers++;
+}
+
+/**
+ * tracecmd_num_instances - the number of instances.
+ */
+int tracecmd_num_instances(void)
+{
+ return buffers;
+}
+
+/**
+ * tracecmd_get_instance_file - return the path to a instance file.
+ * @instance: buffer instance for the file
+ * @file: name of file to return
+ *
+ * Returns the path name of the @file for the given @instance.
+ *
+ * Must use tracecmd_put_tracing_file() to free the returned string.
+ */
+char *
+tracecmd_get_instance_file(struct tracecmd_buffer_instance *instance,
+ const char *file)
+{
+ char *buf;
+ char *path;
+
+ if (instance->name) {
+ buf = malloc_or_die(strlen(instance->name) +
+ strlen(file) + strlen("instances//") + 1);
+ sprintf(buf, "instances/%s/%s", instance->name, file);
+
+ path = tracecmd_get_tracing_file(buf);
+ free(buf);
+ } else
+ path = tracecmd_get_tracing_file(file);
+
+ return path;
+}
+
+/**
+ * tracecmd_make_instances - create the instance directories.
+ */
+void tracecmd_make_instances(void)
+{
+ struct tracecmd_buffer_instance *instance;
+ struct stat st;
+ char *path;
+ int ret;
+
+ for_each_instance(instance) {
+ path = tracecmd_get_instance_dir(instance);
+ ret = stat(path, &st);
+ if (ret < 0) {
+ ret = mkdir(path, 0777);
+ if (ret < 0)
+ die("mkdir %s", path);
+ } else
+ /* Don't delete instances that already exist */
+ instance->keep = 1;
+ tracecmd_put_tracing_file(path);
+ }
+}
+
+/**
+ * tracecmd_get_instance_dir - get the path to the instance
+ * @instance: the instance we care about.
+ *
+ * Return a string of the path to the instance. Must call
+ * tracemcd_put_tracing_file() on the returned path.
+ */
+char *
+tracecmd_get_instance_dir(struct tracecmd_buffer_instance *instance)
+{
+ char *buf;
+ char *path;
+
+ /* only works for instances */
+ if (!instance->name)
+ return NULL;
+
+ buf = malloc_or_die(strlen(instance->name) +
+ strlen("instances/") + 1);
+ sprintf(buf, "instances/%s", instance->name);
+
+ path = tracecmd_get_tracing_file(buf);
+ free(buf);
+
+ return path;
+}
+
+/**
+ * tracecmd_remove_instances - remove the instance directories.
+ *
+ * Go through and close the associated fd's and remove the instance directories.
+ */
+void tracecmd_remove_instances(void)
+{
+ struct tracecmd_buffer_instance *instance;
+ char *path;
+ int ret;
+
+ for_each_instance(instance) {
+ /* Only delete what we created */
+ if (instance->keep)
+ continue;
+ if (instance->tracing_on_fd > 0) {
+ close(instance->tracing_on_fd);
+ instance->tracing_on_fd = 0;
+ }
+ path = tracecmd_get_instance_dir(instance);
+ ret = rmdir(path);
+ if (ret < 0)
+ die("rmdir %s", path);
+ tracecmd_put_tracing_file(path);
+ }
+}
diff --git a/trace-local.h b/trace-local.h
index a1596e7..d294b23 100644
--- a/trace-local.h
+++ b/trace-local.h
@@ -29,7 +29,7 @@
/* fix stupid glib guint64 typecasts and printf formats */
typedef unsigned long long u64;
-struct buffer_instance;
+struct tracecmd_buffer_instance;
/* for local shared information with trace-cmd executable */
@@ -39,13 +39,13 @@ extern int silence_warnings;
extern int show_status;
struct pid_record_data {
- int pid;
- int brass[2];
- int cpu;
- int closed;
- struct tracecmd_input *stream;
- struct buffer_instance *instance;
- struct pevent_record *record;
+ int pid;
+ int brass[2];
+ int cpu;
+ int closed;
+ struct tracecmd_input *stream;
+ struct tracecmd_buffer_instance *instance;
+ struct pevent_record *record;
};
void show_file(const char *name);
@@ -85,8 +85,8 @@ int trace_profile(void);
void trace_profile_set_merge_like_comms(void);
struct tracecmd_input *
-trace_stream_init(struct buffer_instance *instance, int cpu, int fd, int cpus,
- int profile, struct hook_list *hooks, int global);
+trace_stream_init(struct tracecmd_buffer_instance *instance, int cpu, int fd,
+ int cpus, int profile, struct hook_list *hooks, int global);
int trace_stream_read(struct pid_record_data *pids, int nr_pids, struct timeval *tv,
int profile);
@@ -134,56 +134,6 @@ char *get_file_content(const char *file);
char *strstrip(char *str);
-/* --- instance manipulation --- */
-
-struct func_list {
- struct func_list *next;
- const char *func;
-};
-
-struct buffer_instance {
- struct buffer_instance *next;
- const char *name;
- const char *cpumask;
- struct event_list *events;
- struct event_list **event_next;
-
- struct event_list *sched_switch_event;
- struct event_list *sched_wakeup_event;
- struct event_list *sched_wakeup_new_event;
-
- const char *plugin;
- struct func_list *filter_funcs;
- struct func_list *notrace_funcs;
-
- const char *clock;
-
- struct trace_seq *s_save;
- struct trace_seq *s_print;
-
- struct tracecmd_input *handle;
-
- int tracing_on_init_val;
- int tracing_on_fd;
- int keep;
- int buffer_size;
- int profile;
-};
-
-extern struct buffer_instance top_instance;
-extern struct buffer_instance *buffer_instances;
-extern struct buffer_instance *first_instance;
-
-#define for_each_instance(i) for (i = buffer_instances; i; i = (i)->next)
-#define for_all_instances(i) for (i = first_instance; i; \
- i = i == &top_instance ? buffer_instances : (i)->next)
-
-struct buffer_instance *create_instance(const char *name);
-void add_instance(struct buffer_instance *instance);
-char *get_instance_file(struct buffer_instance *instance, const char *file);
-void update_first_instance(struct buffer_instance *instance, int topt);
-
-void show_instance_file(struct buffer_instance *instance, const char *name);
int count_cpus(void);
#endif /* __TRACE_LOCAL_H */
diff --git a/trace-record.c b/trace-record.c
index 616e17b..4ab0783 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -85,7 +85,6 @@ static int sleep_time = 1000;
static int cpu_count;
static int recorder_threads;
static struct pid_record_data *pids;
-static int buffers;
/* Clear all function filters */
static int clear_function_filters;
@@ -113,7 +112,7 @@ static unsigned recorder_flags;
/* Try a few times to get an accurate date */
static int date2ts_tries = 5;
-static struct func_list *graph_funcs;
+static struct tracecmd_func_list *graph_funcs;
static int func_stack;
@@ -173,28 +172,10 @@ static struct reset_file *reset_files;
/* Triggers need to be cleared in a special way */
static struct reset_file *reset_triggers;
-struct buffer_instance top_instance = { .keep = 1 };
-struct buffer_instance *buffer_instances;
-struct buffer_instance *first_instance;
-
static struct tracecmd_recorder *recorder;
static int ignore_event_not_found = 0;
-static inline int is_top_instance(struct buffer_instance *instance)
-{
- return instance == &top_instance;
-}
-
-static inline int no_top_instance(void)
-{
- return first_instance != &top_instance;
-}
-
-static void init_instance(struct buffer_instance *instance)
-{
- instance->event_next = &instance->events;
-}
enum {
RESET_DEFAULT_PRIO = 0,
@@ -275,38 +256,6 @@ static void reset_save_file_cond(const char *file, int prio,
free(content);
}
-/**
- * add_instance - add a buffer instance to the internal list
- * @instance: The buffer instance to add
- */
-void add_instance(struct buffer_instance *instance)
-{
- init_instance(instance);
- instance->next = buffer_instances;
- if (first_instance == buffer_instances)
- first_instance = instance;
- buffer_instances = instance;
- buffers++;
-}
-
-/**
- * create_instance - allocate a new buffer instance
- * @name: The name of the instance (instance will point to this)
- *
- * Returns a newly allocated instance. Note that @name will not be
- * copied, and the instance buffer will point to the string itself.
- */
-struct buffer_instance *create_instance(const char *name)
-{
- struct buffer_instance *instance;
-
- instance = malloc_or_die(sizeof(*instance));
- memset(instance, 0, sizeof(*instance));
- instance->name = name;
-
- return instance;
-}
-
static int __add_all_instances(const char *tracing_dir)
{
struct dirent *dent;
@@ -337,7 +286,7 @@ static int __add_all_instances(const char *tracing_dir)
while ((dent = readdir(dir))) {
const char *name = strdup(dent->d_name);
char *instance_path;
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
if (strcmp(name, ".") == 0 ||
strcmp(name, "..") == 0)
@@ -351,8 +300,8 @@ static int __add_all_instances(const char *tracing_dir)
}
free(instance_path);
- instance = create_instance(name);
- add_instance(instance);
+ instance = tracecmd_create_instance(name);
+ tracecmd_add_instance(instance);
}
closedir(dir);
@@ -386,7 +335,7 @@ void add_all_instances(void)
* @cpu: the CPU to stat
*
*/
-void tracecmd_stat_cpu_instance(struct buffer_instance *instance,
+void tracecmd_stat_cpu_instance(struct tracecmd_buffer_instance *instance,
struct trace_seq *s, int cpu)
{
char buf[BUFSIZ];
@@ -400,7 +349,7 @@ void tracecmd_stat_cpu_instance(struct buffer_instance *instance,
return;
snprintf(file, 40, "per_cpu/cpu%d/stats", cpu);
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
free(file);
fd = open(path, O_RDONLY);
tracecmd_put_tracing_file(path);
@@ -424,20 +373,21 @@ void tracecmd_stat_cpu(struct trace_seq *s, int cpu)
tracecmd_stat_cpu_instance(&top_instance, s, cpu);
}
-static void add_event(struct buffer_instance *instance, struct event_list *event)
+static void add_event(struct tracecmd_buffer_instance *instance,
+ struct event_list *event)
{
*instance->event_next = event;
instance->event_next = &event->next;
event->next = NULL;
}
-static void reset_event_list(struct buffer_instance *instance)
+static void reset_event_list(struct tracecmd_buffer_instance *instance)
{
instance->events = NULL;
- init_instance(instance);
+ tracecmd_init_instance(instance);
}
-static char *get_temp_file(struct buffer_instance *instance, int cpu)
+static char *get_temp_file(struct tracecmd_buffer_instance *instance, int cpu)
{
const char *name = instance->name;
char *file = NULL;
@@ -461,7 +411,8 @@ static void put_temp_file(char *file)
free(file);
}
-static void delete_temp_file(struct buffer_instance *instance, int cpu)
+static void delete_temp_file(struct tracecmd_buffer_instance *instance,
+ int cpu)
{
const char *name = instance->name;
char file[MAX_PATH];
@@ -473,7 +424,8 @@ static void delete_temp_file(struct buffer_instance *instance, int cpu)
unlink(file);
}
-static int kill_thread_instance(int start, struct buffer_instance *instance)
+static int
+kill_thread_instance(int start, struct tracecmd_buffer_instance *instance)
{
int n = start;
int i;
@@ -494,7 +446,7 @@ static int kill_thread_instance(int start, struct buffer_instance *instance)
static void kill_threads(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
int i = 0;
if (!recorder_threads || !pids)
@@ -524,7 +476,8 @@ void die(const char *fmt, ...)
exit(ret);
}
-static int delete_thread_instance(int start, struct buffer_instance *instance)
+static int delete_thread_instance(int start,
+ struct tracecmd_buffer_instance *instance)
{
int n = start;
int i;
@@ -546,7 +499,7 @@ static int delete_thread_instance(int start, struct buffer_instance *instance)
static void delete_thread_data(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
int i = 0;
for_all_instances(instance)
@@ -555,7 +508,7 @@ static void delete_thread_data(void)
* Top instance temp files are still created even if it
* isn't used.
*/
- if (no_top_instance()) {
+ if (tracecmd_no_top_instance()) {
for (i = 0; i < cpu_count; i++)
delete_temp_file(&top_instance, i);
}
@@ -593,12 +546,12 @@ static void stop_threads(enum trace_type type)
}
}
-static int create_recorder(struct buffer_instance *instance, int cpu,
+static int create_recorder(struct tracecmd_buffer_instance *instance, int cpu,
enum trace_type type, int *brass);
static void flush_threads(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
long ret;
int i;
@@ -670,61 +623,14 @@ static int set_ftrace(int set, int use_proc)
return 0;
}
-/**
- * get_instance_file - return the path to a instance file.
- * @instance: buffer instance for the file
- * @file: name of file to return
- *
- * Returns the path name of the @file for the given @instance.
- *
- * Must use tracecmd_put_tracing_file() to free the returned string.
- */
-char *
-get_instance_file(struct buffer_instance *instance, const char *file)
-{
- char *buf;
- char *path;
- if (instance->name) {
- buf = malloc_or_die(strlen(instance->name) +
- strlen(file) + strlen("instances//") + 1);
- sprintf(buf, "instances/%s/%s", instance->name, file);
-
- path = tracecmd_get_tracing_file(buf);
- free(buf);
- } else
- path = tracecmd_get_tracing_file(file);
-
- return path;
-}
-
-static char *
-get_instance_dir(struct buffer_instance *instance)
-{
- char *buf;
- char *path;
-
- /* only works for instances */
- if (!instance->name)
- return NULL;
-
- buf = malloc_or_die(strlen(instance->name) +
- strlen("instances/") + 1);
- sprintf(buf, "instances/%s", instance->name);
-
- path = tracecmd_get_tracing_file(buf);
- free(buf);
-
- return path;
-}
-
-static void __clear_trace(struct buffer_instance *instance)
+static void __clear_trace(struct tracecmd_buffer_instance *instance)
{
FILE *fp;
char *path;
/* reset the trace */
- path = get_instance_file(instance, "trace");
+ path = tracecmd_get_instance_file(instance, "trace");
fp = fopen(path, "w");
if (!fp)
die("writing to '%s'", path);
@@ -735,7 +641,7 @@ static void __clear_trace(struct buffer_instance *instance)
static void clear_trace(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
__clear_trace(instance);
@@ -839,8 +745,8 @@ static void update_ftrace_pids(int reset)
}
}
-static void update_event_filters(struct buffer_instance *instance);
-static void update_pid_event_filters(struct buffer_instance *instance);
+static void update_event_filters(struct tracecmd_buffer_instance *instance);
+static void update_pid_event_filters(struct tracecmd_buffer_instance *instance);
static void enable_tracing(void);
/**
@@ -897,7 +803,7 @@ static char *make_pid_filter(char *curr_filter, const char *field)
static void update_task_filter(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
int pid = getpid();
if (filter_task)
@@ -971,7 +877,8 @@ static void append_sched_event(struct event_list *event, const char *field, int
event->pid_filter = append_pid_filter(event->pid_filter, field, pid);
}
-static void update_sched_events(struct buffer_instance *instance, int pid)
+static void
+update_sched_events(struct tracecmd_buffer_instance *instance, int pid)
{
/*
* Also make sure that the sched_switch to this pid
@@ -985,7 +892,7 @@ static void update_sched_events(struct buffer_instance *instance, int pid)
static void add_new_filter_pid(int pid)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
char buf[100];
add_filter_pid(pid);
@@ -1132,13 +1039,13 @@ static void run_cmd(enum trace_type type, int argc, char **argv)
}
static void
-set_plugin_instance(struct buffer_instance *instance, const char *name)
+set_plugin_instance(struct tracecmd_buffer_instance *instance, const char *name)
{
FILE *fp;
char *path;
char zero = '0';
- path = get_instance_file(instance, "current_tracer");
+ path = tracecmd_get_instance_file(instance, "current_tracer");
fp = fopen(path, "w");
if (!fp) {
/*
@@ -1162,7 +1069,7 @@ set_plugin_instance(struct buffer_instance *instance, const char *name)
/* Make sure func_stack_trace option is disabled */
/* First try instance file, then top level */
- path = get_instance_file(instance, "options/func_stack_trace");
+ path = tracecmd_get_instance_file(instance, "options/func_stack_trace");
fp = fopen(path, "w");
if (!fp) {
tracecmd_put_tracing_file(path);
@@ -1185,7 +1092,7 @@ set_plugin_instance(struct buffer_instance *instance, const char *name)
static void set_plugin(const char *name)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
set_plugin_instance(instance, name);
@@ -1221,9 +1128,11 @@ static int set_option(const char *option)
return 0;
}
-static char *read_instance_file(struct buffer_instance *instance, char *file, int *psize);
+static char *read_instance_file(struct tracecmd_buffer_instance *instance,
+ char *file, int *psize);
-static void disable_func_stack_trace_instance(struct buffer_instance *instance)
+static void
+disable_func_stack_trace_instance(struct tracecmd_buffer_instance *instance)
{
struct stat st;
char *content;
@@ -1232,7 +1141,7 @@ static void disable_func_stack_trace_instance(struct buffer_instance *instance)
int size;
int ret;
- path = get_instance_file(instance, "current_tracer");
+ path = tracecmd_get_instance_file(instance, "current_tracer");
ret = stat(path, &st);
tracecmd_put_tracing_file(path);
if (ret < 0)
@@ -1250,7 +1159,7 @@ static void disable_func_stack_trace_instance(struct buffer_instance *instance)
static void disable_func_stack_trace(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
disable_func_stack_trace_instance(instance);
@@ -1352,13 +1261,14 @@ static void set_options(void)
}
}
-static int trace_check_file_exists(struct buffer_instance *instance, char *file)
+static int trace_check_file_exists(struct tracecmd_buffer_instance *instance,
+ char *file)
{
struct stat st;
char *path;
int ret;
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
ret = stat(path, &st);
tracecmd_put_tracing_file(path);
@@ -1416,7 +1326,7 @@ static void old_update_events(const char *name, char update)
}
static void
-reset_events_instance(struct buffer_instance *instance)
+reset_events_instance(struct tracecmd_buffer_instance *instance)
{
glob_t globbuf;
char *path;
@@ -1427,14 +1337,14 @@ reset_events_instance(struct buffer_instance *instance)
if (use_old_event_method()) {
/* old way only had top instance */
- if (!is_top_instance(instance))
+ if (!tracecmd_is_top_instance(instance))
return;
old_update_events("all", '0');
return;
}
c = '0';
- path = get_instance_file(instance, "events/enable");
+ path = tracecmd_get_instance_file(instance, "events/enable");
fd = open(path, O_WRONLY);
if (fd < 0)
die("opening to '%s'", path);
@@ -1442,7 +1352,7 @@ reset_events_instance(struct buffer_instance *instance)
close(fd);
tracecmd_put_tracing_file(path);
- path = get_instance_file(instance, "events/*/filter");
+ path = tracecmd_get_instance_file(instance, "events/*/filter");
globbuf.gl_offs = 0;
ret = glob(path, 0, NULL, &globbuf);
tracecmd_put_tracing_file(path);
@@ -1462,7 +1372,7 @@ reset_events_instance(struct buffer_instance *instance)
static void reset_events(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
reset_events_instance(instance);
@@ -1494,13 +1404,13 @@ static int write_file(const char *file, const char *str, const char *type)
}
static int
-write_instance_file(struct buffer_instance *instance,
+write_instance_file(struct tracecmd_buffer_instance *instance,
const char *file, const char *str, const char *type)
{
char *path;
int ret;
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
ret = write_file(path, str, type);
tracecmd_put_tracing_file(path);
@@ -1735,7 +1645,7 @@ static void check_tracing_enabled(void)
write(fd, "1", 1);
}
-static int open_tracing_on(struct buffer_instance *instance)
+static int open_tracing_on(struct tracecmd_buffer_instance *instance)
{
int fd = instance->tracing_on_fd;
char *path;
@@ -1744,11 +1654,11 @@ static int open_tracing_on(struct buffer_instance *instance)
if (fd > 0)
return fd;
- path = get_instance_file(instance, "tracing_on");
+ path = tracecmd_get_instance_file(instance, "tracing_on");
fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) {
/* instances may not be created yet */
- if (is_top_instance(instance))
+ if (tracecmd_is_top_instance(instance))
die("opening '%s'", path);
return fd;
}
@@ -1758,7 +1668,7 @@ static int open_tracing_on(struct buffer_instance *instance)
return fd;
}
-static void write_tracing_on(struct buffer_instance *instance, int on)
+static void write_tracing_on(struct tracecmd_buffer_instance *instance, int on)
{
int ret;
int fd;
@@ -1776,7 +1686,7 @@ static void write_tracing_on(struct buffer_instance *instance, int on)
die("writing 'tracing_on'");
}
-static int read_tracing_on(struct buffer_instance *instance)
+static int read_tracing_on(struct tracecmd_buffer_instance *instance)
{
int fd;
char buf[10];
@@ -1797,7 +1707,7 @@ static int read_tracing_on(struct buffer_instance *instance)
static void enable_tracing(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
check_tracing_enabled();
@@ -1810,7 +1720,7 @@ static void enable_tracing(void)
static void disable_tracing(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
write_tracing_on(instance, 0);
@@ -1843,7 +1753,7 @@ update_sched_event(struct event_list *event, const char *field)
event->pid_filter = make_pid_filter(event->pid_filter, field);
}
-static void update_event_filters(struct buffer_instance *instance)
+static void update_event_filters(struct tracecmd_buffer_instance *instance)
{
struct event_list *event;
char *event_filter;
@@ -1905,7 +1815,7 @@ static void update_event_filters(struct buffer_instance *instance)
}
}
-static void update_pid_event_filters(struct buffer_instance *instance)
+static void update_pid_event_filters(struct tracecmd_buffer_instance *instance)
{
/*
* Also make sure that the sched_switch to this pid
@@ -1919,7 +1829,7 @@ static void update_pid_event_filters(struct buffer_instance *instance)
update_event_filters(instance);
}
-static void set_mask(struct buffer_instance *instance)
+static void set_mask(struct tracecmd_buffer_instance *instance)
{
const char *mask = instance->cpumask;
struct stat st;
@@ -1952,7 +1862,7 @@ static void set_mask(struct buffer_instance *instance)
mask = cpumask;
}
- path = get_instance_file(instance, "tracing_cpumask");
+ path = tracecmd_get_instance_file(instance, "tracing_cpumask");
if (!path)
die("could not allocate path");
@@ -1975,7 +1885,7 @@ static void set_mask(struct buffer_instance *instance)
tracecmd_put_tracing_file(path);
}
-static void enable_events(struct buffer_instance *instance)
+static void enable_events(struct tracecmd_buffer_instance *instance)
{
struct event_list *event;
@@ -1991,7 +1901,7 @@ static void enable_events(struct buffer_instance *instance)
}
}
-static void set_clock(struct buffer_instance *instance)
+static void set_clock(struct tracecmd_buffer_instance *instance)
{
char *path;
char *content;
@@ -2012,7 +1922,7 @@ static void set_clock(struct buffer_instance *instance)
die("Can not find clock in trace_clock");
str = strtok(NULL, "]");
}
- path = get_instance_file(instance, "trace_clock");
+ path = tracecmd_get_instance_file(instance, "trace_clock");
add_reset_file(path, str, RESET_DEFAULT_PRIO);
free(content);
@@ -2022,7 +1932,8 @@ static void set_clock(struct buffer_instance *instance)
}
static struct event_list *
-create_event(struct buffer_instance *instance, char *path, struct event_list *old_event)
+create_event(struct tracecmd_buffer_instance *instance, char *path,
+ struct event_list *old_event)
{
struct event_list *event;
struct stat st;
@@ -2062,7 +1973,7 @@ create_event(struct buffer_instance *instance, char *path, struct event_list *ol
return event;
}
-static void make_sched_event(struct buffer_instance *instance,
+static void make_sched_event(struct tracecmd_buffer_instance *instance,
struct event_list **event, struct event_list *sched,
const char *sched_path)
{
@@ -2096,7 +2007,7 @@ static void test_event(struct event_list *event, const char *path,
*save = event;
}
-static int expand_event_files(struct buffer_instance *instance,
+static int expand_event_files(struct tracecmd_buffer_instance *instance,
const char *file, struct event_list *old_event)
{
struct event_list **save_event_tail = instance->event_next;
@@ -2111,7 +2022,7 @@ static int expand_event_files(struct buffer_instance *instance,
p = malloc_or_die(strlen(file) + strlen("events//filter") + 1);
sprintf(p, "events/%s/filter", file);
- path = get_instance_file(instance, p);
+ path = tracecmd_get_instance_file(instance, p);
globbuf.gl_offs = 0;
ret = glob(path, 0, NULL, &globbuf);
@@ -2155,7 +2066,8 @@ static int expand_event_files(struct buffer_instance *instance,
return save_event_tail == instance->event_next;
}
-static void expand_event(struct buffer_instance *instance, struct event_list *event)
+static void expand_event(struct tracecmd_buffer_instance *instance,
+ struct event_list *event)
{
const char *name = event->event;
char *str;
@@ -2206,7 +2118,7 @@ static void expand_event(struct buffer_instance *instance, struct event_list *ev
die("No events enabled with %s", name);
}
-static void expand_event_instance(struct buffer_instance *instance)
+static void expand_event_instance(struct tracecmd_buffer_instance *instance)
{
struct event_list *compressed_list = instance->events;
struct event_list *event;
@@ -2223,7 +2135,7 @@ static void expand_event_instance(struct buffer_instance *instance)
static void expand_event_list(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
if (use_old_event_method())
return;
@@ -2334,7 +2246,7 @@ static void set_prio(int prio)
}
static struct tracecmd_recorder *
-create_recorder_instance_pipe(struct buffer_instance *instance,
+create_recorder_instance_pipe(struct tracecmd_buffer_instance *instance,
int cpu, int *brass)
{
struct tracecmd_recorder *recorder;
@@ -2342,7 +2254,7 @@ create_recorder_instance_pipe(struct buffer_instance *instance,
char *path;
if (instance->name)
- path = get_instance_dir(instance);
+ path = tracecmd_get_instance_dir(instance);
else
path = tracecmd_find_tracing_dir();
@@ -2361,8 +2273,8 @@ create_recorder_instance_pipe(struct buffer_instance *instance,
}
static struct tracecmd_recorder *
-create_recorder_instance(struct buffer_instance *instance, const char *file, int cpu,
- int *brass)
+create_recorder_instance(struct tracecmd_buffer_instance *instance,
+ const char *file, int cpu, int *brass)
{
struct tracecmd_recorder *record;
char *path;
@@ -2373,7 +2285,7 @@ create_recorder_instance(struct buffer_instance *instance, const char *file, int
if (!instance->name)
return tracecmd_create_recorder_maxkb(file, cpu, recorder_flags, max_kb);
- path = get_instance_dir(instance);
+ path = tracecmd_get_instance_dir(instance);
record = tracecmd_create_buffer_recorder_maxkb(file, cpu, recorder_flags,
path, max_kb);
@@ -2386,7 +2298,7 @@ create_recorder_instance(struct buffer_instance *instance, const char *file, int
* If extract is set, then this is going to set up the recorder,
* connections and exit as the tracing is serialized by a single thread.
*/
-static int create_recorder(struct buffer_instance *instance, int cpu,
+static int create_recorder(struct tracecmd_buffer_instance *instance, int cpu,
enum trace_type type, int *brass)
{
long ret;
@@ -2573,7 +2485,7 @@ static void finish_network(void)
static void start_threads(enum trace_type type, int global)
{
int profile = (type & TRACE_TYPE_PROFILE) == TRACE_TYPE_PROFILE;
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
int *brass = NULL;
int i = 0;
int ret;
@@ -2582,9 +2494,11 @@ static void start_threads(enum trace_type type, int global)
setup_network();
/* make a thread for every CPU we have */
- pids = malloc_or_die(sizeof(*pids) * cpu_count * (buffers + 1));
+ pids = malloc_or_die(sizeof(*pids) * cpu_count *
+ (tracecmd_num_instances() + 1));
- memset(pids, 0, sizeof(*pids) * cpu_count * (buffers + 1));
+ memset(pids, 0, sizeof(*pids) * cpu_count *
+ (tracecmd_num_instances() + 1));
for_all_instances(instance) {
int x;
@@ -2616,7 +2530,7 @@ static void start_threads(enum trace_type type, int global)
static void append_buffer(struct tracecmd_output *handle,
struct tracecmd_option *buffer_option,
- struct buffer_instance *instance,
+ struct tracecmd_buffer_instance *instance,
char **temp_files)
{
int i;
@@ -2631,7 +2545,8 @@ static void append_buffer(struct tracecmd_output *handle,
}
static void
-add_buffer_stat(struct tracecmd_output *handle, struct buffer_instance *instance)
+add_buffer_stat(struct tracecmd_output *handle,
+ struct tracecmd_buffer_instance *instance)
{
struct trace_seq s;
int i;
@@ -2692,11 +2607,11 @@ static void touch_file(const char *file)
close(fd);
}
-static void print_stat(struct buffer_instance *instance)
+static void print_stat(struct tracecmd_buffer_instance *instance)
{
int cpu;
- if (!is_top_instance(instance))
+ if (!tracecmd_is_top_instance(instance))
printf("\nBuffer: %s\n\n", instance->name);
for (cpu = 0; cpu < cpu_count; cpu++)
@@ -2707,7 +2622,7 @@ static void record_data(char *date2ts)
{
struct tracecmd_option **buffer_options;
struct tracecmd_output *handle;
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
char **temp_files;
int i;
@@ -2731,7 +2646,7 @@ static void record_data(char *date2ts)
* If top_instance was not used, we still need to create
* empty trace.dat files for it.
*/
- if (no_top_instance()) {
+ if (tracecmd_no_top_instance()) {
for (i = 0; i < cpu_count; i++)
touch_file(temp_files[i]);
}
@@ -2745,7 +2660,7 @@ static void record_data(char *date2ts)
strlen(date2ts)+1, date2ts);
/* Only record the top instance under TRACECMD_OPTION_CPUSTAT*/
- if (!no_top_instance()) {
+ if (!tracecmd_no_top_instance()) {
struct trace_seq *s = top_instance.s_save;
for (i = 0; i < cpu_count; i++)
@@ -2760,8 +2675,9 @@ static void record_data(char *date2ts)
add_uname(handle);
- if (buffers) {
- buffer_options = malloc_or_die(sizeof(*buffer_options) * buffers);
+ if (tracecmd_num_instances()) {
+ buffer_options = malloc_or_die(sizeof(*buffer_options) *
+ tracecmd_num_instances());
i = 0;
for_each_instance(instance) {
buffer_options[i++] = tracecmd_add_buffer_option(handle, instance->name);
@@ -2769,7 +2685,7 @@ static void record_data(char *date2ts)
}
}
- if (!no_top_instance())
+ if (!tracecmd_no_top_instance())
print_stat(&top_instance);
tracecmd_append_cpu_data(handle, cpu_count, temp_files);
@@ -2777,7 +2693,7 @@ static void record_data(char *date2ts)
for (i = 0; i < cpu_count; i++)
put_temp_file(temp_files[i]);
- if (buffers) {
+ if (tracecmd_num_instances()) {
i = 0;
for_each_instance(instance) {
print_stat(instance);
@@ -2792,15 +2708,15 @@ static void record_data(char *date2ts)
tracecmd_output_close(handle);
}
-static void write_func_file(struct buffer_instance *instance,
- const char *file, struct func_list **list)
+static void write_func_file(struct tracecmd_buffer_instance *instance,
+ const char *file, struct tracecmd_func_list **list)
{
- struct func_list *item;
+ struct tracecmd_func_list *item;
char *path;
int fd;
int ret;
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
fd = open(path, O_WRONLY | O_TRUNC);
if (fd < 0)
@@ -2829,17 +2745,17 @@ static void write_func_file(struct buffer_instance *instance,
item->func, file, item->func);
}
-static int functions_filtered(struct buffer_instance *instance)
+static int functions_filtered(struct tracecmd_buffer_instance *instance)
{
char buf[1] = { '#' };
char *path;
int fd;
- path = get_instance_file(instance, "set_ftrace_filter");
+ path = tracecmd_get_instance_file(instance, "set_ftrace_filter");
fd = open(path, O_RDONLY);
tracecmd_put_tracing_file(path);
if (fd < 0) {
- if (is_top_instance(instance))
+ if (tracecmd_is_top_instance(instance))
warning("Can not set set_ftrace_filter");
else
warning("Can not set set_ftrace_filter for %s",
@@ -2859,16 +2775,16 @@ static int functions_filtered(struct buffer_instance *instance)
return 1;
}
-static void set_funcs(struct buffer_instance *instance)
+static void set_funcs(struct tracecmd_buffer_instance *instance)
{
write_func_file(instance, "set_ftrace_filter", &instance->filter_funcs);
write_func_file(instance, "set_ftrace_notrace", &instance->notrace_funcs);
/* graph tracing currently only works for top instance */
- if (is_top_instance(instance))
+ if (tracecmd_is_top_instance(instance))
write_func_file(instance, "set_graph_function", &graph_funcs);
/* make sure we are filtering functions */
- if (func_stack && is_top_instance(instance)) {
+ if (func_stack && tracecmd_is_top_instance(instance)) {
if (!functions_filtered(instance))
die("Function stack trace set, but functions not filtered");
save_option(FUNC_STACK_TRACE);
@@ -2876,9 +2792,9 @@ static void set_funcs(struct buffer_instance *instance)
clear_function_filters = 1;
}
-static void add_func(struct func_list **list, const char *func)
+static void add_func(struct tracecmd_func_list **list, const char *func)
{
- struct func_list *item;
+ struct tracecmd_func_list *item;
item = malloc_or_die(sizeof(*item));
item->func = func;
@@ -2973,7 +2889,8 @@ static unsigned long long find_time_stamp(struct pevent *pevent)
return ts;
}
-static char *read_instance_file(struct buffer_instance *instance, char *file, int *psize)
+static char *read_instance_file(struct tracecmd_buffer_instance *instance,
+ char *file, int *psize)
{
char buffer[BUFSIZ];
char *path;
@@ -2982,7 +2899,7 @@ static char *read_instance_file(struct buffer_instance *instance, char *file, in
int fd;
int r;
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
fd = open(path, O_RDONLY);
tracecmd_put_tracing_file(path);
if (fd < 0) {
@@ -3124,7 +3041,7 @@ static char *get_date_to_ts(void)
return date2ts;
}
-static void set_buffer_size_instance(struct buffer_instance *instance)
+static void set_buffer_size_instance(struct tracecmd_buffer_instance *instance)
{
int buffer_size = instance->buffer_size;
char buf[BUFSIZ];
@@ -3140,7 +3057,7 @@ static void set_buffer_size_instance(struct buffer_instance *instance)
snprintf(buf, BUFSIZ, "%d", buffer_size);
- path = get_instance_file(instance, "buffer_size_kb");
+ path = tracecmd_get_instance_file(instance, "buffer_size_kb");
fd = open(path, O_WRONLY);
if (fd < 0) {
warning("can't open %s", path);
@@ -3157,7 +3074,7 @@ static void set_buffer_size_instance(struct buffer_instance *instance)
void set_buffer_size(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
set_buffer_size_instance(instance);
@@ -3193,7 +3110,7 @@ process_event_trigger(char *path, struct event_iter *iter, enum event_process *p
free(file);
}
-static void clear_instance_triggers(struct buffer_instance *instance)
+static void clear_instance_triggers(struct tracecmd_buffer_instance *instance)
{
struct event_iter *iter;
char *path;
@@ -3201,7 +3118,7 @@ static void clear_instance_triggers(struct buffer_instance *instance)
enum event_iter_type type;
enum event_process processed = PROCESSED_NONE;
- path = get_instance_file(instance, "events");
+ path = tracecmd_get_instance_file(instance, "events");
if (!path)
die("malloc");
@@ -3254,7 +3171,7 @@ process_event_filter(char *path, struct event_iter *iter, enum event_process *pr
free(file);
}
-static void clear_instance_filters(struct buffer_instance *instance)
+static void clear_instance_filters(struct tracecmd_buffer_instance *instance)
{
struct event_iter *iter;
char *path;
@@ -3262,7 +3179,7 @@ static void clear_instance_filters(struct buffer_instance *instance)
enum event_iter_type type;
enum event_process processed = PROCESSED_NONE;
- path = get_instance_file(instance, "events");
+ path = tracecmd_get_instance_file(instance, "events");
if (!path)
die("malloc");
@@ -3287,7 +3204,7 @@ static void clear_instance_filters(struct buffer_instance *instance)
static void clear_filters(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
clear_instance_filters(instance);
@@ -3295,7 +3212,7 @@ static void clear_filters(void)
static void clear_triggers(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
clear_instance_triggers(instance);
@@ -3303,7 +3220,7 @@ static void clear_triggers(void)
static void clear_func_filters(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
char *path;
int i;
const char const *files[] = { "set_ftrace_filter",
@@ -3314,55 +3231,13 @@ static void clear_func_filters(void)
for_all_instances(instance) {
for (i = 0; files[i]; i++) {
- path = get_instance_file(instance, files[i]);
+ path = tracecmd_get_instance_file(instance, files[i]);
clear_func_filter(path);
tracecmd_put_tracing_file(path);
}
}
}
-static void make_instances(void)
-{
- struct buffer_instance *instance;
- struct stat st;
- char *path;
- int ret;
-
- for_each_instance(instance) {
- path = get_instance_dir(instance);
- ret = stat(path, &st);
- if (ret < 0) {
- ret = mkdir(path, 0777);
- if (ret < 0)
- die("mkdir %s", path);
- } else
- /* Don't delete instances that already exist */
- instance->keep = 1;
- tracecmd_put_tracing_file(path);
- }
-}
-
-static void remove_instances(void)
-{
- struct buffer_instance *instance;
- char *path;
- int ret;
-
- for_each_instance(instance) {
- /* Only delete what we created */
- if (instance->keep)
- continue;
- if (instance->tracing_on_fd > 0) {
- close(instance->tracing_on_fd);
- instance->tracing_on_fd = 0;
- }
- path = get_instance_dir(instance);
- ret = rmdir(path);
- if (ret < 0)
- die("rmdir %s", path);
- tracecmd_put_tracing_file(path);
- }
-}
static void check_plugin(const char *plugin)
{
@@ -3398,7 +3273,7 @@ static void check_function_plugin(void)
const char *plugin;
/* We only care about the top_instance */
- if (no_top_instance())
+ if (tracecmd_no_top_instance())
return;
plugin = top_instance.plugin;
@@ -3410,14 +3285,14 @@ static void check_function_plugin(void)
die("Must supply function filtering with --func-stack\n");
}
-static int __check_doing_something(struct buffer_instance *instance)
+static int __check_doing_something(struct tracecmd_buffer_instance *instance)
{
return instance->profile || instance->plugin || instance->events;
}
static void check_doing_something(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance) {
if (__check_doing_something(instance))
@@ -3428,7 +3303,7 @@ static void check_doing_something(void)
}
static void
-update_plugin_instance(struct buffer_instance *instance,
+update_plugin_instance(struct tracecmd_buffer_instance *instance,
enum trace_type type)
{
const char *plugin = instance->plugin;
@@ -3467,7 +3342,7 @@ update_plugin_instance(struct buffer_instance *instance,
static void update_plugins(enum trace_type type)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
update_plugin_instance(instance, type);
@@ -3475,7 +3350,7 @@ static void update_plugins(enum trace_type type)
static void allocate_seq(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance) {
instance->s_save = malloc_or_die(sizeof(struct trace_seq) * cpu_count);
@@ -3524,7 +3399,7 @@ static void add_overrun(int cpu, struct trace_seq *src, struct trace_seq *dst)
static void record_stats(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
struct trace_seq *s_save;
struct trace_seq *s_print;
int cpu;
@@ -3544,7 +3419,7 @@ static void record_stats(void)
static void print_stats(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
for_all_instances(instance)
print_stat(instance);
@@ -3552,7 +3427,7 @@ static void print_stats(void)
static void destroy_stats(void)
{
- struct buffer_instance *instance;
+ struct tracecmd_buffer_instance *instance;
int cpu;
for_all_instances(instance) {
@@ -3609,13 +3484,13 @@ static void add_trigger(struct event_list *event, const char *trigger)
}
}
-static int test_stacktrace_trigger(struct buffer_instance *instance)
+static int test_stacktrace_trigger(struct tracecmd_buffer_instance *instance)
{
char *path;
int ret = 0;
int fd;
- path = get_instance_file(instance, "events/sched/sched_switch/trigger");
+ path = tracecmd_get_instance_file(instance, "events/sched/sched_switch/trigger");
clear_trigger(path);
@@ -3636,7 +3511,7 @@ static int test_stacktrace_trigger(struct buffer_instance *instance)
}
static int
-profile_add_event(struct buffer_instance *instance, const char *event_str, int stack)
+profile_add_event(struct tracecmd_buffer_instance *instance, const char *event_str, int stack)
{
struct event_list *event;
char buf[BUFSIZ];
@@ -3680,7 +3555,7 @@ profile_add_event(struct buffer_instance *instance, const char *event_str, int s
return 0;
}
-static void enable_profile(struct buffer_instance *instance)
+static void enable_profile(struct tracecmd_buffer_instance *instance)
{
int stacktrace = 0;
int ret;
@@ -3733,7 +3608,7 @@ static void enable_profile(struct buffer_instance *instance)
}
static struct event_list *
-create_hook_event(struct buffer_instance *instance,
+create_hook_event(struct tracecmd_buffer_instance *instance,
const char *system, const char *event)
{
struct event_list *event_list;
@@ -3759,7 +3634,7 @@ create_hook_event(struct buffer_instance *instance,
return event_list;
}
-static void add_hook(struct buffer_instance *instance, const char *arg)
+static void add_hook(struct tracecmd_buffer_instance *instance, const char *arg)
{
struct event_list *event;
struct hook_list *hook;
@@ -3780,14 +3655,6 @@ static void add_hook(struct buffer_instance *instance, const char *arg)
}
}
-void update_first_instance(struct buffer_instance *instance, int topt)
-{
- if (topt || instance == &top_instance)
- first_instance = &top_instance;
- else
- first_instance = buffer_instances;
-}
-
enum {
OPT_bycomm = 250,
OPT_stderr = 251,
@@ -3804,7 +3671,7 @@ void trace_record (int argc, char **argv)
const char *option;
struct event_list *event = NULL;
struct event_list *last_event;
- struct buffer_instance *instance = &top_instance;
+ struct tracecmd_buffer_instance *instance = &top_instance;
enum trace_type type = 0;
char *pids;
char *pid;
@@ -3828,7 +3695,7 @@ void trace_record (int argc, char **argv)
int c;
- init_instance(instance);
+ tracecmd_init_instance(instance);
cpu_count = count_cpus();
@@ -3855,8 +3722,8 @@ void trace_record (int argc, char **argv)
usage(argv);
break;
case 'B':
- instance = create_instance(optarg);
- add_instance(instance);
+ instance = tracecmd_create_instance(optarg);
+ tracecmd_add_instance(instance);
break;
case 'a':
add_all_instances();
@@ -3871,7 +3738,7 @@ void trace_record (int argc, char **argv)
}
}
- update_first_instance(instance, topt);
+ tracecmd_update_first_instance(instance, topt);
disable_tracing();
exit(0);
} else if (strcmp(argv[1], "restart") == 0) {
@@ -3886,8 +3753,8 @@ void trace_record (int argc, char **argv)
usage(argv);
break;
case 'B':
- instance = create_instance(optarg);
- add_instance(instance);
+ instance = tracecmd_create_instance(optarg);
+ tracecmd_add_instance(instance);
break;
case 'a':
add_all_instances();
@@ -3902,13 +3769,13 @@ void trace_record (int argc, char **argv)
}
}
- update_first_instance(instance, topt);
+ tracecmd_update_first_instance(instance, topt);
enable_tracing();
exit(0);
} else if (strcmp(argv[1], "reset") == 0) {
/* if last arg is -a, then -b and -d apply to all instances */
int last_specified_all = 0;
- struct buffer_instance *inst; /* iterator */
+ struct tracecmd_buffer_instance *inst; /* iterator */
while ((c = getopt(argc-1, argv+1, "hab:B:td")) >= 0) {
@@ -3933,8 +3800,8 @@ void trace_record (int argc, char **argv)
}
case 'B':
last_specified_all = 0;
- instance = create_instance(optarg);
- add_instance(instance);
+ instance = tracecmd_create_instance(optarg);
+ tracecmd_add_instance(instance);
/* -d will remove keep */
instance->keep = 1;
break;
@@ -3957,19 +3824,19 @@ void trace_record (int argc, char **argv)
inst->keep = 0;
}
} else {
- if (is_top_instance(instance))
+ if (tracecmd_is_top_instance(instance))
die("Can not delete top level buffer");
instance->keep = 0;
}
break;
}
}
- update_first_instance(instance, topt);
+ tracecmd_update_first_instance(instance, topt);
disable_all(1);
set_buffer_size();
clear_filters();
clear_triggers();
- remove_instances();
+ tracecmd_remove_instances();
clear_func_filters();
exit(0);
} else
@@ -4189,8 +4056,8 @@ void trace_record (int argc, char **argv)
instance->buffer_size = atoi(optarg);
break;
case 'B':
- instance = create_instance(optarg);
- add_instance(instance);
+ instance = tracecmd_create_instance(optarg);
+ tracecmd_add_instance(instance);
if (profile)
instance->profile = 1;
break;
@@ -4260,7 +4127,7 @@ void trace_record (int argc, char **argv)
} else
topt = 1;
- update_first_instance(instance, topt);
+ tracecmd_update_first_instance(instance, topt);
if (!extract)
check_doing_something();
@@ -4270,7 +4137,7 @@ void trace_record (int argc, char **argv)
output_file = output;
if (!extract)
- make_instances();
+ tracecmd_make_instances();
/* Save the state of tracing_on before starting */
for_all_instances(instance) {
@@ -4402,7 +4269,7 @@ void trace_record (int argc, char **argv)
set_plugin("nop");
- remove_instances();
+ tracecmd_remove_instances();
/* If tracing_on was enabled before we started, set it on now */
for_all_instances(instance) {
diff --git a/trace-stat.c b/trace-stat.c
index 4d96b02..1add6a8 100644
--- a/trace-stat.c
+++ b/trace-stat.c
@@ -33,18 +33,13 @@
#define BUFSIZ 1024
#endif
-static inline int is_top_instance(struct buffer_instance *instance)
-{
- return instance == &top_instance;
-}
-
-static int get_instance_file_fd(struct buffer_instance *instance,
+static int get_instance_file_fd(struct tracecmd_buffer_instance *instance,
const char *file)
{
char *path;
int fd;
- path = get_instance_file(instance, file);
+ path = tracecmd_get_instance_file(instance, file);
fd = open(path, O_RDONLY);
tracecmd_put_tracing_file(path);
@@ -118,8 +113,9 @@ char *get_file_content(const char *file)
return str;
}
-static char *get_instance_file_content(struct buffer_instance *instance,
- const char *file)
+static char *
+get_instance_file_content(struct tracecmd_buffer_instance *instance,
+ const char *file)
{
char *str = NULL;
int fd;
@@ -134,7 +130,7 @@ static char *get_instance_file_content(struct buffer_instance *instance,
return str;
}
-static void report_plugin(struct buffer_instance *instance)
+static void report_plugin(struct tracecmd_buffer_instance *instance)
{
char *str;
char *cont;
@@ -326,7 +322,7 @@ process_event_enable(char *path, const char *system, const char *name,
free(file);
}
-static void report_events(struct buffer_instance *instance)
+static void report_events(struct tracecmd_buffer_instance *instance)
{
struct event_iter *iter;
char *str;
@@ -357,7 +353,7 @@ static void report_events(struct buffer_instance *instance)
free(str);
- path = get_instance_file(instance, "events");
+ path = tracecmd_get_instance_file(instance, "events");
if (!path)
die("malloc");
@@ -439,7 +435,7 @@ process_event_filter(char *path, struct event_iter *iter, enum event_process *pr
free(file);
}
-static void report_event_filters(struct buffer_instance *instance)
+static void report_event_filters(struct tracecmd_buffer_instance *instance)
{
struct event_iter *iter;
char *path;
@@ -447,7 +443,7 @@ static void report_event_filters(struct buffer_instance *instance)
enum event_iter_type type;
enum event_process processed = PROCESSED_NONE;
- path = get_instance_file(instance, "events");
+ path = tracecmd_get_instance_file(instance, "events");
if (!path)
die("malloc");
@@ -512,7 +508,7 @@ process_event_trigger(char *path, struct event_iter *iter, enum event_process *p
free(file);
}
-static void report_event_triggers(struct buffer_instance *instance)
+static void report_event_triggers(struct tracecmd_buffer_instance *instance)
{
struct event_iter *iter;
char *path;
@@ -520,7 +516,7 @@ static void report_event_triggers(struct buffer_instance *instance)
enum event_iter_type type;
enum event_process processed = PROCESSED_NONE;
- path = get_instance_file(instance, "events");
+ path = tracecmd_get_instance_file(instance, "events");
if (!path)
die("malloc");
@@ -605,11 +601,11 @@ static void list_functions(const char *path, char *string)
free(str);
}
-static void report_graph_funcs(struct buffer_instance *instance)
+static void report_graph_funcs(struct tracecmd_buffer_instance *instance)
{
char *path;
- path = get_instance_file(instance, "set_graph_function");
+ path = tracecmd_get_instance_file(instance, "set_graph_function");
if (!path)
die("malloc");
@@ -617,7 +613,7 @@ static void report_graph_funcs(struct buffer_instance *instance)
tracecmd_put_tracing_file(path);
- path = get_instance_file(instance, "set_graph_notrace");
+ path = tracecmd_get_instance_file(instance, "set_graph_notrace");
if (!path)
die("malloc");
@@ -626,11 +622,11 @@ static void report_graph_funcs(struct buffer_instance *instance)
tracecmd_put_tracing_file(path);
}
-static void report_ftrace_filters(struct buffer_instance *instance)
+static void report_ftrace_filters(struct tracecmd_buffer_instance *instance)
{
char *path;
- path = get_instance_file(instance, "set_ftrace_filter");
+ path = tracecmd_get_instance_file(instance, "set_ftrace_filter");
if (!path)
die("malloc");
@@ -638,7 +634,7 @@ static void report_ftrace_filters(struct buffer_instance *instance)
tracecmd_put_tracing_file(path);
- path = get_instance_file(instance, "set_ftrace_notrace");
+ path = tracecmd_get_instance_file(instance, "set_ftrace_notrace");
if (!path)
die("malloc");
@@ -647,7 +643,7 @@ static void report_ftrace_filters(struct buffer_instance *instance)
tracecmd_put_tracing_file(path);
}
-static void report_buffers(struct buffer_instance *instance)
+static void report_buffers(struct tracecmd_buffer_instance *instance)
{
#define FILE_SIZE 100
char *str;
@@ -702,7 +698,7 @@ static void report_buffers(struct buffer_instance *instance)
free(str);
}
-static void report_clock(struct buffer_instance *instance)
+static void report_clock(struct tracecmd_buffer_instance *instance)
{
char *str;
char *cont;
@@ -733,7 +729,7 @@ static void report_clock(struct buffer_instance *instance)
free(str);
}
-static void report_cpumask(struct buffer_instance *instance)
+static void report_cpumask(struct tracecmd_buffer_instance *instance)
{
char *str;
char *cont;
@@ -783,7 +779,7 @@ static void report_cpumask(struct buffer_instance *instance)
free(str);
}
-static void report_latency(struct buffer_instance *instance)
+static void report_latency(struct tracecmd_buffer_instance *instance)
{
char *str;
char *cont;
@@ -800,7 +796,7 @@ static void report_latency(struct buffer_instance *instance)
free(str);
}
-static void report_probes(struct buffer_instance *instance,
+static void report_probes(struct tracecmd_buffer_instance *instance,
const char *file, const char *string)
{
char *str;
@@ -833,17 +829,17 @@ static void report_probes(struct buffer_instance *instance,
free(str);
}
-static void report_kprobes(struct buffer_instance *instance)
+static void report_kprobes(struct tracecmd_buffer_instance *instance)
{
report_probes(instance, "kprobe_events", "Kprobe events");
}
-static void report_uprobes(struct buffer_instance *instance)
+static void report_uprobes(struct tracecmd_buffer_instance *instance)
{
report_probes(instance, "uprobe_events", "Uprobe events");
}
-static void report_traceon(struct buffer_instance *instance)
+static void report_traceon(struct tracecmd_buffer_instance *instance)
{
char *str;
char *cont;
@@ -863,7 +859,7 @@ static void report_traceon(struct buffer_instance *instance)
free(str);
}
-static void stat_instance(struct buffer_instance *instance)
+static void stat_instance(struct tracecmd_buffer_instance *instance)
{
if (instance != &top_instance) {
if (instance != first_instance)
@@ -888,7 +884,7 @@ static void stat_instance(struct buffer_instance *instance)
void trace_stat (int argc, char **argv)
{
- struct buffer_instance *instance = &top_instance;
+ struct tracecmd_buffer_instance *instance = &top_instance;
int topt = 0;
int c;
@@ -901,10 +897,10 @@ void trace_stat (int argc, char **argv)
usage(argv);
break;
case 'B':
- instance = create_instance(optarg);
- add_instance(instance);
+ instance = tracecmd_create_instance(optarg);
+ tracecmd_add_instance(instance);
/* top instance requires direct access */
- if (!topt && is_top_instance(first_instance))
+ if (!topt && tracecmd_is_top_instance(first_instance))
first_instance = instance;
break;
case 't':
@@ -917,7 +913,7 @@ void trace_stat (int argc, char **argv)
}
}
- update_first_instance(instance, topt);
+ tracecmd_update_first_instance(instance, topt);
for_all_instances(instance) {
stat_instance(instance);
diff --git a/trace-stream.c b/trace-stream.c
index 9ebe65b..924fb03 100644
--- a/trace-stream.c
+++ b/trace-stream.c
@@ -34,8 +34,8 @@
* it to create the pevent and handle.
*/
struct tracecmd_input *
-trace_stream_init(struct buffer_instance *instance, int cpu, int fd, int cpus,
- int profile, struct hook_list *hooks, int global)
+trace_stream_init(struct tracecmd_buffer_instance *instance, int cpu, int fd,
+ int cpus, int profile, struct hook_list *hooks, int global)
{
struct tracecmd_input *trace_input;
struct tracecmd_output *trace_output;
--
2.1.0