From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v11 5/9] trace-cmd: Refactored few functions in trace-record.c
Date: Thu, 25 Apr 2019 14:05:27 +0300 [thread overview]
Message-ID: <20190425110531.8941-6-tstoyanov@vmware.com> (raw)
In-Reply-To: <20190425110531.8941-1-tstoyanov@vmware.com>
In order to reuse the code inside the trace-cmd application, few
functions from trace-record.c are refactored:
- make_instances() and tracecmd_remove_instances() are splited.
New ones are created: tracecmd_make_instance() and tracecmd_remove_instance(),
which are visible outside the trace-record.c
- Following functions are made non-static: tracecmd_init_instance()
get_instance_dir(), write_instance_file(), write_tracing_on(),
tracecmd_set_clock()
- New function is implemented: tracecmd_local_cpu_count(), an internal
API to get local_cpu_count.
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
tracecmd/include/trace-local.h | 9 ++++
tracecmd/trace-record.c | 88 +++++++++++++++++++---------------
2 files changed, 59 insertions(+), 38 deletions(-)
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 71b9249..554f1a3 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -235,6 +235,15 @@ 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);
+void write_tracing_on(struct buffer_instance *instance, int on);
+char *get_instance_dir(struct buffer_instance *instance);
+int write_instance_file(struct buffer_instance *instance,
+ const char *file, const char *str, const char *type);
+void tracecmd_init_instance(struct buffer_instance *instance);
+void tracecmd_make_instance(struct buffer_instance *instance);
+int tracecmd_local_cpu_count(void);
+void tracecmd_set_clock(struct buffer_instance *instance);
+void tracecmd_remove_instance(struct buffer_instance *instance);
/* No longer in event-utils.h */
void __noreturn die(const char *fmt, ...); /* Can be overriden */
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 29f5784..4a82773 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -185,7 +185,7 @@ static inline int no_top_instance(void)
return first_instance != &top_instance;
}
-static void init_instance(struct buffer_instance *instance)
+void tracecmd_init_instance(struct buffer_instance *instance)
{
instance->event_next = &instance->events;
}
@@ -309,7 +309,7 @@ static void reset_save_file_cond(const char *file, int prio,
*/
void add_instance(struct buffer_instance *instance, int cpu_count)
{
- init_instance(instance);
+ tracecmd_init_instance(instance);
instance->next = buffer_instances;
if (first_instance == buffer_instances)
first_instance = instance;
@@ -496,7 +496,7 @@ static void add_event(struct buffer_instance *instance, struct event_list *event
static void reset_event_list(struct buffer_instance *instance)
{
instance->events = NULL;
- init_instance(instance);
+ tracecmd_init_instance(instance);
}
static char *get_temp_file(struct buffer_instance *instance, int cpu)
@@ -792,8 +792,7 @@ get_instance_file(struct buffer_instance *instance, const char *file)
return path;
}
-static char *
-get_instance_dir(struct buffer_instance *instance)
+char *get_instance_dir(struct buffer_instance *instance)
{
char *buf;
char *path;
@@ -837,9 +836,8 @@ static int write_file(const char *file, const char *str, const char *type)
return ret;
}
-static int
-write_instance_file(struct buffer_instance *instance,
- const char *file, const char *str, const char *type)
+int write_instance_file(struct buffer_instance *instance,
+ const char *file, const char *str, const char *type)
{
char *path;
int ret;
@@ -1981,7 +1979,7 @@ static int open_tracing_on(struct buffer_instance *instance)
return fd;
}
-static void write_tracing_on(struct buffer_instance *instance, int on)
+void write_tracing_on(struct buffer_instance *instance, int on)
{
int ret;
int fd;
@@ -2305,7 +2303,7 @@ void tracecmd_enable_events(void)
enable_events(first_instance);
}
-static void set_clock(struct buffer_instance *instance)
+void tracecmd_set_clock(struct buffer_instance *instance)
{
char *path;
char *content;
@@ -4442,49 +4440,58 @@ static void clear_func_filters(void)
}
}
-static void make_instances(void)
+void tracecmd_make_instance(struct buffer_instance *instance)
{
- struct buffer_instance *instance;
struct stat st;
char *path;
int ret;
+ 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->flags |= BUFFER_FL_KEEP;
+ tracecmd_put_tracing_file(path);
+
+}
+
+static void make_instances(void)
+{
+ struct buffer_instance *instance;
+
for_each_instance(instance) {
if (is_guest(instance))
continue;
+ tracecmd_make_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->flags |= BUFFER_FL_KEEP;
- tracecmd_put_tracing_file(path);
+void tracecmd_remove_instance(struct buffer_instance *instance)
+{
+ char *path;
+
+ if (instance->tracing_on_fd > 0) {
+ close(instance->tracing_on_fd);
+ instance->tracing_on_fd = 0;
}
+ path = get_instance_dir(instance);
+ rmdir(path);
+ tracecmd_put_tracing_file(path);
}
void tracecmd_remove_instances(void)
{
struct buffer_instance *instance;
- char *path;
- int ret;
for_each_instance(instance) {
/* Only delete what we created */
if (is_guest(instance) || (instance->flags & BUFFER_FL_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);
+ tracecmd_remove_instance(instance);
}
}
@@ -4979,7 +4986,7 @@ void trace_stop(int argc, char **argv)
int topt = 0;
struct buffer_instance *instance = &top_instance;
- init_instance(instance);
+ tracecmd_init_instance(instance);
for (;;) {
int c;
@@ -5020,7 +5027,7 @@ void trace_restart(int argc, char **argv)
int topt = 0;
struct buffer_instance *instance = &top_instance;
- init_instance(instance);
+ tracecmd_init_instance(instance);
for (;;) {
int c;
@@ -5062,7 +5069,7 @@ void trace_reset(int argc, char **argv)
int topt = 0;
struct buffer_instance *instance = &top_instance;
- init_instance(instance);
+ tracecmd_init_instance(instance);
/* if last arg is -a, then -b and -d apply to all instances */
int last_specified_all = 0;
@@ -5146,11 +5153,16 @@ static void init_common_record_context(struct common_record_context *ctx,
memset(ctx, 0, sizeof(*ctx));
ctx->instance = &top_instance;
ctx->curr_cmd = curr_cmd;
- init_instance(ctx->instance);
+ tracecmd_init_instance(ctx->instance);
local_cpu_count = count_cpus();
ctx->instance->cpu_count = local_cpu_count;
}
+int tracecmd_local_cpu_count(void)
+{
+ return local_cpu_count;
+}
+
#define IS_EXTRACT(ctx) ((ctx)->curr_cmd == CMD_extract)
#define IS_START(ctx) ((ctx)->curr_cmd == CMD_start)
#define IS_STREAM(ctx) ((ctx)->curr_cmd == CMD_stream)
@@ -5728,7 +5740,7 @@ static void record_trace(int argc, char **argv,
tracecmd_disable_all_tracing(1);
for_all_instances(instance)
- set_clock(instance);
+ tracecmd_set_clock(instance);
/* Record records the date first */
if (ctx->date &&
--
2.20.1
next prev parent reply other threads:[~2019-04-25 11:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-25 11:05 [PATCH v11 0/9] trace-cmd: Timetamps sync between host and guest machines, relying on vsock events Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 1/9] trace-cmd: Implemented new lib API: tracecmd_local_events_system() Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 2/9] trace-cmd: Added support for negative time offsets in trace.dat file Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 3/9] trace-cmd: Fix tracecmd_read_page_record() to read more than one event Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 4/9] trace-cmd: Added implementation of htonll() and ntohll() Tzvetomir Stoyanov
2019-04-25 11:05 ` Tzvetomir Stoyanov [this message]
2019-04-25 11:05 ` [PATCH v11 6/9] trace-cmd: Find and store pids of tasks, which run virtual CPUs of given VM Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 7/9] trace-cmd: Implemented new API tracecmd_add_option_v() Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 8/9] trace-cmd: Implemented new option in trace.dat file: TRACECMD_OPTION_TIME_SHIFT Tzvetomir Stoyanov
2019-04-25 11:05 ` [PATCH v11 9/9] trace-cmd [POC]: Implemented timestamps synch algorithm, using vsock events Tzvetomir Stoyanov
2019-08-15 18:40 ` [PATCH v11 0/9] trace-cmd: Timetamps sync between host and guest machines, relying on " Steven Rostedt
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=20190425110531.8941-6-tstoyanov@vmware.com \
--to=tstoyanov@vmware.com \
--cc=linux-trace-devel@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;
as well as URLs for NNTP newsgroup(s).