[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1448053053-24188-7-git-send-email-jbacik@fb.com>
Date: Fri, 20 Nov 2015 15:57:28 -0500
From: Josef Bacik <jbacik@...com>
To: <kernel-team@...com>, <linux-kernel@...r.kernel.org>,
<rostedt@...dmis.org>
Subject: [PATCH 06/11] trace-cmd: add helpers for starting and stopping threads
Starting and stopping the stream threads involves a lot of internal things to
tracecmd, so just expose the start and stop functions. Thanks,
Signed-off-by: Josef Bacik <jbacik@...com>
---
Makefile | 5 +++--
trace-cmd.h | 10 ++++++++++
trace-record.c | 41 ++++++++++++++++++-----------------------
3 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/Makefile b/Makefile
index 6b5bd29..7877b50 100644
--- a/Makefile
+++ b/Makefile
@@ -324,7 +324,7 @@ TRACE_GUI_OBJS = trace-filter.o trace-compat.o trace-filter-hash.o trace-dialog.
trace-xml.o
TRACE_CMD_OBJS = trace-cmd.o trace-record.o trace-read.o trace-split.o trace-listen.o \
trace-stack.o trace-hist.o trace-mem.o trace-snapshot.o trace-stat.o \
- trace-hash.o trace-profile.o trace-stream.o
+ trace-hash.o trace-profile.o
TRACE_VIEW_OBJS = trace-view.o trace-view-store.o
TRACE_GRAPH_OBJS = trace-graph.o trace-plot.o trace-plot-cpu.o trace-plot-task.o
TRACE_VIEW_MAIN_OBJS = trace-view-main.o $(TRACE_VIEW_OBJS) $(TRACE_GUI_OBJS)
@@ -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-stream.o
PLUGIN_OBJS =
PLUGIN_OBJS += plugin_jbd2.o
diff --git a/trace-cmd.h b/trace-cmd.h
index 7bf836f..d2e4f11 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -90,6 +90,13 @@ enum {
TRACECMD_OPTION_HOOK,
};
+enum tracecmd_trace_type {
+ TRACE_TYPE_RECORD = 1,
+ TRACE_TYPE_START = (1 << 1),
+ TRACE_TYPE_STREAM = (1 << 2),
+ TRACE_TYPE_EXTRACT = (1 << 3),
+};
+
enum {
TRACECMD_FL_IGNORE_DATE = (1 << 0),
TRACECMD_FL_BUFFER_INSTANCE = (1 << 1),
@@ -283,6 +290,9 @@ void tracecmd_enable_events(void);
void tracecmd_disable_all_tracing(int disable_tracer);
void tracecmd_disable_tracing(void);
void tracecmd_enable_tracing(void);
+void tracecmd_start_threads(enum tracecmd_trace_type type,
+ tracecmd_handle_init_func handle_init, int global);
+void tracecmd_stop_threads(enum tracecmd_trace_type type);
/* --- Plugin handling --- */
extern struct pevent_plugin_option trace_ftrace_options[];
diff --git a/trace-record.c b/trace-record.c
index f202d44..2bf7815 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -62,15 +62,6 @@
#define UDP_MAX_PACKET (65536 - 20)
-enum trace_type {
- TRACE_TYPE_RECORD = 1,
- TRACE_TYPE_START = (1 << 1),
- TRACE_TYPE_STREAM = (1 << 2),
- TRACE_TYPE_EXTRACT = (1 << 3),
-};
-
-static tracecmd_handle_init_func handle_init = NULL;
-
static int rt_prio;
static int use_tcp;
@@ -83,7 +74,7 @@ static const char *output_file = "trace.dat";
static int latency;
static int sleep_time = 1000;
-static int cpu_count;
+static int cpu_count = 0;
static int recorder_threads;
static struct pid_record_data *pids;
static int buffers;
@@ -562,7 +553,7 @@ static void delete_thread_data(void)
}
}
-static void stop_threads(enum trace_type type)
+void tracecmd_stop_threads(enum tracecmd_trace_type type)
{
struct timeval tv = { 0, 0 };
int ret;
@@ -594,7 +585,7 @@ static void stop_threads(enum trace_type type)
}
static int create_recorder(struct buffer_instance *instance, int cpu,
- enum trace_type type, int *brass);
+ enum tracecmd_trace_type type, int *brass);
static void flush_threads(void)
{
@@ -912,7 +903,7 @@ static void update_task_filter(void)
update_pid_event_filters(instance);
}
-static pid_t trace_waitpid(enum trace_type type, pid_t pid, int *status, int options)
+static pid_t trace_waitpid(enum tracecmd_trace_type type, pid_t pid, int *status, int options)
{
struct timeval tv = { 1, 0 };
int ret;
@@ -1019,7 +1010,7 @@ static void enable_ptrace(void)
ptrace(PTRACE_TRACEME, 0, NULL, 0);
}
-static void ptrace_wait(enum trace_type type, int main_pid)
+static void ptrace_wait(enum tracecmd_trace_type type, int main_pid)
{
unsigned long send_sig;
unsigned long child;
@@ -1081,7 +1072,7 @@ static inline void ptrace_attach(int pid) { }
#endif /* NO_PTRACE */
-static void trace_or_sleep(enum trace_type type)
+static void trace_or_sleep(enum tracecmd_trace_type type)
{
struct timeval tv = { 1 , 0 };
@@ -1093,7 +1084,7 @@ static void trace_or_sleep(enum trace_type type)
sleep(10);
}
-static void run_cmd(enum trace_type type, int argc, char **argv)
+static void run_cmd(enum tracecmd_trace_type type, int argc, char **argv)
{
int status;
int pid;
@@ -2389,7 +2380,7 @@ create_recorder_instance(struct buffer_instance *instance, const char *file, int
* connections and exit as the tracing is serialized by a single thread.
*/
static int create_recorder(struct buffer_instance *instance, int cpu,
- enum trace_type type, int *brass)
+ enum tracecmd_trace_type type, int *brass)
{
long ret;
char *file;
@@ -2572,7 +2563,8 @@ static void finish_network(void)
free(host);
}
-static void start_threads(enum trace_type type, int global)
+void tracecmd_start_threads(enum tracecmd_trace_type type,
+ tracecmd_handle_init_func handle_init, int global)
{
struct buffer_instance *instance;
int *brass = NULL;
@@ -2581,6 +2573,8 @@ static void start_threads(enum trace_type type, int global)
if (host)
setup_network();
+ if (!cpu_count)
+ cpu_count = count_cpus();
/* make a thread for every CPU we have */
pids = malloc_or_die(sizeof(*pids) * cpu_count * (buffers + 1));
@@ -3449,7 +3443,7 @@ static void check_doing_something(void)
static void
update_plugin_instance(struct buffer_instance *instance,
- enum trace_type type)
+ enum tracecmd_trace_type type)
{
const char *plugin = instance->plugin;
@@ -3485,7 +3479,7 @@ update_plugin_instance(struct buffer_instance *instance,
set_plugin_instance(instance, plugin);
}
-static void update_plugins(enum trace_type type)
+static void update_plugins(enum tracecmd_trace_type type)
{
struct buffer_instance *instance;
@@ -3830,7 +3824,8 @@ void trace_record (int argc, char **argv)
struct event_list *event = NULL;
struct event_list *last_event;
struct buffer_instance *instance = &top_instance;
- enum trace_type type = 0;
+ tracecmd_handle_init_func handle_init = NULL;
+ enum tracecmd_trace_type type = 0;
char *pids;
char *pid;
char *sav;
@@ -4362,7 +4357,7 @@ void trace_record (int argc, char **argv)
if (type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM)) {
signal(SIGINT, finish);
if (!latency)
- start_threads(type, global);
+ tracecmd_start_threads(type, handle_init, global);
}
if (extract) {
@@ -4391,7 +4386,7 @@ void trace_record (int argc, char **argv)
tracecmd_disable_tracing();
if (!latency)
- stop_threads(type);
+ tracecmd_stop_threads(type);
}
record_stats();
--
2.1.0
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists