From: Josef Bacik <jbacik@fb.com>
To: <kernel-team@fb.com>, <linux-kernel@vger.kernel.org>,
<rostedt@goodmis.org>
Subject: [PATCH 06/11] trace-cmd: add helpers for starting and stopping threads
Date: Fri, 20 Nov 2015 15:57:28 -0500 [thread overview]
Message-ID: <1448053053-24188-7-git-send-email-jbacik@fb.com> (raw)
In-Reply-To: <1448053053-24188-1-git-send-email-jbacik@fb.com>
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@fb.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
next prev parent reply other threads:[~2015-11-20 20:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 20:57 [PATCH 00/11] trace-cmd: make libtracecmd a linkable object Josef Bacik
2015-11-20 20:57 ` [PATCH 01/11] trace-cmd: add install_libs target to trace-cmd Josef Bacik
2015-11-20 20:57 ` [PATCH 02/11] trace-cmd: make libtracecmd a little more library friendly Josef Bacik
2015-11-20 20:57 ` [PATCH 03/11] trace-cmd: add a function to create a top instance Josef Bacik
2015-11-20 20:57 ` [PATCH 04/11] trace-cmd: add global functions for live tracing Josef Bacik
2019-07-09 13:09 ` Steven Rostedt
2019-07-09 13:56 ` Josef Bacik
2015-11-20 20:57 ` [PATCH 05/11] trace-cmd: allow for custom show and handle init Josef Bacik
2015-11-20 20:57 ` Josef Bacik [this message]
2015-11-20 20:57 ` [PATCH 07/11] trace-cmd: add trace-hash to libtracecmd Josef Bacik
2015-11-20 20:57 ` [PATCH 08/11] trace-cmd: add trace-stat and -ldl " Josef Bacik
2015-11-20 20:57 ` [PATCH 09/11] trace-cmd: disentangle profile and read from record Josef Bacik
2015-11-20 20:57 ` [PATCH 10/11] trace-cmd: add a helper function for stream polling Josef Bacik
2015-11-20 20:57 ` [PATCH 11/11] trace-cmd: add tracecmd_expand_event_list Josef Bacik
2016-11-21 17:13 ` [PATCH 00/11] trace-cmd: make libtracecmd a linkable object Steven Rostedt
2016-11-21 20:06 ` Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448053053-24188-7-git-send-email-jbacik@fb.com \
--to=jbacik@fb.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®