extern int lttng_list_sessions(struct lttng_session **sessions);
extern void lttng_set_current_session_uuid(char *uuid);
extern int lttng_ust_create_trace(pid_t pid);
+extern int lttng_ust_start_trace(pid_t pid);
#endif /* _LIBLTTNGCTL_H */
return lttcomm_get_readable_code(code);
}
+/*
+ * lttng_ust_start_trace
+ *
+ * Request a trace start for pid.
+ */
+int lttng_ust_start_trace(pid_t pid)
+{
+ int ret;
+
+ lsm.pid = pid;
+ ret = ask_sessiond(UST_START_TRACE, NULL);
+
+ return ret;
+}
+
/*
* lttng_ust_create_trace
*
[ LTTCOMM_ERR_INDEX(LTTCOMM_LIST_FAIL) ] = "Unable to list traceable apps",
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found",
+ [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACE) ] = "No trace found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon",
[ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed",
LTTCOMM_LIST_FAIL, /* Listing apps fail */
LTTCOMM_NO_APPS, /* No traceable application */
LTTCOMM_NO_SESS, /* No sessions available */
+ LTTCOMM_NO_TRACE, /* No trace exist */
LTTCOMM_FATAL, /* Session daemon had a fatal error */
LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */
LTTCOMM_SELECT_SESS, /* Must select a session */
return ret;
}
+/*
+ * ust_start_trace
+ *
+ * Start a trace. This trace, identified by the pid, must be
+ * in the current session ust_traces list.
+ */
+static int ust_start_trace(pid_t pid)
+{
+ int sock, ret;
+ struct ltt_ust_trace *trace;
+
+ DBG("Starting trace for pid %d", pid);
+
+ trace = find_session_ust_trace_by_pid(current_session, pid);
+ if (trace == NULL) {
+ ret = LTTCOMM_NO_TRACE;
+ goto error;
+ }
+
+ /* Connect to app using ustctl API */
+ sock = connect_app(pid);
+ if (sock < 0) {
+ ret = LTTCOMM_NO_TRACEABLE;
+ goto error;
+ }
+
+ ret = ustctl_start_trace(sock, "auto");
+ if (ret < 0) {
+ ret = LTTCOMM_START_FAIL;
+ goto error;
+ }
+
+error:
+ return ret;
+}
+
/*
* copy_common_data
*
{
ret = ust_create_trace(lsm->pid);
if (ret < 0) {
- ret = LTTCOMM_CREATE_FAIL;
+ /* If -1 is returned from ust_create_trace, malloc
+ * failed so it's pretty much a fatal error.
+ */
+ ret = LTTCOMM_FATAL;
goto end;
}
break;
}
+ case UST_START_TRACE:
+ {
+ ret = ust_start_trace(lsm->pid);
+
+ /* No auxiliary data so only send the llm struct. */
+ goto end;
+ }
case LTTNG_LIST_SESSIONS:
{
unsigned int session_count = get_session_count();
}
if (opt_session_uuid != NULL) {
+ DBG("Set session uuid to %s", opt_session_uuid);
lttng_set_current_session_uuid(opt_session_uuid);
}
MSG("Trace created successfully!\nUse --start PID to start tracing.");
}
+ if (opt_start_trace) {
+ DBG("Start trace for pid %d", opt_start_trace);
+ ret = lttng_ust_start_trace(opt_start_trace);
+ if (ret < 0) {
+ goto end;
+ }
+ MSG("Trace started successfully!");
+ }
+
return 0;
end:
static int validate_options(void)
{
if ((opt_session_uuid == NULL) &&
- (opt_create_trace)) {
- ERR("Can't create trace without a session ID.\nPlease specify using --session UUID");
+ (opt_create_trace || opt_start_trace)) {
+ ERR("Can't act on trace without a session ID.\nPlease specify using --session UUID");
goto error;
}
*/
static void sighandler(int sig)
{
- DBG("%d received", sig);
switch (sig) {
case SIGTERM:
+ DBG("SIGTERM catched");
clean_exit(EXIT_FAILURE);
break;
case SIGCHLD:
/* Notify is done */
+ DBG("SIGCHLD catched");
break;
default:
+ DBG("Unknown signal %d catched", sig);
break;
}
extern int opt_no_sessiond;
extern int opt_list_session;
extern pid_t opt_create_trace;
-
-#define SESSIOND_PATH_NUM 6
+extern pid_t opt_start_trace;
#endif /* _LTTNG_H */
int opt_no_sessiond = 0;
int opt_list_session = 0;
pid_t opt_create_trace = 0;
+pid_t opt_start_trace = 0;
enum {
OPT_HELP = 42,
{"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0, 0},
{"session", 's', POPT_ARG_STRING, &opt_session_uuid, 0, 0, 0},
{"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0, 0},
+ {"start", 0, POPT_ARG_INT, &opt_start_trace, 0, 0, 0},
{"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0, 0},
//{"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
//fprintf(ofp, " --no-kernel Disable kernel tracing\n");
fprintf(ofp, " -L, --list-apps List traceable UST applications\n");
fprintf(ofp, " -C, --create-trace PID Create trace for PID\n");
+ fprintf(ofp, " --start PID Start trace for PID\n");
fprintf(ofp, "\n");
fprintf(ofp, "Please see the lttng(1) man page for full documentation.\n");
fprintf(ofp, "See http://lttng.org/ust for updates, bug reports and news.\n");