Fix message argument type
[lttng-tools.git] / lttng / lttng.c
index 9714e8a3476c10ad721362bca4d019c1c2fc62ae..b523960c33063be98e5bdf35fc9359fcdf76835f 100644 (file)
@@ -32,8 +32,8 @@
 
 #include <lttng/lttng.h>
 
-#include "lttng.h"
 #include "lttngerr.h"
+#include "options.h"
 
 /* Variables */
 static char *progname;
@@ -47,9 +47,11 @@ static int process_client_opt(void);
 static int process_opt_list_apps(void);
 static int process_opt_list_sessions(void);
 static int process_opt_list_traces(void);
+static int process_opt_kernel_list_events(void);
 static int process_opt_create_session(void);
 static int process_kernel_create_trace(void);
 static int process_opt_kernel_event(void);
+static int process_kernel_start_trace(void);
 static int set_session_uuid(void);
 static void sighandler(int sig);
 static int set_signal_handler(void);
@@ -86,6 +88,18 @@ static int process_client_opt(void)
                goto error;
        }
 
+       if (opt_list_events) {
+               if (opt_trace_kernel) {
+                       ret = process_opt_kernel_list_events();
+                       if (ret < 0) {
+                               goto end;
+                       }
+               } else if (opt_trace_pid != 0) {
+                       // TODO
+               }
+               goto error;
+       }
+
        /* Session creation or auto session set on */
        if (auto_session || opt_create_session) {
                DBG("Creating a new session");
@@ -129,13 +143,27 @@ static int process_client_opt(void)
                        }
                }
 
-               if (opt_event_list != NULL) {
+               if (opt_event_list != NULL || opt_enable_all_event) {
                        ret = process_opt_kernel_event();
                        if (ret < 0) {
                                goto end;
                        }
-               } else {
-                       // Enable all events
+               }
+
+               if (auto_trace || opt_start_trace) {
+                       DBG("Starting kernel tracing");
+                       ret = process_kernel_start_trace();
+                       if (ret < 0) {
+                               goto end;
+                       }
+               }
+
+               if (opt_stop_trace) {
+                       DBG("Stopping kernel tracing");
+                       ret = lttng_kernel_stop_tracing();
+                       if (ret < 0) {
+                               goto end;
+                       }
                }
        }
 
@@ -175,6 +203,33 @@ error:     /* fall through */
        return ret;
 }
 
+/*
+ *  process_kernel_start_trace
+ *
+ *  Start a kernel trace.
+ */
+static int process_kernel_start_trace(void)
+{
+       int ret;
+
+       ret = lttng_kernel_create_stream();
+       if (ret < 0) {
+               goto error;
+       }
+
+       ret = lttng_kernel_start_tracing();
+       if (ret < 0) {
+               goto error;
+       }
+
+       MSG("Kernel tracing started");
+
+       return 0;
+
+error:
+       return ret;
+}
+
 /*
  *  process_kernel_create_trace
  *
@@ -209,7 +264,40 @@ error:
 }
 
 /*
- *  process_kernel_event
+ *  process_opt_kernel_list_events
+ *
+ *  Ask for all trace events in the kernel and pretty print them.
+ */
+static int process_opt_kernel_list_events(void)
+{
+       int ret, pos, size;
+       char *event_list, *event, *ptr;
+
+       DBG("Getting all tracing events");
+
+       ret = lttng_kernel_list_events(&event_list);
+       if (ret < 0) {
+               ERR("Unable to list events.");
+               return ret;
+       }
+
+       MSG("Kernel tracepoints:\n-------------");
+
+       ptr = event_list;
+       while ((size = sscanf(ptr, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
+               MSG("    - %s", event);
+               /* Move pointer to the next line */
+               ptr += pos + 1;
+               free(event);
+       }
+
+       free(event_list);
+
+       return 0;
+}
+
+/*
+ *  process_opt_kernel_event
  *
  *  Enable kernel event from the command line list given.
  */
@@ -218,6 +306,17 @@ static int process_opt_kernel_event(void)
        int ret;
        char *event_name;
 
+       if (opt_enable_all_event) {
+               ret = lttng_kernel_enable_event(NULL);
+               if (ret < 0) {
+                       ERR("%s", lttng_get_readable_code(ret));
+               } else {
+                       MSG("All kernel event enabled");
+               }
+
+               goto end;
+       }
+
        event_name = strtok(opt_event_list, ",");
        while (event_name != NULL) {
                DBG("Enabling kernel event %s", event_name);
@@ -231,6 +330,7 @@ static int process_opt_kernel_event(void)
                event_name = strtok(NULL, ",");
        }
 
+end:
        return 0;
 }
 
@@ -525,10 +625,13 @@ static int validate_options(void)
        } else if (opt_stop_trace && opt_trace_pid != 0 && opt_trace_name == NULL) {
                ERR("Please specify a trace name for user-space tracing");
                goto error;
+       } else if (opt_stop_trace && opt_session_name == NULL) {
+               ERR("Please specify a session to stop tracing");
+               goto error;
        }
 
        /* If start trace, auto start tracing */
-       if (opt_start_trace || opt_event_list != NULL) {
+       if (opt_start_trace || opt_event_list != NULL || opt_enable_all_event) {
                DBG("Requesting auto tracing");
                auto_trace = 1;
        }
@@ -598,8 +701,8 @@ static int check_ltt_sessiond(void)
        int ret;
        char *pathname = NULL, *alloc_pathname = NULL;
 
-       ret = lttng_check_session_daemon();
-       if (ret < 0) {
+       ret = lttng_session_daemon_alive();
+       if (ret == 0) { /* not alive */
                /* Try command line option path */
                if (opt_sessiond_path != NULL) {
                        ret = access(opt_sessiond_path, F_OK | X_OK);
This page took 0.026971 seconds and 5 git commands to generate.