diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 07dfa56e..1e80cb6b 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -92,6 +92,10 @@ The category names currently supported are: Default value is "none". +* ftracedir : String. Mountpoint of tracefs. Defaults to +"/sys/kernel/debug/tracing" if not specified. Has no effect if ftrace is not +enabled. + * gnuplot : Boolean. If True, it will create a gnu plot compatible file for each threads (see gnuplot section for more details). Default value is False. diff --git a/src/rt-app.c b/src/rt-app.c index 673df444..d5cd3f04 100644 --- a/src/rt-app.c +++ b/src/rt-app.c @@ -64,7 +64,6 @@ static pthread_mutex_t joining_mutex; static pthread_mutex_t fork_mutex; static ftrace_data_t ft_data = { - .debugfs = "/sys/kernel/debug", .marker_fd = -1, }; @@ -1542,8 +1541,8 @@ int main(int argc, char* argv[]) if (ftrace_level != FTRACE_NONE) { log_notice("configuring ftrace"); // check if tracing is enabled - strcpy(tmp, ft_data.debugfs); - strcat(tmp, "/tracing/tracing_on"); + strcpy(tmp, opts.ftracedir); + strcat(tmp, "/tracing_on"); int ftrace_f = open(tmp, O_RDONLY); if (ftrace_f < 0){ log_error("Cannot open tracing_on file %s", tmp); @@ -1557,8 +1556,8 @@ int main(int argc, char* argv[]) } close(ftrace_f); // set the marker - strcpy(tmp, ft_data.debugfs); - strcat(tmp, "/tracing/trace_marker"); + strcpy(tmp, opts.ftracedir); + strcat(tmp, "/trace_marker"); ft_data.marker_fd = open(tmp, O_WRONLY); if (ft_data.marker_fd < 0) { log_error("Cannot open trace_marker file %s", tmp); diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 09dbd9b5..e10651ba 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -1207,6 +1207,7 @@ parse_global(struct json_object *global, rtapp_options_t *opts) opts->io_device = strdup("/dev/null"); opts->mem_buffer_size = DEFAULT_MEM_BUF_SIZE; opts->cumulative_slack = 0; + opts->ftracedir = ftrace_dir(); return; } @@ -1304,6 +1305,7 @@ parse_global(struct json_object *global, rtapp_options_t *opts) log_critical(PFX "Invalid ftrace categories"); exit(EXIT_INV_CONFIG); } + opts->ftracedir = get_string_value_from(global, "ftracedir", TRUE, ftrace_dir()); opts->lock_pages = get_bool_value_from(global, "lock_pages", TRUE, 1); opts->pi_enabled = get_bool_value_from(global, "pi_enabled", TRUE, 0); diff --git a/src/rt-app_types.h b/src/rt-app_types.h index bed8fa38..beacad2d 100644 --- a/src/rt-app_types.h +++ b/src/rt-app_types.h @@ -289,6 +289,8 @@ typedef struct _rtapp_options_t { char *io_device; int cumulative_slack; + + char *ftracedir; /* should end in 'tracing' */ } rtapp_options_t; typedef struct _timing_point_t { diff --git a/src/rt-app_utils.c b/src/rt-app_utils.c index b12855c3..63fb1885 100644 --- a/src/rt-app_utils.c +++ b/src/rt-app_utils.c @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include "rt-app_utils.h" @@ -267,6 +268,60 @@ resource_to_string(resource_t resource, char *resource_name) return 0; } +/* point directly to the tracing directory */ +#define DEFAULT_FTRACE_DIR "/sys/kernel/debug/tracing" + +char *mtab_by_type(const char *type, int typelen) +{ + FILE *fd_mntent; + + fd_mntent = setmntent("/etc/mtab", "r"); + if(fd_mntent) + { + struct mntent *mntent; + + while(mntent = getmntent(fd_mntent), mntent) + { + log_debug("mntent->dir=%s type=%s", mntent->mnt_dir, mntent->mnt_type); + if(!strncmp(type, mntent->mnt_type, typelen)) + { + char *path = strdup(mntent->mnt_dir); + endmntent(fd_mntent); + return path; + } + } + endmntent(fd_mntent); + } + return NULL; +} + +char *ftrace_dir(void) +{ + char *path; + + /* tracefs paths point directly to the tracing directory */ + path = mtab_by_type("tracefs", sizeof("tracefs")-1); + if(path) + return path; + + /* debugfs paths point one level above the tracing directory */ + path = mtab_by_type("debugfs", sizeof("debugfs")-1); + if(path) + { + char *tmp; + int len = strlen(path) + sizeof("/tracing"); + tmp = malloc(len); + if(!tmp) + return NULL; + strcpy(tmp, path); + free(path); + strcat(tmp, "/tracing"); + return tmp; + } + + return strdup(DEFAULT_FTRACE_DIR); +} + int ftrace_setup(char *categories) { char *cat = strtok(categories, ","); diff --git a/src/rt-app_utils.h b/src/rt-app_utils.h index 06e8ad87..7c117efc 100644 --- a/src/rt-app_utils.h +++ b/src/rt-app_utils.h @@ -141,6 +141,10 @@ string_to_resource(const char *name, resource_t *resource); int resource_to_string(resource_t resource, char *name); +/* ftrace_dir always returns a string on the heap */ +char * +ftrace_dir(void); + int ftrace_setup(char *categories);