Changes malloc to zmalloc
[ust.git] / ustctl / ustctl.c
index 789dfe0feeb7c8d44da14ebc97ae23cef75969c3..d29097567aed1b93143c5f22c66a391f0992833b 100644 (file)
 #include <stdlib.h>
 #include <fcntl.h>
 
-#include "ustcomm.h"
-#include "ustcmd.h"
+#include "ust/ustcmd.h"
 #include "usterr.h"
 
 enum command {
+       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,
+       GET_SUBBUF_SIZE,
+       GET_SUBBUF_NUM,
+       GET_SOCK_PATH,
+       SET_SOCK_PATH,
+       FORCE_SWITCH,
        UNKNOWN
 };
 
@@ -52,12 +59,21 @@ void usage(void)
        fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
 \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\
 \
 ");
 }
@@ -72,25 +88,33 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts)
        while (1) {
                int option_index = 0;
                static struct option long_options[] = {
-                       {"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},
-                       {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);
@@ -99,50 +123,31 @@ 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");
-
-               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);
                }
        }
 
        if (argc - optind > 0 && opts->cmd != GET_ONLINE_PIDS) {
                int i;
                int pididx=0;
-               opts->pids = malloc((argc-optind+1) * sizeof(pid_t));
+               opts->pids = zmalloc((argc-optind+1) * sizeof(pid_t));
 
                for(i=optind; i<argc; i++) {
                        /* don't take any chances, use a long long */
@@ -165,6 +170,7 @@ int main(int argc, char *argv[])
 {
        pid_t *pidit;
        int result;
+       char *tmp;
        struct ust_opts opts;
 
        progname = argv[0];
@@ -212,13 +218,20 @@ int main(int argc, char *argv[])
 
        while(*pidit != -1) {
                switch (opts.cmd) {
+                       case CREATE_TRACE:
+                               result = ustcmd_create_trace(*pidit);
+                               if (result) {
+                                       ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit);
+                                       break;
+                               }
+                               break;
+
                        case START_TRACE:
                                result = ustcmd_start_trace(*pidit);
                                if (result) {
                                        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:
@@ -227,25 +240,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:
@@ -279,6 +281,66 @@ int main(int argc, char *argv[])
                                        ustcmd_set_marker_state(opts.regex, 0, *pidit);
                                break;
 
+                       case SET_SUBBUF_SIZE:
+                               ustcmd_set_subbuf_size(opts.regex, *pidit);
+                               break;
+
+                       case SET_SUBBUF_NUM:
+                               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) {
+                                       ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit);
+                                       break;
+                               }
+                               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;
This page took 0.027782 seconds and 4 git commands to generate.