X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ustctl%2Fustctl.c;h=b9f2dce83b43913bc6aaedd766d160d9a81accdb;hb=b9318b35947bbd6d3b2998b28d974c5e5bfabcf6;hp=39ca4025ac347941d2aee84f1abd99533509b113;hpb=763f41e58126afdc361006831a7daca773a9627a;p=ust.git diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c index 39ca402..b9f2dce 100644 --- a/ustctl/ustctl.c +++ b/ustctl/ustctl.c @@ -27,18 +27,22 @@ #include "usterr.h" enum command { - CREATE_TRACE, + CREATE_TRACE=1000, + ALLOC_TRACE, START_TRACE, STOP_TRACE, - START, - DESTROY, + DESTROY_TRACE, LIST_MARKERS, ENABLE_MARKER, DISABLE_MARKER, GET_ONLINE_PIDS, SET_SUBBUF_SIZE, SET_SUBBUF_NUM, - ALLOC_TRACE, + GET_SUBBUF_SIZE, + GET_SUBBUF_NUM, + GET_SOCK_PATH, + SET_SOCK_PATH, + FORCE_SWITCH, UNKNOWN }; @@ -57,14 +61,20 @@ void usage(void) \n\ Commands:\n\ --create-trace\t\t\tCreate trace\n\ + --alloc-trace\t\t\tAlloc trace\n\ --start-trace\t\t\tStart tracing\n\ --stop-trace\t\t\tStop tracing\n\ --destroy-trace\t\t\tDestroy the trace\n\ --set-subbuf-size \"CHANNEL/bytes\"\tSet the size of subbuffers per channel\n\ --set-subbuf-num \"CHANNEL/n\"\tSet the number of subbuffers per channel\n\ + --set-sock-path\t\t\tSet the path of the daemon socket\n\ + --get-subbuf-size \"CHANNEL\"\t\tGet the size of subbuffers per channel\n\ + --get-subbuf-num \"CHANNEL\"\t\tGet the number of subbuffers per channel\n\ + --get-sock-path\t\t\tGet the path of the daemon socket\n\ --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\ --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\ --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\ + --force-switch\t\t\tForce a subbuffer switch\n\ \ "); } @@ -79,29 +89,33 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) while (1) { int option_index = 0; static struct option long_options[] = { - {"create-trace", 0, 0, 1012}, - {"alloc-trace", 0, 0, 1015}, - {"start-trace", 0, 0, 1000}, - {"stop-trace", 0, 0, 1001}, - {"destroy-trace", 0, 0, 1002}, - {"list-markers", 0, 0, 1004}, - {"print-markers", 0, 0, 1005}, - {"pid", 1, 0, 1006}, - {"enable-marker", 1, 0, 1007}, - {"disable-marker", 1, 0, 1008}, - {"start", 0, 0, 1009}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 1010}, - {"online-pids", 0, 0, 1011}, - {"set-subbuf-size", 1, 0, 1013}, - {"set-subbuf-num", 1, 0, 1014}, - {0, 0, 0, 0} + { "create-trace", 0, 0, CREATE_TRACE }, + { "alloc-trace", 0, 0, ALLOC_TRACE }, + { "start-trace", 0, 0, START_TRACE }, + { "stop-trace", 0, 0, STOP_TRACE }, + { "destroy-trace", 0, 0, DESTROY_TRACE }, + { "list-markers", 0, 0, LIST_MARKERS }, + { "enable-marker", 1, 0, ENABLE_MARKER }, + { "disable-marker", 1, 0, DISABLE_MARKER }, + { "help", 0, 0, 'h' }, + { "online-pids", 0, 0, GET_ONLINE_PIDS }, + { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE }, + { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM }, + { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE }, + { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM }, + { "get-sock-path", 0, 0, GET_SOCK_PATH }, + { "set-sock-path", 1, 0, SET_SOCK_PATH }, + { "force-switch", 0, 0, FORCE_SWITCH }, + { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "h", long_options, &option_index); if (c == -1) break; + if(c >= 1000) + opts->cmd = c; + switch (c) { case 0: printf("option %s", long_options[option_index].name); @@ -110,57 +124,24 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) printf("\n"); break; - case 1000: - opts->cmd = START_TRACE; - break; - case 1001: - opts->cmd = STOP_TRACE; - break; - case 1009: - opts->cmd = START; - break; - case 1002: - opts->cmd = DESTROY; - break; - case 1004: - opts->cmd = LIST_MARKERS; - break; - case 1007: - opts->cmd = ENABLE_MARKER; - opts->regex = strdup(optarg); - break; - case 1008: - opts->cmd = DISABLE_MARKER; + case ENABLE_MARKER: + case DISABLE_MARKER: + case SET_SUBBUF_SIZE: + case SET_SUBBUF_NUM: + case GET_SUBBUF_SIZE: + case GET_SUBBUF_NUM: + case SET_SOCK_PATH: opts->regex = strdup(optarg); break; - case 1011: - opts->cmd = GET_ONLINE_PIDS; - break; + case 'h': usage(); exit(0); - case 1010: - printf("Version 0.1\n"); - break; - case 1012: - opts->cmd = CREATE_TRACE; - break; - case 1013: - opts->cmd = SET_SUBBUF_SIZE; - opts->regex = strdup(optarg); - break; - case 1014: - opts->cmd = SET_SUBBUF_NUM; - opts->regex = strdup(optarg); - break; - case 1015: - opts->cmd = ALLOC_TRACE; - break; - default: - /* unknown option or other error; error is - printed by getopt, just return */ - opts->cmd = UNKNOWN; - return 1; + + case '?': + fprintf(stderr, "Invalid argument\n\n"); + usage(); + exit(1); } } @@ -190,6 +171,7 @@ int main(int argc, char *argv[]) { pid_t *pidit; int result; + char *tmp; struct ust_opts opts; progname = argv[0]; @@ -251,7 +233,6 @@ int main(int argc, char *argv[]) ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit); break; } - //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit); break; case STOP_TRACE: @@ -260,25 +241,14 @@ int main(int argc, char *argv[]) ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit); break; } - //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit); break; - case START: - result = ustcmd_setup_and_start(*pidit); - if (result) { - ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit); - break; - } - //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit); - break; - - case DESTROY: + case DESTROY_TRACE: result = ustcmd_destroy_trace(*pidit); if (result) { ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit); break; } - //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit); break; case LIST_MARKERS: @@ -320,6 +290,26 @@ int main(int argc, char *argv[]) ustcmd_set_subbuf_num(opts.regex, *pidit); break; + case GET_SUBBUF_SIZE: + result = ustcmd_get_subbuf_size(opts.regex, *pidit); + if (result == -1) { + ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit); + break; + } + + printf("the size of subbufers is %d\n", result); + break; + + case GET_SUBBUF_NUM: + result = ustcmd_get_subbuf_num(opts.regex, *pidit); + if (result == -1) { + ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit); + break; + } + + printf("the number of subbufers is %d\n", result); + break; + case ALLOC_TRACE: result = ustcmd_alloc_trace(*pidit); if (result) { @@ -328,6 +318,30 @@ int main(int argc, char *argv[]) } break; + case GET_SOCK_PATH: + result = ustcmd_get_sock_path(&tmp, *pidit); + if (result) { + ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit); + break; + } + printf("the socket path is %s\n", tmp); + free(tmp); + break; + + case SET_SOCK_PATH: + result = ustcmd_set_sock_path(opts.regex, *pidit); + if (result) { + ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit); + } + break; + + case FORCE_SWITCH: + result = ustcmd_force_switch(*pidit); + if (result) { + ERR("error while trying to force switch for PID %u\n", (unsigned int) *pidit); + } + break; + default: ERR("unknown command\n"); break;