From 89565b43051f0e41abe73c15ecf001b0fd80c3fb Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 13 Sep 2006 16:55:40 +0000 Subject: [PATCH] add hybrid mode git-svn-id: http://ltt.polymtl.ca/svn@2097 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt-control/configure.in | 2 +- ltt-control/liblttctl/liblttctl.c | 13 +- ltt-control/liblttctl/lttctl.h | 16 ++- ltt-control/lttctl/lttctl.c | 193 ++++++++++++++++++++++++++---- ltt-control/lttd/lttd.c | 31 ++++- 5 files changed, 219 insertions(+), 36 deletions(-) diff --git a/ltt-control/configure.in b/ltt-control/configure.in index 17d1125..dbd709c 100644 --- a/ltt-control/configure.in +++ b/ltt-control/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.18-23082006) +AM_INIT_AUTOMAKE(ltt-control,0.20-13092006) AM_CONFIG_HEADER(config.h) AM_PROG_LIBTOOL diff --git a/ltt-control/liblttctl/liblttctl.c b/ltt-control/liblttctl/liblttctl.c index 1535e27..4690d7b 100644 --- a/ltt-control/liblttctl/liblttctl.c +++ b/ltt-control/liblttctl/liblttctl.c @@ -298,7 +298,10 @@ int lttctl_destroy_handle(struct lttctl_handle *h) int lttctl_create_trace(const struct lttctl_handle *h, - char *name, enum trace_mode mode, char *trace_type, unsigned subbuf_size, unsigned n_subbufs) + char *name, enum trace_mode mode, char *trace_type, + unsigned subbuf_size_low, unsigned n_subbufs_low, + unsigned subbuf_size_med, unsigned n_subbufs_med, + unsigned subbuf_size_high, unsigned n_subbufs_high) { int err; @@ -323,8 +326,12 @@ int lttctl_create_trace(const struct lttctl_handle *h, strncpy(req.msg.trace_type, trace_type, NAME_MAX); req.msg.op = OP_CREATE; req.msg.args.new_trace.mode = mode; - req.msg.args.new_trace.subbuf_size = subbuf_size; - req.msg.args.new_trace.n_subbufs = n_subbufs; + req.msg.args.new_trace.subbuf_size_low = subbuf_size_low; + req.msg.args.new_trace.n_subbufs_low = n_subbufs_low; + req.msg.args.new_trace.subbuf_size_med = subbuf_size_med; + req.msg.args.new_trace.n_subbufs_med = n_subbufs_med; + req.msg.args.new_trace.subbuf_size_high = subbuf_size_high; + req.msg.args.new_trace.n_subbufs_high = n_subbufs_high; err = lttctl_netlink_sendto(h, (void *)&req, req.nlh.nlmsg_len); if(err < 0) goto senderr; diff --git a/ltt-control/liblttctl/lttctl.h b/ltt-control/liblttctl/lttctl.h index b3766d7..8dae012 100644 --- a/ltt-control/liblttctl/lttctl.h +++ b/ltt-control/liblttctl/lttctl.h @@ -42,7 +42,8 @@ enum trace_op { enum trace_mode { LTT_TRACE_NORMAL, - LTT_TRACE_FLIGHT + LTT_TRACE_FLIGHT, + LTT_TRACE_HYBRID }; typedef struct lttctl_peer_msg { @@ -52,8 +53,12 @@ typedef struct lttctl_peer_msg { union { struct { enum trace_mode mode; - unsigned subbuf_size; - unsigned n_subbufs; + unsigned subbuf_size_low; + unsigned n_subbufs_low; + unsigned subbuf_size_med; + unsigned n_subbufs_med; + unsigned subbuf_size_high; + unsigned n_subbufs_high; } new_trace; } args; } lttctl_peer_msg_t; @@ -77,7 +82,10 @@ int lttctl_destroy_handle(struct lttctl_handle *h); int lttctl_create_trace(const struct lttctl_handle *h, - char *name, enum trace_mode mode, char *trace_type, unsigned subbuf_size, unsigned n_subbufs); + char *name, enum trace_mode mode, char *trace_type, + unsigned subbuf_size_low, unsigned n_subbufs_low, + unsigned subbuf_size_med, unsigned n_subbufs_med, + unsigned subbuf_size_high, unsigned n_subbufs_high); int lttctl_destroy_trace(const struct lttctl_handle *handle, char *name); diff --git a/ltt-control/lttctl/lttctl.c b/ltt-control/lttctl/lttctl.c index 301a4a3..fc865b1 100644 --- a/ltt-control/lttctl/lttctl.c +++ b/ltt-control/lttctl/lttctl.c @@ -35,6 +35,7 @@ enum trace_ctl_op { CTL_OP_START, CTL_OP_STOP, CTL_OP_DAEMON, + CTL_OP_DAEMON_HYBRID_FINISH, CTL_OP_DESCRIPTION, CTL_OP_NONE }; @@ -42,8 +43,12 @@ enum trace_ctl_op { static char *trace_name = NULL; static char *trace_type = "relay"; static char *mode_name = NULL; -static unsigned subbuf_size = 0; -static unsigned n_subbufs = 0; +static unsigned subbuf_size_low = 0; +static unsigned n_subbufs_low = 0; +static unsigned subbuf_size_med = 0; +static unsigned n_subbufs_med = 0; +static unsigned subbuf_size_high = 0; +static unsigned n_subbufs_high = 0; static unsigned append_trace = 0; static enum trace_mode mode = LTT_TRACE_NORMAL; static enum trace_ctl_op op = CTL_OP_NONE; @@ -61,8 +66,8 @@ void show_arguments(void) printf("-n name Name of the trace.\n"); printf("-b Create trace channels and start tracing (no daemon).\n"); printf("-c Create trace channels.\n"); - printf("-m mode Normal or flight recorder mode.\n"); - printf(" Mode values : normal (default) or flight.\n"); + printf("-m mode Normal, flight recorder or hybrid mode.\n"); + printf(" Mode values : normal (default), flight or hybrid.\n"); printf("-r Destroy trace channels.\n"); printf("-R Stop tracing and destroy trace channels.\n"); printf("-s Start tracing.\n"); @@ -70,13 +75,19 @@ void show_arguments(void) // "none exists.\n"); printf("-q Stop tracing.\n"); printf("-d Create trace, spawn a lttd daemon, start tracing.\n"); - printf(" (optionnaly, you can set LTT_DAEMON\n"); + printf(" (optionally, you can set LTT_DAEMON\n"); printf(" and the LTT_FACILITIES env. vars.)\n"); + printf("-f Stop tracing, dump flight recorder trace, destroy channels\n"); + printf(" (for hybrid traces)\n"); printf("-t Trace root path. (ex. /root/traces/example_trace)\n"); printf("-T Type of trace (ex. relay)\n"); printf("-l LTT channels root path. (ex. /mnt/relayfs/ltt)\n"); - printf("-z Size of the subbuffers (will be rounded to next page size)\n"); - printf("-x Number of subbuffers\n"); + printf("-Z Size of the low data rate subbuffers (will be rounded to next page size)\n"); + printf("-X Number of low data rate subbuffers\n"); + printf("-V Size of the medium data rate subbuffers (will be rounded to next page size)\n"); + printf("-B Number of medium data rate subbuffers\n"); + printf("-z Size of the high data rate subbuffers (will be rounded to next page size)\n"); + printf("-x Number of high data rate subbuffers\n"); printf("-e Get XML facilities description\n"); printf("-a Append to trace\n"); printf("-N Number of lttd threads\n"); @@ -132,6 +143,8 @@ int parse_arguments(int argc, char **argv) mode = LTT_TRACE_NORMAL; else if(strcmp(mode_name, "flight") == 0) mode = LTT_TRACE_FLIGHT; + else if(strcmp(mode_name, "hybrid") == 0) + mode = LTT_TRACE_HYBRID; else { printf("Invalid mode '%s'.\n", argv[argn]); printf("\n"); @@ -155,22 +168,62 @@ int parse_arguments(int argc, char **argv) case 'q': op = CTL_OP_STOP; break; + case 'Z': + if(argn+1 < argc) { + subbuf_size_low = (unsigned)atoi(argv[argn+1]); + argn++; + } else { + printf("Specify a number of low traffic subbuffers after -Z.\n"); + printf("\n"); + ret = EINVAL; + } + break; + case 'X': + if(argn+1 < argc) { + n_subbufs_low = (unsigned)atoi(argv[argn+1]); + argn++; + } else { + printf("Specify a low traffic subbuffer size after -X.\n"); + printf("\n"); + ret = EINVAL; + } + break; + case 'V': + if(argn+1 < argc) { + subbuf_size_med = (unsigned)atoi(argv[argn+1]); + argn++; + } else { + printf("Specify a number of medium traffic subbuffers after -V.\n"); + printf("\n"); + ret = EINVAL; + } + break; + case 'B': + if(argn+1 < argc) { + n_subbufs_med = (unsigned)atoi(argv[argn+1]); + argn++; + } else { + printf("Specify a medium traffic subbuffer size after -B.\n"); + printf("\n"); + ret = EINVAL; + } + break; case 'z': if(argn+1 < argc) { - subbuf_size = (unsigned)atoi(argv[argn+1]); + subbuf_size_high = (unsigned)atoi(argv[argn+1]); argn++; } else { - printf("Specify a number of subbuffers after -z.\n"); + printf("Specify a number of high traffic subbuffers after -z.\n"); printf("\n"); ret = EINVAL; } break; case 'x': if(argn+1 < argc) { - n_subbufs = (unsigned)atoi(argv[argn+1]); + n_subbufs_high = (unsigned)atoi(argv[argn+1]); argn++; } else { - printf("Specify a subbuffer size after -x.\n"); + printf("Specify a high traffic subbuffer size after -x.\n"); printf("\n"); ret = EINVAL; } @@ -178,6 +231,9 @@ int parse_arguments(int argc, char **argv) case 'd': op = CTL_OP_DAEMON; break; + case 'f': + op = CTL_OP_DAEMON_HYBRID_FINISH; + break; case 'e': op = CTL_OP_DESCRIPTION; break; @@ -246,7 +302,7 @@ int parse_arguments(int argc, char **argv) ret = EINVAL; } - if(op == CTL_OP_DAEMON) { + if(op == CTL_OP_DAEMON || op == CTL_OP_DAEMON_HYBRID_FINISH) { if(trace_root == NULL) { printf("Please specify -t trace_root_path with the -d option.\n"); printf("\n"); @@ -392,7 +448,10 @@ int lttctl_daemon(struct lttctl_handle *handle, char *trace_name) strcat(channel_path, trace_name); - ret = lttctl_create_trace(handle, trace_name, mode, trace_type, subbuf_size, n_subbufs); + ret = lttctl_create_trace(handle, trace_name, mode, trace_type, + subbuf_size_low, n_subbufs_low, + subbuf_size_med, n_subbufs_med, + subbuf_size_high, n_subbufs_high); if(ret != 0) goto create_error; pid = fork(); @@ -420,12 +479,21 @@ int lttctl_daemon(struct lttctl_handle *handle, char *trace_name) } else if(pid == 0) { /* child */ int ret; - if(append_trace) - ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", - channel_path, "-d", "-a", "-N", num_threads, NULL); - else - ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", - channel_path, "-d", "-N", num_threads, NULL); + if(mode != LTT_TRACE_HYBRID) { + if(append_trace) + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-a", "-N", num_threads, NULL); + else + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-N", num_threads, NULL); + } else { + if(append_trace) + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-a", "-N", num_threads, "-n", NULL); + else + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-N", num_threads, "-n", NULL); + } if(ret) { ret = errno; perror("Error in executing the lttd daemon"); @@ -449,6 +517,78 @@ create_error: return ret; } + + + +int lttctl_daemon_hybrid_finish(struct lttctl_handle *handle, char *trace_name) +{ + char channel_path[PATH_MAX] = ""; + pid_t pid; + int ret; + char *lttd_path = getenv("LTT_DAEMON"); + + if(lttd_path == NULL) lttd_path = + PACKAGE_BIN_DIR "/lttd"; + + strcat(channel_path, channel_root); + strcat(channel_path, "/"); + strcat(channel_path, trace_name); + + + ret = lttctl_stop(handle, trace_name); + if(ret != 0) goto stop_error; + + pid = fork(); + + if(pid > 0) { + int status = 0; + /* parent */ + + ret = waitpid(pid, &status, 0); + if(ret == -1) { + ret = errno; + perror("Error in waitpid"); + goto destroy_error; + } + + ret = 0; + if(WIFEXITED(status)) + ret = WEXITSTATUS(status); + if(ret) goto destroy_error; + + } else if(pid == 0) { + /* child */ + int ret; + if(append_trace) + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-a", "-N", num_threads, "-f", NULL); + else + ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", + channel_path, "-d", "-N", num_threads, "-f", NULL); + if(ret) { + ret = errno; + perror("Error in executing the lttd daemon"); + exit(ret); + } + } else { + /* error */ + perror("Error in forking for lttd daemon"); + } + + ret = lttctl_destroy_trace(handle, trace_name); + if(ret != 0) goto destroy_error; + + return 0; + + /* error handling */ +destroy_error: + printf("Hybrid trace destroy error\n"); +stop_error: + return ret; +} + + + int main(int argc, char ** argv) { int ret; @@ -468,14 +608,18 @@ int main(int argc, char ** argv) switch(op) { case CTL_OP_CREATE_START: - ret = lttctl_create_trace(handle, trace_name, mode, trace_type, subbuf_size, - n_subbufs); + ret = lttctl_create_trace(handle, trace_name, mode, trace_type, + subbuf_size_low, n_subbufs_low, + subbuf_size_med, n_subbufs_med, + subbuf_size_high, n_subbufs_high); if(!ret) ret = lttctl_start(handle, trace_name); break; case CTL_OP_CREATE: - ret = lttctl_create_trace(handle, trace_name, mode, trace_type, subbuf_size, - n_subbufs); + ret = lttctl_create_trace(handle, trace_name, mode, trace_type, + subbuf_size_low, n_subbufs_low, + subbuf_size_med, n_subbufs_med, + subbuf_size_high, n_subbufs_high); break; case CTL_OP_DESTROY: ret = lttctl_destroy_trace(handle, trace_name); @@ -494,6 +638,9 @@ int main(int argc, char ** argv) case CTL_OP_DAEMON: ret = lttctl_daemon(handle, trace_name); break; + case CTL_OP_DAEMON_HYBRID_FINISH: + ret = lttctl_daemon_hybrid_finish(handle, trace_name); + break; case CTL_OP_DESCRIPTION: ret = create_eventdefs(); break; diff --git a/ltt-control/lttd/lttd.c b/ltt-control/lttd/lttd.c index fea1188..e931df5 100644 --- a/ltt-control/lttd/lttd.c +++ b/ltt-control/lttd/lttd.c @@ -67,12 +67,14 @@ struct channel_trace_fd { int num_pairs; }; -static char *trace_name = NULL; -static char *channel_name = NULL; -static int daemon_mode = 0; -static int append_mode = 0; -static unsigned long num_threads = 1; +static char *trace_name = NULL; +static char *channel_name = NULL; +static int daemon_mode = 0; +static int append_mode = 0; +static unsigned long num_threads = 1; volatile static int quit_program = 0; /* For signal handler */ +static int dump_flight_only = 0; +static int dump_normal_only = 0; /* Args : * @@ -92,6 +94,8 @@ void show_arguments(void) printf("-d Run in background (daemon).\n"); printf("-a Append to an possibly existing trace.\n"); printf("-N Number of threads to start.\n"); + printf("-f Dump only flight recorder channels.\n"); + printf("-n Dump only normal channels.\n"); printf("\n"); } @@ -143,6 +147,12 @@ int parse_arguments(int argc, char **argv) argn++; } break; + case 'f': + dump_flight_only = 1; + break; + case 'n': + dump_normal_only = 1; + break; default: printf("Invalid argument '%s'.\n", argv[argn]); printf("\n"); @@ -256,6 +266,17 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name, ret = open_channel_trace_pairs(path_channel, path_trace, fd_pairs); if(ret < 0) continue; } else if(S_ISREG(stat_buf.st_mode)) { + if(strncmp(entry->d_name, "flight-", sizeof("flight-")-1) != 0) { + if(dump_flight_only) { + printf("Skipping normal channel %s\n", path_channel); + continue; + } + } else { + if(dump_normal_only) { + printf("Skipping flight channel %s\n", path_channel); + continue; + } + } printf("Opening file.\n"); fd_pairs->pair = realloc(fd_pairs->pair, -- 2.39.5