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; either version 2
7 * of the License, or (at your option) any later version.
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.
25 #include <urcu/list.h>
26 #include <ust/ustctl.h>
28 #include "liblttsessiondcomm.h"
32 #include "ltt-sessiond.h"
34 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
35 struct ltt_session
*session
, pid_t pid
);
38 * find_session_ust_trace_by_pid
40 * Iterate over the session ust_traces and
41 * return a pointer or NULL if not found.
43 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
44 struct ltt_session
*session
, pid_t pid
)
46 struct ltt_ust_trace
*iter
;
48 cds_list_for_each_entry(iter
, &session
->ust_traces
, list
) {
49 if (iter
->pid
== pid
) {
59 * get_trace_count_per_session
61 * Return the total count of traces (ust and kernel)
62 * for the specified session.
64 int get_trace_count_per_session(struct ltt_session
*session
)
66 return session
->ust_trace_count
+ session
->kern_trace_count
;
70 * get_traces_per_session
72 * Fill the lttng_trace array of all the
73 * available trace of the session.
75 void get_traces_per_session(struct ltt_session
*session
, struct lttng_trace
*traces
)
78 struct ltt_ust_trace
*ust_iter
;
79 struct ltt_kernel_trace
*kern_iter
;
80 struct lttng_trace trace
;
82 DBG("Getting userspace traces for session %s", session
->name
);
84 /* Getting userspace traces */
85 cds_list_for_each_entry(ust_iter
, &session
->ust_traces
, list
) {
86 trace
.type
= USERSPACE
;
87 trace
.pid
= ust_iter
->pid
;
88 strncpy(trace
.name
, ust_iter
->name
, sizeof(trace
.name
));
89 trace
.name
[sizeof(trace
.name
) - 1] = '\0';
90 memcpy(&traces
[i
], &trace
, sizeof(trace
));
91 memset(&trace
, 0, sizeof(trace
));
95 DBG("Getting kernel traces for session %s", session
->name
);
97 /* Getting kernel traces */
98 cds_list_for_each_entry(kern_iter
, &session
->kernel_traces
, list
) {
100 strncpy(trace
.name
, kern_iter
->name
, sizeof(trace
.name
));
101 trace
.name
[sizeof(trace
.name
) - 1] = '\0';
102 memcpy(&traces
[i
], &trace
, sizeof(trace
));
103 memset(&trace
, 0, sizeof(trace
));
111 * Create an userspace trace using pid.
112 * This trace is then appended to the current session
115 int ust_create_trace(struct command_ctx
*cmd_ctx
)
118 struct ltt_ust_trace
*trace
;
120 DBG("Creating trace for pid %d", cmd_ctx
->lsm
->pid
);
122 trace
= malloc(sizeof(struct ltt_ust_trace
));
130 trace
->pid
= cmd_ctx
->lsm
->pid
;
132 /* NOTE: to be removed. Trace name will no longer be
133 * required for LTTng userspace tracer. For now, we set it
134 * to 'auto' for API compliance.
136 snprintf(trace
->name
, 5, "auto");
138 ret
= ustctl_create_trace(cmd_ctx
->ust_sock
, trace
->name
);
140 ret
= LTTCOMM_CREATE_FAIL
;
144 /* Check if current session is valid */
145 if (cmd_ctx
->session
) {
146 cds_list_add(&trace
->list
, &cmd_ctx
->session
->ust_traces
);
147 cmd_ctx
->session
->ust_trace_count
++;
161 * Start a trace. This trace, identified by the pid, must be
162 * in the current session ust_traces list.
164 int ust_start_trace(struct command_ctx
*cmd_ctx
)
167 struct ltt_ust_trace
*trace
;
169 DBG("Starting trace for pid %d", cmd_ctx
->lsm
->pid
);
171 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
173 ret
= LTTCOMM_NO_TRACE
;
177 ret
= ustctl_start_trace(cmd_ctx
->ust_sock
, "auto");
179 ret
= LTTCOMM_START_FAIL
;
192 * Stop a trace. This trace, identified by the pid, must be
193 * in the current session ust_traces list.
195 int ust_stop_trace(struct command_ctx
*cmd_ctx
)
198 struct ltt_ust_trace
*trace
;
200 DBG("Stopping trace for pid %d", cmd_ctx
->lsm
->pid
);
202 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
204 ret
= LTTCOMM_NO_TRACE
;
208 ret
= ustctl_stop_trace(cmd_ctx
->ust_sock
, trace
->name
);
210 ret
= LTTCOMM_STOP_FAIL
;
This page took 0.034731 seconds and 5 git commands to generate.