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.
26 #include <ust/ustctl.h>
28 #include "liblttsessiondcomm.h"
30 #include "ltt-sessiond.h"
36 * find_session_ust_trace_by_pid
38 * Iterate over the session ust_traces and
39 * return a pointer or NULL if not found.
41 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
42 struct ltt_session
*session
, pid_t pid
)
44 struct ltt_ust_trace
*iter
;
46 cds_list_for_each_entry(iter
, &session
->ust_traces
, list
) {
47 if (iter
->pid
== pid
) {
57 * get_trace_count_per_session
59 * Return the total count of traces (ust and kernel)
60 * for the specified session.
62 int get_trace_count_per_session(struct ltt_session
*session
)
64 return session
->ust_trace_count
+ session
->kern_session_count
;
68 * get_traces_per_session
70 * Fill the lttng_trace array of all the
71 * available trace of the session.
73 void get_traces_per_session(struct ltt_session
*session
, struct lttng_trace
*traces
)
76 struct ltt_ust_trace
*ust_iter
;
77 struct lttng_trace trace
;
79 DBG("Getting userspace traces for session %s", session
->name
);
81 /* Getting userspace traces */
82 cds_list_for_each_entry(ust_iter
, &session
->ust_traces
, list
) {
83 trace
.type
= USERSPACE
;
84 trace
.pid
= ust_iter
->pid
;
85 strncpy(trace
.name
, ust_iter
->name
, sizeof(trace
.name
));
86 trace
.name
[sizeof(trace
.name
) - 1] = '\0';
87 memcpy(&traces
[i
], &trace
, sizeof(trace
));
88 memset(&trace
, 0, sizeof(trace
));
92 DBG("Getting kernel traces for session %s", session
->name
);
94 /* Getting kernel traces */
95 if (session
->kern_session_count
> 0) {
97 strncpy(trace
.name
, "kernel", 6);
98 memcpy(&traces
[i
], &trace
, sizeof(trace
));
105 * Create an userspace trace using pid.
106 * This trace is then appended to the current session
109 int ust_create_trace(struct command_ctx
*cmd_ctx
)
112 struct ltt_ust_trace
*trace
;
114 DBG("Creating trace for pid %d", cmd_ctx
->lsm
->pid
);
116 trace
= malloc(sizeof(struct ltt_ust_trace
));
124 trace
->pid
= cmd_ctx
->lsm
->pid
;
126 /* NOTE: to be removed. Trace name will no longer be
127 * required for LTTng userspace tracer. For now, we set it
128 * to 'auto' for API compliance.
130 snprintf(trace
->name
, 5, "auto");
132 ret
= ustctl_create_trace(cmd_ctx
->ust_sock
, trace
->name
);
134 ret
= LTTCOMM_CREATE_FAIL
;
138 /* Check if current session is valid */
139 if (cmd_ctx
->session
) {
140 cds_list_add(&trace
->list
, &cmd_ctx
->session
->ust_traces
);
141 cmd_ctx
->session
->ust_trace_count
++;
155 * Start a trace. This trace, identified by the pid, must be
156 * in the current session ust_traces list.
158 int ust_start_trace(struct command_ctx
*cmd_ctx
)
161 struct ltt_ust_trace
*trace
;
163 DBG("Starting trace for pid %d", cmd_ctx
->lsm
->pid
);
165 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
167 ret
= LTTCOMM_NO_TRACE
;
171 ret
= ustctl_start_trace(cmd_ctx
->ust_sock
, "auto");
173 ret
= LTTCOMM_START_FAIL
;
186 * Stop a trace. This trace, identified by the pid, must be
187 * in the current session ust_traces list.
189 int ust_stop_trace(struct command_ctx
*cmd_ctx
)
192 struct ltt_ust_trace
*trace
;
194 DBG("Stopping trace for pid %d", cmd_ctx
->lsm
->pid
);
196 trace
= find_session_ust_trace_by_pid(cmd_ctx
->session
, cmd_ctx
->lsm
->pid
);
198 ret
= LTTCOMM_NO_TRACE
;
202 ret
= ustctl_stop_trace(cmd_ctx
->ust_sock
, trace
->name
);
204 ret
= LTTCOMM_STOP_FAIL
;
This page took 0.036023 seconds and 5 git commands to generate.