Cleanup comments and bad indent
[lttng-tools.git] / ltt-sessiond / ust-ctl.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
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
7 * of the License.
8 *
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.
13 *
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.
17 */
18
19 #define _GNU_SOURCE
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include <lttng-sessiond-comm.h>
27 #include "lttngerr.h"
28 #include "ust-ctl.h"
29
30 #ifdef DISABLED
31 /*
32 * find_session_ust_trace_by_pid
33 *
34 * Iterate over the session ust_traces and
35 * return a pointer or NULL if not found.
36 */
37 static struct ltt_ust_trace *find_session_ust_trace_by_pid(
38 struct ltt_session *session, pid_t pid)
39 {
40 struct ltt_ust_trace *iter;
41
42 cds_list_for_each_entry(iter, &session->ust_traces, list) {
43 if (iter->pid == pid) {
44 /* Found */
45 return iter;
46 }
47 }
48
49 return NULL;
50 }
51
52 /*
53 * get_trace_count_per_session
54 *
55 * Return the total count of traces (ust and kernel)
56 * for the specified session.
57 */
58 int get_trace_count_per_session(struct ltt_session *session)
59 {
60 return session->ust_trace_count;
61 }
62
63 /*
64 * get_traces_per_session
65 *
66 * Fill the lttng_trace array of all the
67 * available trace of the session.
68 */
69 /*
70 void get_traces_per_session(struct ltt_session *session, struct lttng_trace *traces)
71 {
72 int i = 0;
73 struct ltt_ust_trace *ust_iter;
74 struct lttng_trace trace;
75
76 DBG("Getting userspace traces for session %s", session->name);
77
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));
85 i++;
86 }
87
88 DBG("Getting kernel traces for session %s", session->name);
89
90 if (session->kern_session_count > 0) {
91 trace.type = KERNEL;
92 strncpy(trace.name, "kernel", sizeof(trace.name));
93 trace.name[sizeof(trace.name) - 1] = '\0';
94 memcpy(&traces[i], &trace, sizeof(trace));
95 }
96 }
97 */
98
99 /*
100 * ust_create_trace
101 *
102 * Create an userspace trace using pid.
103 * This trace is then appended to the current session
104 * ust trace list.
105 */
106 int ust_create_trace(struct command_ctx *cmd_ctx)
107 {
108 int ret;
109 struct ltt_ust_trace *trace;
110
111 DBG("Creating trace for pid %d", cmd_ctx->lsm->pid);
112
113 trace = malloc(sizeof(struct ltt_ust_trace));
114 if (trace == NULL) {
115 perror("malloc");
116 ret = -1;
117 goto error;
118 }
119
120 /* Init */
121 trace->pid = cmd_ctx->lsm->pid;
122 trace->shmid = 0;
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.
126 */
127 snprintf(trace->name, 5, "auto");
128
129 ret = ustctl_create_trace(cmd_ctx->ust_sock, trace->name);
130 if (ret < 0) {
131 ret = LTTCOMM_CREATE_FAIL;
132 goto error_create;
133 }
134
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++;
139 }
140
141 return LTTCOMM_OK;
142
143 error_create:
144 free(trace);
145 error:
146 return ret;
147 }
148
149 /*
150 * ust_start_trace
151 *
152 * Start a trace. This trace, identified by the pid, must be
153 * in the current session ust_traces list.
154 */
155 int ust_start_trace(struct command_ctx *cmd_ctx)
156 {
157 int ret;
158 struct ltt_ust_trace *trace;
159
160 DBG("Starting trace for pid %d", cmd_ctx->lsm->pid);
161
162 trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
163 if (trace == NULL) {
164 ret = LTTCOMM_NO_TRACE;
165 goto error;
166 }
167
168 ret = ustctl_start_trace(cmd_ctx->ust_sock, "auto");
169 if (ret < 0) {
170 ret = LTTCOMM_START_FAIL;
171 goto error;
172 }
173
174 ret = LTTCOMM_OK;
175
176 error:
177 return ret;
178 }
179
180 /*
181 * ust_stop_trace
182 *
183 * Stop a trace. This trace, identified by the pid, must be
184 * in the current session ust_traces list.
185 */
186 int ust_stop_trace(struct command_ctx *cmd_ctx)
187 {
188 int ret;
189 struct ltt_ust_trace *trace;
190
191 DBG("Stopping trace for pid %d", cmd_ctx->lsm->pid);
192
193 trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid);
194 if (trace == NULL) {
195 ret = LTTCOMM_NO_TRACE;
196 goto error;
197 }
198
199 ret = ustctl_stop_trace(cmd_ctx->ust_sock, trace->name);
200 if (ret < 0) {
201 ret = LTTCOMM_STOP_FAIL;
202 goto error;
203 }
204
205 ret = LTTCOMM_OK;
206
207 error:
208 return ret;
209 }
210 #endif
211
This page took 0.034535 seconds and 4 git commands to generate.