+ /*
+ * Action on traces (kernel or/and userspace).
+ */
+
+ if (opt_trace_kernel) {
+ if (auto_trace || opt_create_trace) {
+ DBG("Creating a kernel trace");
+ ret = process_kernel_create_trace();
+ if (ret < 0) {
+ goto end;
+ }
+ }
+
+ if (opt_event_list != NULL || opt_enable_all_event) {
+ ret = process_opt_kernel_event();
+ if (ret < 0) {
+ goto end;
+ }
+ }
+
+ 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;
+ }
+ }
+ }
+
+ if (opt_trace_pid != 0) {
+ if (auto_trace || opt_create_trace) {
+ DBG("Create a userspace trace for pid %d", opt_trace_pid);
+ ret = lttng_ust_create_trace(opt_trace_pid);
+ if (ret < 0) {
+ goto end;
+ }
+ MSG("Trace created successfully!");
+ }
+
+ if (auto_trace || opt_start_trace) {
+ DBG("Start trace for pid %d", opt_trace_pid);
+ ret = lttng_ust_start_trace(opt_trace_pid);
+ if (ret < 0) {
+ goto end;
+ }
+ MSG("Trace started successfully!");
+ } else if (opt_stop_trace) {
+ DBG("Stop trace for pid %d", opt_trace_pid);
+ ret = lttng_ust_stop_trace(opt_trace_pid);
+ if (ret < 0) {
+ goto end;
+ }
+ MSG("Trace stopped successfully!");
+ }
+
+ }
+
+ return 0;
+
+end:
+ ERR("%s", lttng_get_readable_code(ret));
+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
+ *
+ * Create a kernel trace.
+ */
+static int process_kernel_create_trace(void)
+{
+ int ret;
+
+ /* Setup kernel session */
+ ret = lttng_kernel_create_session();
+ if (ret < 0) {
+ goto error;
+ }
+
+ /* Create an empty channel (with no event) */
+ ret = lttng_kernel_create_channel();
+ if (ret < 0) {
+ goto error;