Initial work for kernel tracing support
[lttng-tools.git] / ltt-sessiond / trace.c
index a821327e253242ef780b4d8c06614687169cfdbf..1cddb31fac9c6bb68a8a9f401e6567a08941f33d 100644 (file)
@@ -29,6 +29,7 @@
 #include "lttngerr.h"
 #include "trace.h"
 #include "session.h"
+#include "ltt-sessiond.h"
 
 static struct ltt_ust_trace *find_session_ust_trace_by_pid(
                struct ltt_session *session, pid_t pid);
@@ -62,7 +63,7 @@ static struct ltt_ust_trace *find_session_ust_trace_by_pid(
  */
 int get_trace_count_per_session(struct ltt_session *session)
 {
-       return session->ust_trace_count + session->kern_trace_count;
+       return session->ust_trace_count + session->kern_session_count;
 }
 
 /*
@@ -75,7 +76,6 @@ void get_traces_per_session(struct ltt_session *session, struct lttng_trace *tra
 {
        int i = 0;
        struct ltt_ust_trace *ust_iter;
-       struct ltt_kernel_trace *kern_iter;
        struct lttng_trace trace;
 
        DBG("Getting userspace traces for session %s", session->name);
@@ -94,13 +94,10 @@ void get_traces_per_session(struct ltt_session *session, struct lttng_trace *tra
        DBG("Getting kernel traces for session %s", session->name);
 
        /* Getting kernel traces */
-       cds_list_for_each_entry(kern_iter, &session->kernel_traces, list) {
+       if (session->kern_session_count > 0) {
                trace.type = KERNEL;
-               strncpy(trace.name, kern_iter->name, sizeof(trace.name));
-               trace.name[sizeof(trace.name) - 1] = '\0';
+               strncpy(trace.name, "kernel", 6);
                memcpy(&traces[i], &trace, sizeof(trace));
-               memset(&trace, 0, sizeof(trace));
-               i++;
        }
 }
 
@@ -111,12 +108,12 @@ void get_traces_per_session(struct ltt_session *session, struct lttng_trace *tra
  *  This trace is then appended to the current session
  *  ust trace list.
  */
-int ust_create_trace(int sock, pid_t pid)
+int ust_create_trace(struct command_ctx *cmd_ctx)
 {
        int ret;
        struct ltt_ust_trace *trace;
 
-       DBG("Creating trace for pid %d", pid);
+       DBG("Creating trace for pid %d", cmd_ctx->lsm->pid);
 
        trace = malloc(sizeof(struct ltt_ust_trace));
        if (trace == NULL) {
@@ -126,7 +123,7 @@ int ust_create_trace(int sock, pid_t pid)
        }
 
        /* Init */
-       trace->pid = pid;
+       trace->pid = cmd_ctx->lsm->pid;
        trace->shmid = 0;
        /* NOTE: to be removed. Trace name will no longer be
         * required for LTTng userspace tracer. For now, we set it
@@ -134,19 +131,19 @@ int ust_create_trace(int sock, pid_t pid)
         */
        snprintf(trace->name, 5, "auto");
 
-       ret = ustctl_create_trace(sock, trace->name);
+       ret = ustctl_create_trace(cmd_ctx->ust_sock, trace->name);
        if (ret < 0) {
                ret = LTTCOMM_CREATE_FAIL;
                goto error_create;
        }
 
        /* Check if current session is valid */
-       if (current_session) {
-               cds_list_add(&trace->list, &current_session->ust_traces);
-               current_session->ust_trace_count++;
+       if (cmd_ctx->session) {
+               cds_list_add(&trace->list, &cmd_ctx->session->ust_traces);
+               cmd_ctx->session->ust_trace_count++;
        }
 
-       return 0;
+       return LTTCOMM_OK;
 
 error_create:
        free(trace);
@@ -160,25 +157,27 @@ error:
  *  Start a trace. This trace, identified by the pid, must be
  *  in the current session ust_traces list.
  */
-int ust_start_trace(int sock, pid_t pid)
+int ust_start_trace(struct command_ctx *cmd_ctx)
 {
        int ret;
        struct ltt_ust_trace *trace;
 
-       DBG("Starting trace for pid %d", pid);
+       DBG("Starting trace for pid %d", cmd_ctx->lsm->pid);
 
-       trace = find_session_ust_trace_by_pid(current_session, pid);
+       trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
        if (trace == NULL) {
                ret = LTTCOMM_NO_TRACE;
                goto error;
        }
 
-       ret = ustctl_start_trace(sock, "auto");
+       ret = ustctl_start_trace(cmd_ctx->ust_sock, "auto");
        if (ret < 0) {
                ret = LTTCOMM_START_FAIL;
                goto error;
        }
 
+       ret = LTTCOMM_OK;
+
 error:
        return ret;
 }
@@ -189,25 +188,27 @@ error:
  *  Stop a trace. This trace, identified by the pid, must be
  *  in the current session ust_traces list.
  */
-int ust_stop_trace(int sock, pid_t pid)
+int ust_stop_trace(struct command_ctx *cmd_ctx)
 {
        int ret;
        struct ltt_ust_trace *trace;
 
-       DBG("Stopping trace for pid %d", pid);
+       DBG("Stopping trace for pid %d", cmd_ctx->lsm->pid);
 
-       trace = find_session_ust_trace_by_pid(current_session, pid);
+       trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
        if (trace == NULL) {
                ret = LTTCOMM_NO_TRACE;
                goto error;
        }
 
-       ret = ustctl_stop_trace(sock, trace->name);
+       ret = ustctl_stop_trace(cmd_ctx->ust_sock, trace->name);
        if (ret < 0) {
                ret = LTTCOMM_STOP_FAIL;
                goto error;
        }
 
+       ret = LTTCOMM_OK;
+
 error:
        return ret;
 }
This page took 0.025733 seconds and 4 git commands to generate.