/* * The 'view <options>' first level command */ int cmd_view(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); if (lttng_opt_mi) { WARN("mi does not apply to view command"); } while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } } opt_session_name = (char*) poptGetArg(pc); ret = view_trace(); end: poptFreeContext(pc); return ret; }
/* * The 'destroy <options>' first level command */ int cmd_destroy(int argc, const char **argv) { int opt; int ret = CMD_SUCCESS , i, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; const char *leftover = NULL; struct lttng_session *sessions; int count; int found; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); break; default: ret = CMD_UNDEFINED; break; } goto end; } /* Mi preparation */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_destroy); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } /* For validation and semantic purpose we open a sessions element */ ret = mi_lttng_sessions_open(writer); if (ret) { ret = CMD_ERROR; goto end; } } /* Recuperate all sessions for further operation */ count = lttng_list_sessions(&sessions); if (count < 0) { ERR("%s", lttng_strerror(count)); command_ret = CMD_ERROR; success = 0; goto mi_closing; } /* Ignore session name in case all sessions are to be destroyed */ if (opt_destroy_all) { command_ret = destroy_all_sessions(sessions, count); if (command_ret) { success = 0; } } else { opt_session_name = (char *) poptGetArg(pc); if (!opt_session_name) { /* No session name specified, lookup default */ session_name = get_session_name(); if (session_name == NULL) { command_ret = CMD_ERROR; success = 0; goto mi_closing; } } else { session_name = opt_session_name; } /* Find the corresponding lttng_session struct */ found = 0; for (i = 0; i < count; i++) { if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { found = 1; command_ret = destroy_session(&sessions[i]); if (command_ret) { success = 0; } } } if (!found) { ERR("Session name %s not found", session_name); command_ret = LTTNG_ERR_SESS_NOT_FOUND; success = 0; goto mi_closing; } } leftover = poptGetArg(pc); if (leftover) { ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; success = 0; goto mi_closing; } mi_closing: /* Mi closing */ if (lttng_opt_mi) { /* Close sessions and output element element */ ret = mi_lttng_close_multi_element(writer, 2); if (ret) { ret = CMD_ERROR; goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } if (opt_session_name == NULL) { free(session_name); } /* Overwrite ret if an error occurred during destroy_session/all */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
/* * Add event to trace session */ int cmd_enable_events(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; const char *leftover = NULL; int event_type = -1; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); /* Default event type */ opt_event_type = LTTNG_EVENT_ALL; while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_TRACEPOINT: opt_event_type = LTTNG_EVENT_TRACEPOINT; break; case OPT_PROBE: opt_event_type = LTTNG_EVENT_PROBE; break; case OPT_USERSPACE_PROBE: opt_event_type = LTTNG_EVENT_USERSPACE_PROBE; break; case OPT_FUNCTION: opt_event_type = LTTNG_EVENT_FUNCTION; break; case OPT_SYSCALL: opt_event_type = LTTNG_EVENT_SYSCALL; break; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LOGLEVEL: opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; opt_loglevel = poptGetOptArg(pc); break; case OPT_LOGLEVEL_ONLY: opt_loglevel_type = LTTNG_EVENT_LOGLEVEL_SINGLE; opt_loglevel = poptGetOptArg(pc); break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; case OPT_FILTER: break; case OPT_EXCLUDE: break; default: ret = CMD_UNDEFINED; goto end; } /* Validate event type. Multiple event type are not supported. */ if (event_type == -1) { event_type = opt_event_type; } else { if (event_type != opt_event_type) { ERR("Multiple event type not supported."); ret = CMD_ERROR; goto end; } } } ret = print_missing_or_multiple_domains( opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python); if (ret) { ret = CMD_ERROR; goto end; } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_enable_event); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } opt_event_list = (char*) poptGetArg(pc); if (opt_event_list == NULL && opt_enable_all == 0) { ERR("Missing event name(s).\n"); ret = CMD_ERROR; goto end; } leftover = poptGetArg(pc); if (leftover) { ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { command_ret = CMD_ERROR; success = 0; goto mi_closing; } } else { session_name = opt_session_name; } command_ret = enable_events(session_name); if (command_ret) { success = 0; goto mi_closing; } mi_closing: /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; } if (opt_session_name == NULL) { free(session_name); } /* Overwrite ret if an error occurred in enable_events */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
/* * cmd_disable_events * * Disable event to trace session */ int cmd_disable_events(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; int event_type = -1; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); /* Default event type */ opt_event_type = LTTNG_EVENT_ALL; while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_TYPE_SYSCALL: opt_event_type = LTTNG_EVENT_SYSCALL; break; case OPT_TYPE_TRACEPOINT: opt_event_type = LTTNG_EVENT_TRACEPOINT; break; case OPT_TYPE_PROBE: opt_event_type = LTTNG_EVENT_PROBE; break; case OPT_TYPE_FUNCTION: opt_event_type = LTTNG_EVENT_FUNCTION; break; case OPT_TYPE_ALL: opt_event_type = LTTNG_EVENT_ALL; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } /* Validate event type. Multiple event type are not supported. */ if (event_type == -1) { event_type = opt_event_type; } else { if (event_type != opt_event_type) { ERR("Multiple event type not supported."); ret = CMD_ERROR; goto end; } } } ret = print_missing_or_multiple_domains( opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python); if (ret) { ret = CMD_ERROR; goto end; } /* Ust and agent only support ALL event type */ if ((opt_userspace || opt_jul || opt_log4j || opt_python) && opt_event_type != LTTNG_EVENT_ALL) { ERR("Disabling userspace and agent (-j | -l | -p) event(s) based on instrumentation type is not supported.\n"); ret = CMD_ERROR; goto end; } opt_event_list = (char*) poptGetArg(pc); if (opt_event_list == NULL && opt_disable_all == 0) { ERR("Missing event name(s).\n"); ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { ret = CMD_ERROR; goto end; } } else { session_name = opt_session_name; } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_disable_event); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } command_ret = disable_events(session_name); if (command_ret) { success = 0; } /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: if (!opt_session_name && session_name) { free(session_name); } /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; } /* Overwrite ret if an error occurred in disable_events */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
/* * Add/remove tracker to/from session. */ static int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, int argc, const char **argv) { int opt, ret = 0; enum cmd_error_code command_ret = CMD_SUCCESS; int success = 1; static poptContext pc; char *session_name = NULL; struct mi_writer *writer = NULL; if (argc < 1) { command_ret = CMD_ERROR; goto end; } pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; case OPT_SESSION: case OPT_PID: opt_pid = 1; break; default: command_ret = CMD_UNDEFINED; goto end; } } ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); if (ret) { ret = CMD_ERROR; goto end; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { command_ret = CMD_ERROR; goto end; } } else { session_name = opt_session_name; } /* Currently only PID tracker is supported */ if (!opt_pid) { ERR("Please specify at least one tracker with its expected arguments"); command_ret = CMD_ERROR; goto end; } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { command_ret = CMD_ERROR; goto end; } } if (writer) { /* Open command element */ ret = mi_lttng_writer_command_open(writer, get_mi_element_command(cmd_type)); if (ret) { command_ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { command_ret = CMD_ERROR; goto end; } } command_ret = track_untrack_pid(cmd_type, cmd_str, session_name, opt_pid_string, opt_all, writer); if (command_ret != CMD_SUCCESS) { success = 0; } /* Mi closing */ if (writer) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { command_ret = CMD_ERROR; goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { command_ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { command_ret = CMD_ERROR; goto end; } } end: if (!opt_session_name) { free(session_name); } /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ command_ret = CMD_ERROR; } poptFreeContext(pc); return (int) command_ret; }
/* * cmd_stop * * The 'stop <options>' first level command */ int cmd_stop(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; const char *leftover = NULL; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_stop); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } /* * Open sessions element * For validation */ ret = mi_lttng_writer_open_element(writer, config_element_sessions); if (ret) { ret = CMD_ERROR; goto end; } } opt_session_name = (char*) poptGetArg(pc); leftover = poptGetArg(pc); if (leftover) { ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; goto end; } command_ret = stop_tracing(); if (command_ret) { success = 0; } /* Mi closing */ if (lttng_opt_mi) { /* Close sessions and output element */ ret = mi_lttng_close_multi_element(writer, 2); if (ret) { ret = CMD_ERROR; goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } /* Overwrite ret if an error occurred in stop_tracing() */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
/* * The 'create <options>' first level command * * Returns one of the CMD_* result constants. */ int cmd_create(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; char *opt_arg = NULL; const char *leftover = NULL; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; case OPT_LIVE_TIMER: { uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); if (!opt_arg) { /* Set up default values. */ opt_live_timer = (uint32_t) DEFAULT_LTTNG_LIVE_TIMER; DBG("Session live timer interval set to default value %d", opt_live_timer); break; } if (utils_parse_time_suffix(opt_arg, &v) < 0) { ERR("Wrong value for --live parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } if (v != (uint32_t) v) { ERR("32-bit overflow in --live parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } if (v == 0) { ERR("Live timer interval must be greater than zero"); ret = CMD_ERROR; goto end; } opt_live_timer = (uint32_t) v; DBG("Session live timer interval set to %d", opt_live_timer); break; } default: ret = CMD_UNDEFINED; goto end; } } if (opt_no_consumer) { MSG("The option --no-consumer is obsolete. Use --no-output now."); ret = CMD_WARNING; goto end; } ret = validate_url_option_combination(); if (ret) { ret = CMD_ERROR; goto end; } /* Spawn a session daemon if needed */ if (!opt_no_sessiond) { ret = launch_sessiond(); if (ret) { ret = CMD_ERROR; goto end; } } /* MI initialization */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_create); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } opt_session_name = (char*) poptGetArg(pc); leftover = poptGetArg(pc); if (leftover) { ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; goto end; } command_ret = create_session(); if (command_ret) { success = 0; } if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } /* Overwrite ret if an error occurred in create_session() */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }
/* * The 'list <options>' first level command */ int cmd_list(int argc, const char **argv) { int opt, ret = CMD_SUCCESS; const char *session_name; static poptContext pc; struct lttng_domain domain; struct lttng_domain *domains = NULL; memset(&domain, 0, sizeof(domain)); if (argc < 1) { ret = CMD_ERROR; goto end; } pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_USERSPACE: opt_userspace = 1; break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = CMD_ERROR; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_list); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } /* Get session name (trailing argument) */ session_name = poptGetArg(pc); DBG2("Session name: %s", session_name); if (opt_kernel) { domain.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { DBG2("Listing userspace global domain"); domain.type = LTTNG_DOMAIN_UST; } else if (opt_jul) { DBG2("Listing JUL domain"); domain.type = LTTNG_DOMAIN_JUL; } else if (opt_log4j) { domain.type = LTTNG_DOMAIN_LOG4J; } else if (opt_python) { domain.type = LTTNG_DOMAIN_PYTHON; } if (!opt_kernel && opt_syscall) { WARN("--syscall will only work with the Kernel domain (-k)"); ret = CMD_ERROR; goto end; } if (opt_kernel || opt_userspace || opt_jul || opt_log4j || opt_python) { handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { ret = CMD_FATAL; goto end; } } if (session_name == NULL) { if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j && !opt_python) { ret = list_sessions(NULL); if (ret) { goto end; } } if (opt_kernel) { if (opt_syscall) { ret = list_syscalls(); if (ret) { goto end; } } else { ret = list_kernel_events(); if (ret) { goto end; } } } if (opt_userspace) { if (opt_fields) { ret = list_ust_event_fields(); } else { ret = list_ust_events(); } if (ret) { goto end; } } if (opt_jul || opt_log4j || opt_python) { ret = list_agent_events(); if (ret) { goto end; } } } else { /* List session attributes */ if (lttng_opt_mi) { /* Open element sessions * Present for xml consistency */ ret = mi_lttng_sessions_open(writer); if (ret) { goto end; } } /* MI: the ouptut of list_sessions is an unclosed session element */ ret = list_sessions(session_name); if (ret) { goto end; } /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); goto end; } /* Channel listing */ if (opt_kernel || opt_userspace) { if (lttng_opt_mi) { /* Add of domains and domain element for xml * consistency and validation */ ret = mi_lttng_domains_open(writer); if (ret) { goto end; } /* Open domain and leave it open for * nested channels printing */ ret = mi_lttng_domain(writer, &domain, 1); if (ret) { goto end; } } /* Trackers */ ret = list_trackers(); if (ret) { goto end; } /* Channels */ ret = list_channels(opt_channel); if (ret) { goto end; } if (lttng_opt_mi) { /* Close domain and domain element */ ret = mi_lttng_close_multi_element(writer, 2); } if (ret) { goto end; } } else { int i, nb_domain; /* We want all domain(s) */ nb_domain = lttng_list_domains(session_name, &domains); if (nb_domain < 0) { ret = CMD_ERROR; ERR("%s", lttng_strerror(nb_domain)); goto end; } if (lttng_opt_mi) { ret = mi_lttng_domains_open(writer); if (ret) { ret = CMD_ERROR; goto end; } } for (i = 0; i < nb_domain; i++) { switch (domains[i].type) { case LTTNG_DOMAIN_KERNEL: MSG("=== Domain: Kernel ===\n"); break; case LTTNG_DOMAIN_UST: MSG("=== Domain: UST global ===\n"); MSG("Buffer type: %s\n", domains[i].buf_type == LTTNG_BUFFER_PER_PID ? "per PID" : "per UID"); break; case LTTNG_DOMAIN_JUL: MSG("=== Domain: JUL (Java Util Logging) ===\n"); break; case LTTNG_DOMAIN_LOG4J: MSG("=== Domain: LOG4j (Logging for Java) ===\n"); break; case LTTNG_DOMAIN_PYTHON: MSG("=== Domain: Python (logging) ===\n"); break; default: MSG("=== Domain: Unimplemented ===\n"); break; } if (lttng_opt_mi) { ret = mi_lttng_domain(writer, &domains[i], 1); if (ret) { ret = CMD_ERROR; goto end; } } /* Clean handle before creating a new one */ if (handle) { lttng_destroy_handle(handle); } handle = lttng_create_handle(session_name, &domains[i]); if (handle == NULL) { ret = CMD_FATAL; goto end; } if (domains[i].type == LTTNG_DOMAIN_JUL || domains[i].type == LTTNG_DOMAIN_LOG4J || domains[i].type == LTTNG_DOMAIN_PYTHON) { ret = list_session_agent_events(); if (ret) { goto end; } goto next_domain; } switch (domains[i].type) { case LTTNG_DOMAIN_KERNEL: case LTTNG_DOMAIN_UST: ret = list_trackers(); if (ret) { goto end; } break; default: break; } ret = list_channels(opt_channel); if (ret) { goto end; } next_domain: if (lttng_opt_mi) { /* Close domain element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } } } if (lttng_opt_mi) { /* Close the domains, session and sessions element */ ret = mi_lttng_close_multi_element(writer, 3); if (ret) { ret = CMD_ERROR; goto end; } } } } /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { ret = CMD_ERROR; goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { ret = CMD_ERROR; goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; } free(domains); if (handle) { lttng_destroy_handle(handle); } poptFreeContext(pc); return ret; }
/* * Add channel to trace session */ int cmd_enable_channels(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; static poptContext pc; char *session_name = NULL; char *opt_arg = NULL; const char *leftover = NULL; init_channel_config(); pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: SHOW_HELP(); goto end; case OPT_DISCARD: chan_opts.attr.overwrite = 0; DBG("Channel set to discard"); break; case OPT_OVERWRITE: chan_opts.attr.overwrite = 1; DBG("Channel set to overwrite"); break; case OPT_SUBBUF_SIZE: { uint64_t rounded_size; int order; /* Parse the size */ opt_arg = poptGetOptArg(pc); if (utils_parse_size_suffix(opt_arg, &chan_opts.attr.subbuf_size) < 0 || !chan_opts.attr.subbuf_size) { ERR("Wrong value in --subbuf-size parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } order = get_count_order_u64(chan_opts.attr.subbuf_size); assert(order >= 0); rounded_size = 1ULL << order; if (rounded_size < chan_opts.attr.subbuf_size) { ERR("The subbuf size (%" PRIu64 ") is rounded and overflows!", chan_opts.attr.subbuf_size); ret = CMD_ERROR; goto end; } if (rounded_size != chan_opts.attr.subbuf_size) { WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", chan_opts.attr.subbuf_size, rounded_size); chan_opts.attr.subbuf_size = rounded_size; } /* Should now be power of 2 */ assert(!((chan_opts.attr.subbuf_size - 1) & chan_opts.attr.subbuf_size)); DBG("Channel subbuf size set to %" PRIu64, chan_opts.attr.subbuf_size); break; } case OPT_NUM_SUBBUF: { uint64_t rounded_size; int order; errno = 0; opt_arg = poptGetOptArg(pc); chan_opts.attr.num_subbuf = strtoull(opt_arg, NULL, 0); if (errno != 0 || !chan_opts.attr.num_subbuf || !isdigit(opt_arg[0])) { ERR("Wrong value in --num-subbuf parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } order = get_count_order_u64(chan_opts.attr.num_subbuf); assert(order >= 0); rounded_size = 1ULL << order; if (rounded_size < chan_opts.attr.num_subbuf) { ERR("The number of subbuffers (%" PRIu64 ") is rounded and overflows!", chan_opts.attr.num_subbuf); ret = CMD_ERROR; goto end; } if (rounded_size != chan_opts.attr.num_subbuf) { WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", chan_opts.attr.num_subbuf, rounded_size); chan_opts.attr.num_subbuf = rounded_size; } /* Should now be power of 2 */ assert(!((chan_opts.attr.num_subbuf - 1) & chan_opts.attr.num_subbuf)); DBG("Channel subbuf num set to %" PRIu64, chan_opts.attr.num_subbuf); break; } case OPT_SWITCH_TIMER: { uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); if (utils_parse_time_suffix(opt_arg, &v) < 0) { ERR("Wrong value for --switch-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } if (v != (uint32_t) v) { ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } chan_opts.attr.switch_timer_interval = (uint32_t) v; DBG("Channel switch timer interval set to %d %s", chan_opts.attr.switch_timer_interval, USEC_UNIT); break; } case OPT_READ_TIMER: { uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); if (utils_parse_time_suffix(opt_arg, &v) < 0) { ERR("Wrong value for --read-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } if (v != (uint32_t) v) { ERR("32-bit overflow in --read-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } chan_opts.attr.read_timer_interval = (uint32_t) v; DBG("Channel read timer interval set to %d %s", chan_opts.attr.read_timer_interval, USEC_UNIT); break; } case OPT_MONITOR_TIMER: { uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); if (utils_parse_time_suffix(opt_arg, &v) < 0) { ERR("Wrong value for --monitor-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } opt_monitor_timer.interval = (uint64_t) v; opt_monitor_timer.set = true; DBG("Channel monitor timer interval set to %" PRIu64 " %s", opt_monitor_timer.interval, USEC_UNIT); break; } case OPT_BLOCKING_TIMEOUT: { uint64_t v; long long v_msec; errno = 0; opt_arg = poptGetOptArg(pc); if (strcmp(opt_arg, "inf") == 0) { opt_blocking_timeout.value = (int64_t) -1; opt_blocking_timeout.set = true; DBG("Channel blocking timeout set to infinity"); break; } if (utils_parse_time_suffix(opt_arg, &v) < 0) { ERR("Wrong value for --blocking-timeout parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } /* * While LTTng-UST and LTTng-tools will accept a * blocking timeout expressed in µs, the current * tracer implementation relies on poll() which * takes an "int timeout" parameter expressed in * msec. * * Since the error reporting from the tracer is * not precise, we perform this check here to * provide a helpful error message in case of * overflow. * * The setter (liblttng-ctl) also performs an * equivalent check. */ v_msec = v / 1000; if (v_msec != (int32_t) v_msec) { ERR("32-bit milliseconds overflow in --blocking-timeout parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } opt_blocking_timeout.value = (int64_t) v; opt_blocking_timeout.set = true; DBG("Channel blocking timeout set to %" PRId64 " %s%s", opt_blocking_timeout.value, USEC_UNIT, opt_blocking_timeout.value == 0 ? " (non-blocking)" : ""); break; } case OPT_USERSPACE: opt_userspace = 1; break; case OPT_TRACEFILE_SIZE: opt_arg = poptGetOptArg(pc); if (utils_parse_size_suffix(opt_arg, &chan_opts.attr.tracefile_size) < 0) { ERR("Wrong value in --tracefile-size parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } DBG("Maximum tracefile size set to %" PRIu64, chan_opts.attr.tracefile_size); break; case OPT_TRACEFILE_COUNT: { unsigned long v; errno = 0; opt_arg = poptGetOptArg(pc); v = strtoul(opt_arg, NULL, 0); if (errno != 0 || !isdigit(opt_arg[0])) { ERR("Wrong value in --tracefile-count parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } if (v != (uint32_t) v) { ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } chan_opts.attr.tracefile_count = (uint32_t) v; DBG("Maximum tracefile count set to %" PRIu64, chan_opts.attr.tracefile_count); break; } case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; default: ret = CMD_UNDEFINED; goto end; } } ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); if (ret) { ret = CMD_ERROR; goto end; } if (chan_opts.attr.overwrite == 1 && opt_blocking_timeout.set && opt_blocking_timeout.value != 0) { ERR("You cannot specify --overwrite and --blocking-timeout=N, " "where N is different than 0"); ret = CMD_ERROR; goto end; } /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); if (!writer) { ret = -LTTNG_ERR_NOMEM; goto end; } /* Open command element */ ret = mi_lttng_writer_command_open(writer, mi_lttng_element_command_enable_channels); if (ret) { ret = CMD_ERROR; goto end; } /* Open output element */ ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command_output); if (ret) { ret = CMD_ERROR; goto end; } } opt_channels = (char*) poptGetArg(pc); if (opt_channels == NULL) { ERR("Missing channel name.\n"); ret = CMD_ERROR; success = 0; goto mi_closing; } leftover = poptGetArg(pc); if (leftover) { ERR("Unknown argument: %s", leftover); ret = CMD_ERROR; success = 0; goto mi_closing; } if (!opt_session_name) { session_name = get_session_name(); if (session_name == NULL) { command_ret = CMD_ERROR; success = 0; goto mi_closing; } } else { session_name = opt_session_name; } command_ret = enable_channel(session_name); if (command_ret) { success = 0; } mi_closing: /* Mi closing */ if (lttng_opt_mi) { /* Close output element */ ret = mi_lttng_writer_close_element(writer); if (ret) { goto end; } /* Success ? */ ret = mi_lttng_writer_write_element_bool(writer, mi_lttng_element_command_success, success); if (ret) { goto end; } /* Command element close */ ret = mi_lttng_writer_command_close(writer); if (ret) { goto end; } } end: /* Mi clean-up */ if (writer && mi_lttng_writer_destroy(writer)) { /* Preserve original error code */ ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL; } if (!opt_session_name && session_name) { free(session_name); } /* Overwrite ret if an error occurred when enable_channel */ ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; }