From 8d5607b44df5d7328c6885b29b711e97eb766f13 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 12 Nov 2009 16:57:28 -0500 Subject: [PATCH] Add lttctl support for switch_timer Signed-off-by: Mathieu Desnoyers --- configure.in | 2 +- liblttctl/liblttctl.c | 68 +++++++++++++++++++++++++++++++++++++++++++ liblttctl/lttctl.h | 2 ++ lttctl/lttctl.c | 17 +++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 6ce398f..39d7f49 100644 --- a/configure.in +++ b/configure.in @@ -23,7 +23,7 @@ AC_PREREQ(2.57) AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) #AC_WITH_LTDL # not needed ? -AM_INIT_AUTOMAKE(ltt-control,0.72-23102009) +AM_INIT_AUTOMAKE(ltt-control,0.73-12112009) AM_CONFIG_HEADER(config.h) AM_PROG_LIBTOOL diff --git a/liblttctl/liblttctl.c b/liblttctl/liblttctl.c index 6d49aeb..e9f4f18 100644 --- a/liblttctl/liblttctl.c +++ b/liblttctl/liblttctl.c @@ -640,6 +640,7 @@ static int __lttctl_set_channel_subbuf_size(const char *name, if (ret) fprintf(stderr, "Set channel's subbuf size failed\n"); } + int lttctl_set_channel_subbuf_size(const char *name, const char *channel, unsigned subbuf_size) { @@ -690,6 +691,73 @@ arg_error: return ret; } +static int __lttctl_set_channel_switch_timer(const char *name, + const char *channel, unsigned switch_timer) +{ + int ret; + char ctlfname[PATH_MAX]; + char opstr[32]; + + sprintf(ctlfname, "%s/ltt/control/%s/channel/%s/switch_timer", + debugfsmntdir, name, channel); + + sprintf(opstr, "%u", switch_timer); + + ret = lttctl_sendop(ctlfname, opstr); + if (ret) + fprintf(stderr, "Set channel's switch timer failed\n"); +} + +int lttctl_set_channel_switch_timer(const char *name, const char *channel, + unsigned switch_timer) +{ + int ret; + char **channellist; + int n_channel; + + if (!name || !channel) { + fprintf(stderr, "%s: args invalid\n", __func__); + ret = -EINVAL; + goto arg_error; + } + + ret = lttctl_check_trace(name, 1); + if (ret) + goto arg_error; + + if (strcmp(channel, "all")) { + ret = __lttctl_set_channel_subbuf_size(name, channel, + switch_timer); + if (ret) + goto op_err; + } else { + /* allow set subbuf_size for metadata channel */ + n_channel = lttctl_get_channellist(name, &channellist, 1); + if (n_channel < 0) { + fprintf(stderr, "%s: lttctl_get_channellist failed\n", + __func__); + ret = -ENOENT; + goto op_err; + } + + for (; n_channel > 0; n_channel--) { + ret = __lttctl_set_channel_switch_timer(name, + channellist[n_channel - 1], switch_timer); + if (ret) + goto op_err_clean; + } + lttctl_free_channellist(channellist, n_channel); + } + + return 0; + +op_err_clean: + lttctl_free_channellist(channellist, n_channel); +op_err: +arg_error: + return ret; +} + int getdebugfsmntdir(char *mntdir) { char mnt_dir[PATH_MAX]; diff --git a/liblttctl/lttctl.h b/liblttctl/lttctl.h index facc8f0..55a7b4c 100644 --- a/liblttctl/lttctl.h +++ b/liblttctl/lttctl.h @@ -35,6 +35,8 @@ int lttctl_set_channel_subbuf_num(const char *name, const char *channel, unsigned subbuf_num); int lttctl_set_channel_subbuf_size(const char *name, const char *channel, unsigned subbuf_size); +int lttctl_set_channel_switch_timer(const char *name, const char *channel, + unsigned switch_timer); /* Helper functions */ int getdebugfsmntdir(char *mntdir); diff --git a/lttctl/lttctl.c b/lttctl/lttctl.c index e08280a..7380136 100644 --- a/lttctl/lttctl.c +++ b/lttctl/lttctl.c @@ -41,6 +41,7 @@ struct channel_option { int overwrite; int bufnum; int bufsize; + int switch_timer; }; struct lttctl_option { @@ -124,6 +125,8 @@ static void show_arguments(void) printf(" channel..bufsize= (in bytes, rounded to " "next power of 2)\n"); printf(" can be set to all for all channels\n"); + printf(" channel..switch_timer= (timer interval in " + "ms)\n"); printf("\n"); printf(" Integration options:\n"); printf(" -C, --create_start\n"); @@ -205,6 +208,7 @@ static void init_channel_opt(struct channel_option *opt, char *opt_name) opt->overwrite = -1; opt->bufnum = -1; opt->bufsize = -1; + opt->switch_timer = -1; strcpy(opt->chan_name, opt_name); } } @@ -291,6 +295,14 @@ int set_channel_opt(struct channel_option *opt, char *opt_name, char *opt_valstr opt->bufsize = opt_val; return 0; + } else if (!strcmp("switch_timer", opt_name)) { + ret = sscanf(opt_valstr, "%d", &opt_val); + if (ret != 1 || opt_val < 0) { + return -EINVAL; + } + + opt->switch_timer = opt_val; + return 0; } else { return -EINVAL; } @@ -622,6 +634,11 @@ static int lttctl_channel_setup(struct channel_option *opt) opt->bufsize)) != 0) return ret; } + if (opt->switch_timer != -1) { + if ((ret = lttctl_set_channel_switch_timer(opt_tracename, + opt->chan_name, opt->switch_timer)) != 0) + return ret; + } return 0; } -- 2.34.1