2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <lttng-sessiond-comm.h>
32 * find_session_ust_trace_by_pid
34 * Iterate over the session ust_traces and
35 * return a pointer or NULL if not found.
37 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
38 struct ltt_session
*session
, pid_t pid
)
40 struct ltt_ust_trace
*iter
;
42 cds_list_for_each_entry(iter
, &session
->ust_traces
, list
) {
43 if (iter
->pid
== pid
) {
53 * get_trace_count_per_session
55 * Return the total count of traces (ust and kernel)
56 * for the specified session.
58 int get_trace_count_per_session(struct ltt_session
*session
)
60 return session
->ust_trace_count
;
64 * get_traces_per_session
66 * Fill the lttng_trace array of all the
67 * available trace of the session.
70 void get_traces_per_session(struct ltt_session *session, struct lttng_trace *traces)
73 struct ltt_ust_trace *ust_iter;
74 struct lttng_trace trace;
76 DBG("Getting userspace traces for session %s", session->name);
78 cds_list_for_each_entry(ust_iter, &session->ust_traces, list) {
79 trace.type = USERSPACE;
80 trace.pid = ust_iter->pid;
81 strncpy(trace.name, ust_iter->name, sizeof(trace.name));
82 trace.name[sizeof(trace.name) - 1] = '\0';
83 memcpy(&traces[i], &trace, sizeof(trace));
84 memset(&trace, 0, sizeof(trace));
88 DBG("Getting kernel traces for session %s", session->name);
90 if (session->kern_session_count > 0) {
92 strncpy(trace.name, "kernel", sizeof(trace.name));
93 trace.name[sizeof(trace.name) - 1] = '\0';
94 memcpy(&traces[i], &trace, sizeof(trace));
102 * Create an userspace trace using pid.
103 * This trace is then appended to the current session
106 int ust_create_trace(struct command_ctx
*cmd_ctx
)
109 struct ltt_ust_trace
*trace
;
111 DBG("Creating trace for pid %d", cmd_ctx
->lsm
->pid
);
113 trace
= malloc(sizeof(struct ltt_ust_trace
));
121 trace
->pid
= cmd_ctx
->lsm
->pid
;
123 /* NOTE: to be removed. Trace name will no longer be
124 * required for LTTng userspace tracer. For now, we set it
125 * to 'auto' for API compliance.
127 snprintf(trace
->name
, 5, "auto");
129 ret
= ustctl_create_trace(cmd_ctx
->ust_sock
, trace
->name
);
131 ret
= LTTCOMM_CREATE_FAIL
;
135 /* Check if current session is valid */
136 if (cmd_ctx
->session
) {
137 cds_list_add(&trace
->list
, &cmd_ctx
->session
->ust_traces
);
138 cmd_ctx
->session
->ust_trace_count
++;
152 * Start a trace. This trace, identified by the pid, must be
153 * in the current session ust_traces list.
155 int ust_start_trace(struct command_ctx
*cmd_ctx
)
158 struct ltt_ust_trace
*trace
;
160 DBG("Starting trace for pid %d", cmd_ctx
->lsm
->pid
);
162 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
164 ret
= LTTCOMM_NO_TRACE
;
168 ret
= ustctl_start_trace(cmd_ctx
->ust_sock
, "auto");
170 ret
= LTTCOMM_START_FAIL
;
183 * Stop a trace. This trace, identified by the pid, must be
184 * in the current session ust_traces list.
186 int ust_stop_trace(struct command_ctx
*cmd_ctx
)
189 struct ltt_ust_trace
*trace
;
191 DBG("Stopping trace for pid %d", cmd_ctx
->lsm
->pid
);
193 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
195 ret
= LTTCOMM_NO_TRACE
;
199 ret
= ustctl_stop_trace(cmd_ctx
->ust_sock
, trace
->name
);
201 ret
= LTTCOMM_STOP_FAIL
;
This page took 0.03494 seconds and 5 git commands to generate.