@@ -12,9 +12,9 @@ SYNOPSIS
--
*#include <trace-cmd.h>*
-struct tracecmd_input pass:[*]*tracecmd_open*(const char pass:[*]_file_);
-struct tracecmd_input pass:[*]*tracecmd_open_fd*(int _fd_);
-struct tracecmd_input pass:[*]*tracecmd_open_head*(const char pass:[*]_file_);
+struct tracecmd_input pass:[*]*tracecmd_open*(const char pass:[*]_file_, int _flags_);
+struct tracecmd_input pass:[*]*tracecmd_open_fd*(int _fd_, int _flags_);
+struct tracecmd_input pass:[*]*tracecmd_open_head*(const char pass:[*]_file_, int _flags_);
int *tracecmd_init_data*(struct tracecmd_input pass:[*]_handle_);
void *tracecmd_close*(struct tracecmd_input pass:[*]_handle_);
--
@@ -25,7 +25,13 @@ This set of APIs can be used to open and close a trace file recorded by
_trace-cmd(1)_ and containing tracing information from ftrace, the official
Linux kernel tracer. The opened file is represented by a _tracecmd_input_
structure, all other library APIs that work with the file require a pointer
-to the structure.
+to the structure. The APIs for opening a trace file have a _flag_ input
+parameter, which controls how the file will be opened and parsed. The _flag_
+is a combination of these options:
+
+ TRACECMD_FLAG_LOAD_NO_PLUGINS - Do not load any plugins
+ TRACECMD_FLAG_LOAD_NO_SYSTEM_PLUGINS - Do not load system wide plugins, load only "local only"
+ plugins from user's home directory.
The _tracecmd_open()_ function opens a given trace _file_, parses the
metadata headers from the file, allocates and initializes а _tracecmd_input_
@@ -12,7 +12,7 @@ SYNOPSIS
*#include <trace-cmd.h>*
Open and close trace file:
- struct tracecmd_input pass:[*]*tracecmd_open_head*(const char pass:[*]_file_);
+ struct tracecmd_input pass:[*]*tracecmd_open_head*(const char pass:[*]_file_, int _flags_);
void *tracecmd_close*(struct tracecmd_input pass:[*]_handle_);
Read tracing records from a trace file:
@@ -11,9 +11,14 @@
struct tracecmd_input;
-struct tracecmd_input *tracecmd_open_head(const char *file);
-struct tracecmd_input *tracecmd_open(const char *file);
-struct tracecmd_input *tracecmd_open_fd(int fd);
+enum tracecmd_open_flags {
+ TRACECMD_FLAG_LOAD_NO_PLUGINS = 1 << 0, /* Do not load plugins */
+ TRACECMD_FLAG_LOAD_NO_SYSTEM_PLUGINS = 1 << 1, /* Do not load system plugins */
+};
+struct tracecmd_input *tracecmd_open_head(const char *file, int flags);
+struct tracecmd_input *tracecmd_open(const char *file, int flags);
+struct tracecmd_input *tracecmd_open_fd(int fd, int flags);
+
void tracecmd_close(struct tracecmd_input *handle);
int tracecmd_pair_peer(struct tracecmd_input *handle,
struct tracecmd_input *peer);
@@ -141,7 +141,7 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)
kshark_free_task_list(kshark_ctx);
- handle = tracecmd_open_head(file);
+ handle = tracecmd_open_head(file, 0);
if (!handle)
return false;
@@ -25,7 +25,7 @@
void tracecmd_parse_cmdlines(struct tep_handle *pevent, char *file, int size);
void tracecmd_parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
void tracecmd_parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
-struct tep_plugin_list *trace_load_plugins(struct tep_handle *tep);
+struct tep_plugin_list *trace_load_plugins(struct tep_handle *tep, int flags);
int *tracecmd_add_id(int *list, int id, int len);
@@ -46,9 +46,6 @@ struct hook_list;
/* --- tracecmd plugins --- */
-extern int tracecmd_disable_sys_plugins;
-extern int tracecmd_disable_plugins;
-
enum tracecmd_context {
TRACECMD_INPUT,
TRACECMD_OUTPUT,
@@ -141,8 +138,8 @@ typedef void (*tracecmd_show_data_func)(struct tracecmd_input *handle,
typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
struct hook_list *hook, int global);
-struct tracecmd_input *tracecmd_alloc(const char *file);
-struct tracecmd_input *tracecmd_alloc_fd(int fd);
+struct tracecmd_input *tracecmd_alloc(const char *file, int flags);
+struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags);
void tracecmd_ref(struct tracecmd_input *handle);
int tracecmd_read_headers(struct tracecmd_input *handle);
int tracecmd_get_parsing_failures(struct tracecmd_input *handle);
@@ -2,6 +2,6 @@
int main()
{
- tracecmd_open_head("trace.dat");
+ tracecmd_open_head("trace.dat", 0);
return 0;
}
@@ -3076,6 +3076,7 @@ struct hook_list *tracecmd_hooks(struct tracecmd_input *handle)
/**
* tracecmd_alloc_fd - create a tracecmd_input handle from a file descriptor
* @fd: the file descriptor for the trace.dat file
+ * @flags: bitmask of enum tracecmd_open_flags
*
* Allocate a tracecmd_input handle from a file descriptor and open the
* file. This tests if the file is of trace-cmd format and allocates
@@ -3087,7 +3088,7 @@ struct hook_list *tracecmd_hooks(struct tracecmd_input *handle)
* Unless you know what you are doing with this, you want to use
* tracecmd_open_fd() instead.
*/
-struct tracecmd_input *tracecmd_alloc_fd(int fd)
+struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
{
struct tracecmd_input *handle;
char test[] = TRACECMD_MAGIC;
@@ -3128,9 +3129,11 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
goto failed_read;
/* register default ftrace functions first */
- tracecmd_ftrace_overrides(handle, &handle->finfo);
+ if (!(flags & TRACECMD_FLAG_LOAD_NO_PLUGINS) &&
+ !(flags & TRACECMD_FLAG_LOAD_NO_SYSTEM_PLUGINS))
+ tracecmd_ftrace_overrides(handle, &handle->finfo);
- handle->plugin_list = trace_load_plugins(handle->pevent);
+ handle->plugin_list = trace_load_plugins(handle->pevent, flags);
tep_set_file_bigendian(handle->pevent, buf[0]);
tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian());
@@ -3161,6 +3164,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
/**
* tracecmd_alloc_fd - create a tracecmd_input handle from a file name
* @file: the file name of the file that is of tracecmd data type.
+ * @flags: bitmask of enum tracecmd_open_flags
*
* Allocate a tracecmd_input handle from a given file name and open the
* file. This tests if the file is of trace-cmd format and allocates
@@ -3172,7 +3176,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
* Unless you know what you are doing with this, you want to use
* tracecmd_open() instead.
*/
-struct tracecmd_input *tracecmd_alloc(const char *file)
+struct tracecmd_input *tracecmd_alloc(const char *file, int flags)
{
int fd;
@@ -3180,19 +3184,20 @@ struct tracecmd_input *tracecmd_alloc(const char *file)
if (fd < 0)
return NULL;
- return tracecmd_alloc_fd(fd);
+ return tracecmd_alloc_fd(fd, flags);
}
/**
* tracecmd_open_fd - create a tracecmd_handle from the trace.dat file descriptor
* @fd: the file descriptor for the trace.dat file
+ * @flags: bitmask of enum tracecmd_open_flags
*/
-struct tracecmd_input *tracecmd_open_fd(int fd)
+struct tracecmd_input *tracecmd_open_fd(int fd, int flags)
{
struct tracecmd_input *handle;
int ret;
- handle = tracecmd_alloc_fd(fd);
+ handle = tracecmd_alloc_fd(fd, flags);
if (!handle)
return NULL;
@@ -3212,8 +3217,9 @@ fail:
/**
* tracecmd_open - create a tracecmd_handle from a given file
* @file: the file name of the file that is of tracecmd data type.
+ * @flags: bitmask of enum tracecmd_open_flags
*/
-struct tracecmd_input *tracecmd_open(const char *file)
+struct tracecmd_input *tracecmd_open(const char *file, int flags)
{
int fd;
@@ -3221,15 +3227,16 @@ struct tracecmd_input *tracecmd_open(const char *file)
if (fd < 0)
return NULL;
- return tracecmd_open_fd(fd);
+ return tracecmd_open_fd(fd, flags);
}
/**
* tracecmd_open_head - create a tracecmd_handle from a given file, read
* and parse only the trace headers from the file
* @file: the file name of the file that is of tracecmd data type.
+ * @flags: bitmask of enum tracecmd_open_flags
*/
-struct tracecmd_input *tracecmd_open_head(const char *file)
+struct tracecmd_input *tracecmd_open_head(const char *file, int flags)
{
struct tracecmd_input *handle;
int fd;
@@ -3238,7 +3245,7 @@ struct tracecmd_input *tracecmd_open_head(const char *file)
if (fd < 0)
return NULL;
- handle = tracecmd_alloc_fd(fd);
+ handle = tracecmd_alloc_fd(fd, flags);
if (!handle)
return NULL;
@@ -1417,7 +1417,7 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd)
return NULL;
/* get a input handle from this */
- ihandle = tracecmd_alloc_fd(fd2);
+ ihandle = tracecmd_alloc_fd(fd2, 0);
if (!ihandle)
return NULL;
@@ -27,8 +27,6 @@
#define LOCAL_PLUGIN_DIR ".trace-cmd/plugins"
#define PROC_STACK_FILE "/proc/sys/kernel/stack_tracer_enabled"
-int tracecmd_disable_sys_plugins;
-int tracecmd_disable_plugins;
static bool debug;
static FILE *logfp;
@@ -335,14 +333,14 @@ static char *get_source_plugins_dir(void)
}
struct tep_plugin_list*
-trace_load_plugins(struct tep_handle *tep)
+trace_load_plugins(struct tep_handle *tep, int flags)
{
struct tep_plugin_list *list;
char *path;
- if (tracecmd_disable_plugins)
+ if (flags & TRACECMD_FLAG_LOAD_NO_PLUGINS)
tep_set_flag(tep, TEP_DISABLE_PLUGINS);
- if (tracecmd_disable_sys_plugins)
+ if (flags & TRACECMD_FLAG_LOAD_NO_SYSTEM_PLUGINS)
tep_set_flag(tep, TEP_DISABLE_SYS_PLUGINS);
path = get_source_plugins_dir();
@@ -46,7 +46,7 @@ struct pid_record_data {
void show_file(const char *name);
-struct tracecmd_input *read_trace_header(const char *file);
+struct tracecmd_input *read_trace_header(const char *file, int flags);
int read_trace_files(void);
void trace_record(int argc, char **argv);
@@ -17,6 +17,7 @@ void trace_check_events(int argc, char **argv)
int parsing_failures = 0;
struct tep_handle *pevent = NULL;
struct tep_plugin_list *list = NULL;
+ int open_flags = 0;
while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) {
switch (c) {
@@ -25,7 +26,7 @@ void trace_check_events(int argc, char **argv)
usage(argv);
break;
case 'N':
- tracecmd_disable_plugins = 1;
+ open_flags |= TRACECMD_FLAG_LOAD_NO_PLUGINS;
break;
}
}
@@ -44,7 +45,7 @@ void trace_check_events(int argc, char **argv)
if (!pevent)
exit(EINVAL);
- list = trace_load_plugins(pevent);
+ list = trace_load_plugins(pevent, open_flags);
ret = tracefs_fill_local_events(tracing, pevent, &parsing_failures);
if (ret || parsing_failures)
ret = EINVAL;
@@ -1039,7 +1039,7 @@ void trace_hist(int argc, char **argv)
if (!input_file)
input_file = DEFAULT_INPUT_FILE;
- handle = tracecmd_alloc(input_file);
+ handle = tracecmd_alloc(input_file, 0);
if (!handle)
die("can't open %s\n", input_file);
@@ -357,7 +357,7 @@ static void show_plugin_options(void)
trace_seq_init(&s);
- list = trace_load_plugins(pevent);
+ list = trace_load_plugins(pevent, 0);
tep_plugin_print_options(&s);
trace_seq_do_printf(&s);
tep_unload_plugins(list, pevent);
@@ -383,7 +383,7 @@ static void show_plugins(void)
trace_seq_init(&s);
- list = trace_load_plugins(pevent);
+ list = trace_load_plugins(pevent, 0);
tep_print_plugins(&s, " ", "\n", list);
trace_seq_do_printf(&s);
@@ -550,7 +550,7 @@ void trace_mem(int argc, char **argv)
if (!input_file)
input_file = DEFAULT_INPUT_FILE;
- handle = tracecmd_alloc(input_file);
+ handle = tracecmd_alloc(input_file, 0);
if (!handle)
die("can't open %s\n", input_file);
@@ -1332,13 +1332,13 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
}
}
-struct tracecmd_input *read_trace_header(const char *file)
+struct tracecmd_input *read_trace_header(const char *file, int flags)
{
input_fd = open(file, O_RDONLY);
if (input_fd < 0)
die("opening '%s'\n", file);
- return tracecmd_alloc_fd(input_fd);
+ return tracecmd_alloc_fd(input_fd, flags);
}
static void sig_end(int sig)
@@ -1522,6 +1522,7 @@ void trace_report (int argc, char **argv)
long long tsoffset = 0;
unsigned long long ts2secs = 0;
unsigned long long ts2sc;
+ int open_flags = 0;
int show_stat = 0;
int show_funcs = 0;
int show_endian = 0;
@@ -1620,10 +1621,10 @@ void trace_report (int argc, char **argv)
show_printk = 1;
break;
case 'L':
- tracecmd_disable_sys_plugins = 1;
+ open_flags |= TRACECMD_FLAG_LOAD_NO_SYSTEM_PLUGINS;
break;
case 'N':
- tracecmd_disable_plugins = 1;
+ open_flags |= TRACECMD_FLAG_LOAD_NO_PLUGINS;
break;
case 'n':
*nohandler_ptr = malloc(sizeof(struct event_str));
@@ -1768,7 +1769,7 @@ void trace_report (int argc, char **argv)
die("Wakeup tracing can only be done on a single input file");
list_for_each_entry(inputs, &input_files, list) {
- handle = read_trace_header(inputs->file);
+ handle = read_trace_header(inputs->file, open_flags);
if (!handle)
die("error reading header for %s", inputs->file);
@@ -116,7 +116,7 @@ void trace_restore (int argc, char **argv)
if (input) {
struct tracecmd_input *ihandle;
- ihandle = tracecmd_alloc(input);
+ ihandle = tracecmd_alloc(input, 0);
if (!ihandle)
die("error reading file %s", input);
/* make sure headers are ok */
@@ -506,7 +506,7 @@ void trace_split (int argc, char **argv)
if (!input_file)
input_file = default_input_file;
- handle = tracecmd_open(input_file);
+ handle = tracecmd_open(input_file, 0);
if (!handle)
die("error reading %s", input_file);
@@ -53,7 +53,7 @@ trace_stream_init(struct buffer_instance *instance, int cpu, int fd, int cpus,
lseek(ofd, 0, SEEK_SET);
- trace_input = tracecmd_alloc_fd(ofd);
+ trace_input = tracecmd_alloc_fd(ofd, 0);
if (!trace_input) {
close(ofd);
goto fail;
Added a new flag parameter to these APIs, to control how the trace file is opened and parsed: tracecmd_open() tracecmd_open_fd() tracecmd_open_head() The first implemented flags control whether the plugins should be loaded and used when opening the file. These flags replace the global variables, used for the same purpose. Loading of ftrace function event plugins is also affected by these flags. These changes fix the bug reported by Douglas RAILLARD. Reported-by: Douglas RAILLARD <douglas.raillard@arm.com> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=211255 Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- .../libtracecmd/libtracecmd-files.3.txt | 14 ++++++--- Documentation/libtracecmd/libtracecmd.3.txt | 2 +- include/trace-cmd/trace-cmd.h | 11 +++++-- kernel-shark/src/libkshark.c | 2 +- .../include/private/trace-cmd-private.h | 9 ++---- lib/trace-cmd/test.c | 2 +- lib/trace-cmd/trace-input.c | 29 ++++++++++++------- lib/trace-cmd/trace-output.c | 2 +- lib/trace-cmd/trace-util.c | 8 ++--- tracecmd/include/trace-local.h | 2 +- tracecmd/trace-check-events.c | 5 ++-- tracecmd/trace-hist.c | 2 +- tracecmd/trace-list.c | 4 +-- tracecmd/trace-mem.c | 2 +- tracecmd/trace-read.c | 11 +++---- tracecmd/trace-restore.c | 2 +- tracecmd/trace-split.c | 2 +- tracecmd/trace-stream.c | 2 +- 18 files changed, 63 insertions(+), 48 deletions(-)