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"
33 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
34 struct ltt_session
*session
, pid_t pid
);
37 * find_session_ust_trace_by_pid
39 * Iterate over the session ust_traces and
40 * return a pointer or NULL if not found.
42 static struct ltt_ust_trace
*find_session_ust_trace_by_pid(
43 struct ltt_session
*session
, pid_t pid
)
45 struct ltt_ust_trace
*iter
;
47 cds_list_for_each_entry(iter
, &session
->ust_traces
, list
) {
48 if (iter
->pid
== pid
) {
58 * get_trace_count_per_session
60 * Return the total count of traces (ust and kernel)
61 * for the specified session.
63 int get_trace_count_per_session(struct ltt_session
*session
)
65 return session
->ust_trace_count
+ session
->kern_trace_count
;
69 * get_traces_per_session
71 * Fill the lttng_trace array of all the
72 * available trace of the session.
74 void get_traces_per_session(struct ltt_session
*session
, struct lttng_trace
*traces
)
77 struct ltt_ust_trace
*ust_iter
;
78 struct ltt_kernel_trace
*kern_iter
;
79 struct lttng_trace trace
;
81 DBG("Getting userspace traces for session %s", session
->name
);
83 /* Getting userspace traces */
84 cds_list_for_each_entry(ust_iter
, &session
->ust_traces
, list
) {
85 trace
.type
= USERSPACE
;
86 trace
.pid
= ust_iter
->pid
;
87 strncpy(trace
.name
, ust_iter
->name
, sizeof(trace
.name
));
88 trace
.name
[sizeof(trace
.name
) - 1] = '\0';
89 memcpy(&traces
[i
], &trace
, sizeof(trace
));
90 memset(&trace
, 0, sizeof(trace
));
94 DBG("Getting kernel traces for session %s", session
->name
);
96 /* Getting kernel traces */
97 cds_list_for_each_entry(kern_iter
, &session
->kernel_traces
, list
) {
99 strncpy(trace
.name
, kern_iter
->name
, sizeof(trace
.name
));
100 trace
.name
[sizeof(trace
.name
) - 1] = '\0';
101 memcpy(&traces
[i
], &trace
, sizeof(trace
));
102 memset(&trace
, 0, sizeof(trace
));
110 * Create an userspace trace using pid.
111 * This trace is then appended to the current session
114 int ust_create_trace(int sock
, pid_t pid
)
117 struct ltt_ust_trace
*trace
;
119 DBG("Creating trace for pid %d", pid
);
121 trace
= malloc(sizeof(struct ltt_ust_trace
));
131 /* NOTE: to be removed. Trace name will no longer be
132 * required for LTTng userspace tracer. For now, we set it
133 * to 'auto' for API compliance.
135 snprintf(trace
->name
, 5, "auto");
137 ret
= ustctl_create_trace(sock
, trace
->name
);
139 ret
= LTTCOMM_CREATE_FAIL
;
143 /* Check if current session is valid */
144 if (current_session
) {
145 cds_list_add(&trace
->list
, ¤t_session
->ust_traces
);
146 current_session
->ust_trace_count
++;
160 * Start a trace. This trace, identified by the pid, must be
161 * in the current session ust_traces list.
163 int ust_start_trace(int sock
, pid_t pid
)
166 struct ltt_ust_trace
*trace
;
168 DBG("Starting trace for pid %d", pid
);
170 trace
= find_session_ust_trace_by_pid(current_session
, pid
);
172 ret
= LTTCOMM_NO_TRACE
;
176 ret
= ustctl_start_trace(sock
, "auto");
178 ret
= LTTCOMM_START_FAIL
;
189 * Stop a trace. This trace, identified by the pid, must be
190 * in the current session ust_traces list.
192 int ust_stop_trace(int sock
, pid_t pid
)
195 struct ltt_ust_trace
*trace
;
197 DBG("Stopping trace for pid %d", pid
);
199 trace
= find_session_ust_trace_by_pid(current_session
, pid
);
201 ret
= LTTCOMM_NO_TRACE
;
205 ret
= ustctl_stop_trace(sock
, trace
->name
);
207 ret
= LTTCOMM_STOP_FAIL
;
This page took 0.035099 seconds and 5 git commands to generate.