Esempio n. 1
0
LTTNG_HIDDEN
int mi_lttng_event_function_entry(struct mi_writer *writer,
		struct lttng_event *event)
{
	int ret;

	ret = mi_lttng_writer_open_element(writer, config_element_attributes);
	if (ret) {
		goto end;
	}

	ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
	if (ret) {
		goto end;
	}

	/* event probe symbol_name */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_symbol_name, event->attr.ftrace.symbol_name);
	if (ret) {
		goto end;
	}

	/* Close function_attributes and attributes */
	ret = mi_lttng_close_multi_element(writer, 2);
end:
	return ret;
}
Esempio n. 2
0
LTTNG_HIDDEN
int mi_lttng_snapshot_output_session_name(struct mi_writer *writer,
		const char *session_name)
{
	int ret;

	/* Open session element */
	ret = mi_lttng_writer_open_element(writer, config_element_session);
	if (ret) {
		goto end;
	}

	/* Snapshot output list for current session name */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			session_name);
	if (ret) {
		goto end;
	}

	/* Open element snapshots (sequence one snapshot) */
	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots);
	if (ret) {
		goto end;
	}

end:
	return ret;
}
Esempio n. 3
0
static
int mi_lttng_app_context(struct mi_writer *writer,
		const char *provider_name, const char *ctx_name)
{
	int ret;

	/* Open app */
	ret = mi_lttng_writer_open_element(writer,
			config_element_context_app);
	if (ret) {
		goto end;
	}

	/* provider_name */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_context_app_provider_name,
			provider_name);
	if (ret) {
		goto end;
	}

	/* ctx_name */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_context_app_ctx_name, ctx_name);
	if (ret) {
		goto end;
	}

	/* Close app */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 4
0
LTTNG_HIDDEN
int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
		int is_open)
{
	int ret;

	/* Open element pid */
	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_pid);
	if (ret) {
		goto end;
	}

	/* Writing pid number */
	ret = mi_lttng_writer_write_element_signed_int(writer,
			mi_lttng_element_pid_id, (int)pid);
	if (ret) {
		goto end;
	}

	/* Writing name of the process */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			cmdline);
	if (ret) {
		goto end;
	}

	if (!is_open) {
		/* Closing Pid */
		ret = mi_lttng_writer_close_element(writer);
	}

end:
	return ret;
}
Esempio n. 5
0
/*
 * Mi print of partial session
 */
static int mi_print_session(char *session_name, int enabled)
{
	int ret;
	assert(writer);
	assert(session_name);

	/* Open session element */
	ret = mi_lttng_writer_open_element(writer, config_element_session);
	if (ret) {
		goto end;
	}

	/* Print session name element */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			session_name);
	if (ret) {
		goto end;
	}

	/* Is enabled ? */
	ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled,
			enabled);
	if (ret) {
		goto end;
	}

	/* Close session element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 6
0
/*
 * Mi print exlcusion list
 */
static
int mi_print_exclusion(char **names)
{
	int i, ret;
	int count = names ? strutils_array_of_strings_len(names) : 0;

	assert(writer);

	if (count == 0) {
		ret = 0;
		goto end;
	}
	ret = mi_lttng_writer_open_element(writer, config_element_exclusions);
	if (ret) {
		goto end;
	}

	for (i = 0; i < count; i++) {
		ret = mi_lttng_writer_write_element_string(writer,
				config_element_exclusion, names[i]);
		if (ret) {
			goto end;
		}
	}

	/* Close exclusions element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 7
0
LTTNG_HIDDEN
int mi_lttng_session(struct mi_writer *writer,
		struct lttng_session *session, int is_open)
{
	int ret;

	assert(session);

	/* Open sessions element */
	ret = mi_lttng_writer_open_element(writer,
			config_element_session);
	if (ret) {
		goto end;
	}

	/* Name of the session */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, session->name);
	if (ret) {
		goto end;
	}

	/* Path */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_path, session->path);
	if (ret) {
		goto end;
	}

	/* Enabled ? */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_enabled, session->enabled);
	if (ret) {
		goto end;
	}

	/* Snapshot mode */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			config_element_snapshot_mode, session->snapshot_mode);
	if (ret) {
		goto end;
	}

	/* Live timer interval in usec */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			config_element_live_timer_interval,
			session->live_timer_interval);
	if (ret) {
		goto end;
	}

	if (!is_open) {
		/* Closing session element */
		ret = mi_lttng_writer_close_element(writer);
	}
end:
	return ret;

}
Esempio n. 8
0
LTTNG_HIDDEN
int mi_lttng_event_function_probe(struct mi_writer *writer,
		struct lttng_event *event)
{
	int ret;

	ret = mi_lttng_writer_open_element(writer, config_element_attributes);
	if (ret) {
		goto end;
	}

	ret = mi_lttng_writer_open_element(writer, config_element_probe_attributes);
	if (ret) {
		goto end;
	}

	if (event->attr.probe.addr != 0) {
		/* event probe address */
		ret = mi_lttng_writer_write_element_unsigned_int(writer,
				config_element_address, event->attr.probe.addr);
		if (ret) {
			goto end;
		}
	} else {
		/* event probe offset */
		ret = mi_lttng_writer_write_element_unsigned_int(writer,
				config_element_offset, event->attr.probe.offset);
		if (ret) {
			goto end;
		}

		/* event probe symbol_name */
		ret = mi_lttng_writer_write_element_string(writer,
				config_element_symbol_name, event->attr.probe.symbol_name);
		if (ret) {
			goto end;
		}
	}

	/* Close probe_attributes and attributes */
	ret = mi_lttng_close_multi_element(writer, 2);
end:
	return ret;
}
Esempio n. 9
0
LTTNG_HIDDEN
int mi_lttng_snapshot_add_output(struct mi_writer *writer,
		const char *current_session_name, const char *n_ptr,
		struct lttng_snapshot_output *output)
{
	int ret;

	/* Open element snapshot */
	ret = mi_lttng_writer_open_element(writer,
			mi_lttng_element_command_snapshot);
	if (ret) {
		goto end;
	}

	/* Snapshot output id */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			mi_lttng_element_id, output->id);
	if (ret) {
		goto end;
	}

	/* Snapshot output names */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, n_ptr);
	if (ret) {
		goto end;
	}

	/* Destination of the output (ctrl_url)*/
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
	if (ret) {
		goto end;
	}

	/* Snapshot added for session "current_session_name"*/
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_snapshot_session_name, current_session_name);
	if (ret) {
		goto end;
	}

	/* total size of all stream combined */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			mi_lttng_element_snapshot_max_size, output->max_size);
	if (ret) {
		goto end;
	}

	/* Close snapshot element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 10
0
LTTNG_HIDDEN
int mi_lttng_snapshot_list_output(struct mi_writer *writer,
		struct lttng_snapshot_output *output)
{
	int ret;

	/* Open element snapshot output */
	ret = mi_lttng_writer_open_element(writer,
			mi_lttng_element_command_snapshot);
	if (ret) {
		goto end;
	}

	/* ID of the snapshot output */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			mi_lttng_element_id, output->id);
	if (ret) {
		goto end;
	}

	/* Name of the output */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			output->name);
	if (ret) {
		goto end;
	}

	/* Destination of the output (ctrl_url)*/
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
	if (ret) {
		goto end;
	}

	/* Destination of the output (data_url) */
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_snapshot_data_url, output->data_url);
	if (ret) {
		goto end;
	}

	/* total size of all stream combined */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			mi_lttng_element_snapshot_max_size, output->max_size);
	if (ret) {
		goto end;
	}

	/* Close snapshot output element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 11
0
LTTNG_HIDDEN
int mi_lttng_event_common_attributes(struct mi_writer *writer,
		struct lttng_event *event)
{
	int ret;
	const char *filter_expression;

	/* Open event element */
	ret = mi_lttng_writer_open_element(writer, config_element_event);
	if (ret) {
		goto end;
	}

	/* Event name */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, event->name);
	if (ret) {
		goto end;
	}

	/* Event type */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_type, mi_lttng_eventtype_string(event->type));
	if (ret) {
		goto end;
	}

	/* Is event enabled */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_enabled, event->enabled);
	if (ret) {
		goto end;
	}

	/* Event filter expression */
	ret = lttng_event_get_filter_expression(event, &filter_expression);
	if (ret) {
		goto end;
	}

	if (filter_expression) {
		ret = mi_lttng_writer_write_element_string(writer,
				config_element_filter_expression,
				filter_expression);
		if (ret) {
			goto end;
		}
	}

end:
	return ret;
}
Esempio n. 12
0
LTTNG_HIDDEN
int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command)
{
	int ret;

	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_command);
	if (ret) {
		goto end;
	}
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_command_name, command);
end:
	return ret;
}
Esempio n. 13
0
LTTNG_HIDDEN
int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id,
		const char *name, const char *current_session_name)
{
	int ret;

	/* Open element del_snapshot */
	ret = mi_lttng_writer_open_element(writer,
			mi_lttng_element_command_snapshot);
	if (ret) {
		goto end;
	}


	if (id != UINT32_MAX) {
		/* "Snapshot output "id" successfully deleted
		 * for "current_session_name"
		 * ID of the snapshot output
		 */
		ret = mi_lttng_writer_write_element_unsigned_int(writer,
				mi_lttng_element_id, id);
		if (ret) {
			goto end;
		}
	} else {
		/* "Snapshot output "name" successfully deleted
		 * for session "current_session_name"
		 * Name of the output
		 */
		ret = mi_lttng_writer_write_element_string(writer, config_element_name,
				name);
		if (ret) {
			goto end;
		}
	}

	/* Snapshot was deleted for session "current_session_name"*/
	ret = mi_lttng_writer_write_element_string(writer,
			mi_lttng_element_snapshot_session_name,
			current_session_name);
	if (ret) {
		goto end;
	}

	/* Close snapshot element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 14
0
LTTNG_HIDDEN
int mi_lttng_event_field(struct mi_writer *writer,
		struct lttng_event_field *field)
{
	int ret;

	if (!field->field_name[0]) {
		ret = 0;
		goto end;
	}

	/* Open field */
	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_event_field);
	if (ret) {
		goto end;
	}

	if (!field->field_name[0]) {
		goto close;
	}

	/* Name */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			field->field_name);
	if (ret) {
		goto end;
	}

	/* Type */
	ret = mi_lttng_writer_write_element_string(writer, config_element_type,
			mi_lttng_eventfieldtype_string(field->type));
	if (ret) {
		goto end;
	}

	/* nowrite  */
	ret = mi_lttng_writer_write_element_signed_int(writer,
			mi_lttng_element_nowrite, field->nowrite);
	if (ret) {
		goto end;
	}

close:
	/* Close field element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 15
0
LTTNG_HIDDEN
int mi_lttng_pid_tracker_open(struct mi_writer *writer)
{
	int ret;

	/* Open element pid_tracker */
	ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker);
	if (ret) {
		goto end;
	}

	/* Open targets element */
	ret = mi_lttng_targets_open(writer);
end:
	return ret;
}
Esempio n. 16
0
LTTNG_HIDDEN
int mi_lttng_context(struct mi_writer *writer,
		struct lttng_event_context *context, int is_open)
{
	int ret;
	const char *type_string;
	struct lttng_event_perf_counter_ctx *perf_context;
	/* Open context */
	ret = mi_lttng_writer_open_element(writer , config_element_context);
	if (ret) {
		goto end;
	}

	type_string = mi_lttng_event_contexttype_string(context->ctx);
	if (!type_string) {
		ret = -LTTNG_ERR_INVALID;
		goto end;
	}

	/* Print context type */
	ret = mi_lttng_writer_write_element_string(writer, config_element_type,
			type_string);

	/* Special case for PERF_*_COUNTER
	 * print the lttng_event_perf_counter_ctx*/
	switch (context->ctx) {
	case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
	case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER:
	case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
		perf_context = &context->u.perf_counter;
		ret =  mi_lttng_perf_counter_context(writer, perf_context);
		if (ret) {
			goto end;
		}
		break;
	default:
		break;
	}

	/* Close context */
	if (!is_open) {
		ret = mi_lttng_writer_close_element(writer);
	}

end:
	return ret;
}
Esempio n. 17
0
LTTNG_HIDDEN
int mi_lttng_domain(struct mi_writer *writer,
		struct lttng_domain *domain, int is_open)
{
	int ret = 0;
	const char *str_domain;
	const char *str_buffer;

	assert(domain);

	/* Open domain element */
	ret = mi_lttng_writer_open_element(writer, config_element_domain);
	if (ret) {
		goto end;
	}

	/* Domain Type */
	str_domain = mi_lttng_domaintype_string(domain->type);
	ret = mi_lttng_writer_write_element_string(writer, config_element_type,
			str_domain);
	if (ret) {
		goto end;
	}

	/* Buffer Type */
	str_buffer= mi_lttng_buffertype_string(domain->buf_type);
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_buffer_type, str_buffer);
	if (ret) {
		goto end;
	}

	/* TODO: union  attr
	 * This union is not currently used and was added for
	 * future ust domain support.
	 * Date: 25-06-2014
	 * */

	if (!is_open) {
		/* Closing domain element */
		ret = mi_lttng_writer_close_element(writer);
	}

end:
	return ret;

}
Esempio n. 18
0
LTTNG_HIDDEN
int mi_lttng_snapshot_record(struct mi_writer *writer,
		const char *current_session_name, const char *url,
		const char *cmdline_ctrl_url, const char *cmdline_data_url)
{
	int ret;

	/* Open element snapshot */
	ret = mi_lttng_writer_open_element(writer,
			mi_lttng_element_command_snapshot);
	if (ret) {
		goto end;
	}

	/*
	 * If a valid an URL was given, serialize it,
	 * else take the command line data and ctrl urls*/
	if (url) {
		/* Destination of the output (ctrl_url)*/
		ret = mi_lttng_writer_write_element_string(writer,
				mi_lttng_element_snapshot_ctrl_url, url);
		if (ret) {
			goto end;
		}
	} else if (cmdline_ctrl_url) {
		/* Destination of the output (ctrl_url)*/
		ret = mi_lttng_writer_write_element_string(writer,
				mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url);
		if (ret) {
			goto end;
		}

		/* Destination of the output (data_url) */
		ret = mi_lttng_writer_write_element_string(writer,
				mi_lttng_element_snapshot_data_url, cmdline_data_url);
		if (ret) {
			goto end;
		}
	}

	/* Close record_snapshot element */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 19
0
LTTNG_HIDDEN
int mi_lttng_channel(struct mi_writer *writer,
		struct lttng_channel *channel, int is_open)
{
	int ret = 0;

	assert(channel);

	/* Opening channel element */
	ret = mi_lttng_writer_open_element(writer, config_element_channel);
	if (ret) {
		goto end;
	}

	/* Name */
	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			channel->name);
	if (ret) {
		goto end;
	}

	/* Enabled ? */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_enabled, channel->enabled);
	if (ret) {
		goto end;
	}

	/* Attribute */
	ret = mi_lttng_channel_attr(writer, &channel->attr);
	if (ret) {
		goto end;
	}

	if (!is_open) {
		/* Closing channel element */
		ret = mi_lttng_writer_close_element(writer);
		if (ret) {
			goto end;
		}
	}
end:
	return ret;
}
Esempio n. 20
0
static int write_event_exclusions(struct mi_writer *writer,
		struct lttng_event *event)
{
	int i;
	int ret;
	int exclusion_count;

	/* Open event exclusions */
	ret = mi_lttng_writer_open_element(writer, config_element_exclusions);
	if (ret) {
		goto end;
	}

	exclusion_count = lttng_event_get_exclusion_name_count(event);
	if (exclusion_count < 0) {
		ret = exclusion_count;
		goto end;
	}

	for (i = 0; i < exclusion_count; i++) {
		const char *name;

		ret = lttng_event_get_exclusion_name(event, i, &name);
		if (ret) {
			/* Close exclusions */
			mi_lttng_writer_close_element(writer);
			goto end;
		}

		ret = mi_lttng_writer_write_element_string(writer,
				config_element_exclusion, name);
		if (ret) {
			/* Close exclusions */
			mi_lttng_writer_close_element(writer);
			goto end;
		}
	}

	/* Close exclusions */
	ret = mi_lttng_writer_close_element(writer);

end:
	return ret;
}
Esempio n. 21
0
LTTNG_HIDDEN
int mi_lttng_event_common_attributes(struct mi_writer *writer,
		struct lttng_event *event)
{
	int ret;

	/* Open event element */
	ret = mi_lttng_writer_open_element(writer, config_element_event);
	if (ret) {
		goto end;
	}

	/* Event name */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, event->name);
	if (ret) {
		goto end;
	}

	/* Event type */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_type, mi_lttng_eventtype_string(event->type));
	if (ret) {
		goto end;
	}

	/* Is event enabled */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_enabled, event->enabled);
	if (ret) {
		goto end;
	}

	/* Event filter enabled? */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_filter, event->filter);

end:
	return ret;
}
Esempio n. 22
0
LTTNG_HIDDEN
int mi_lttng_perf_counter_context(struct mi_writer *writer,
		struct lttng_event_perf_counter_ctx  *perf_context)
{
	int ret;

	/* Open perf_counter_context */
	ret = mi_lttng_writer_open_element(writer,
			mi_lttng_element_perf_counter_context);
	if (ret) {
		goto end;
	}

	/* Type */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			config_element_type, perf_context->type);
	if (ret) {
		goto end;
	}

	/* Config */
	ret = mi_lttng_writer_write_element_unsigned_int(writer,
			config_element_config, perf_context->config);
	if (ret) {
		goto end;
	}

	/* Name of the perf counter */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, perf_context->name);
	if (ret) {
		goto end;
	}

	/* Close perf_counter_context */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 23
0
/* Mi print a partial event.
 * enabled is 0 or 1
 * success is 0 or 1
 */
static int mi_print_event(char *event_name, int enabled, int success)
{
	int ret;

	assert(writer);
	assert(event_name);

	/* Open event element */
	ret = mi_lttng_writer_open_element(writer, config_element_event);
	if (ret) {
		goto end;
	}

	/* Print the name of event */
	ret = mi_lttng_writer_write_element_string(writer,
			config_element_name, event_name);
	if (ret) {
		goto end;
	}

	/* Print enabled ? */
	ret = mi_lttng_writer_write_element_bool(writer,
			config_element_enabled, enabled);
	if (ret) {
		goto end;
	}

	/* Success ? */
	ret = mi_lttng_writer_write_element_bool(writer,
			mi_lttng_element_command_success, success);
	if (ret) {
		goto end;
	}

	/* Close event element */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 24
0
static int mi_partial_session(const char *session_name)
{
	int ret;
	assert(writer);
	assert(session_name);

	/* Open session element */
	ret = mi_lttng_writer_open_element(writer, config_element_session);
	if (ret) {
		goto end;
	}

	ret = mi_lttng_writer_write_element_string(writer, config_element_name,
			session_name);
	if (ret) {
		goto end;
	}

	/* Closing session element */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 25
0
/*
 * Print the necessary mi for a session and name.
 */
static int mi_print(char *session_name)
{
	int ret;

	assert(writer);
	assert(session_name);

	/*
	 * Open a sessions element
	 * This is purely for validation purpose
	 */
	ret = mi_lttng_sessions_open(writer);
	if (ret) {
		goto end;
	}

	/* Open a session element */
	ret = mi_lttng_writer_open_element(writer, config_element_session);
	if (ret) {
		goto end;
	}

	/* Session name */
	ret = mi_lttng_writer_write_element_string(writer , config_element_name,
			session_name);
	if (ret) {
		goto end;
	}

	/* Close session and sessions element */
	ret = mi_lttng_close_multi_element(writer, 2);
	if (ret) {
		goto end;
	}
end:
	return ret;
}
Esempio n. 26
0
LTTNG_HIDDEN
int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open)
{
	int ret;

	ret = mi_lttng_writer_open_element(writer,
			config_element_target_pid);
	if (ret) {
		goto end;
	}

	/* Writing pid number
	 * Special case for element all on track untrack command
	 * All pid is represented as wildcard *
	 */
	if ((int) pid == -1) {
		ret = mi_lttng_writer_write_element_string(writer,
				config_element_pid,
				mi_lttng_element_track_untrack_all_wildcard);
	} else {
		ret = mi_lttng_writer_write_element_signed_int(writer,
				config_element_pid, (int) pid);
	}
	if (ret) {
		goto end;
	}

	if (!is_open) {
		ret = mi_lttng_writer_close_element(writer);
		if (ret) {
			goto end;
		}
	}

end:
	return ret;
}
Esempio n. 27
0
/*
 * Mi print of save command
 */
static int mi_save_print(const char *session_name)
{
	int ret;
	assert(writer);

	if (opt_save_all) {
		/* We use a wildcard to represent all sessions */
		session_name = "*";
	}

	/* Print save element */
	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_save);
	if (ret) {
		goto end;
	}

	/* Print session element */
	ret = mi_partial_session(session_name);
	if (ret) {
		goto end;
	}

	/* Path element */
	if (opt_output_path) {
		ret = mi_lttng_writer_write_element_string(writer, config_element_path,
				opt_output_path);
		if (ret) {
			goto end;
		}
	}

	/* Close save element */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 28
0
LTTNG_HIDDEN
int mi_lttng_calibrate(struct mi_writer *writer,
		struct lttng_calibrate *calibrate)
{
	int ret;

	/* Open calibrate element */
	ret = mi_lttng_writer_open_element(writer, mi_lttng_element_calibrate);
	if (ret) {
		goto end;
	}

	/* Calibration type */
	ret = mi_lttng_writer_write_element_string(writer, config_element_type,
			mi_lttng_calibratetype_string(calibrate->type));
	if (ret) {
		goto end;
	}

	/* Closing calibrate element */
	ret = mi_lttng_writer_close_element(writer);
end:
	return ret;
}
Esempio n. 29
0
/*
 * The 'snapshot <cmd> <options>' first level command
 */
int cmd_snapshot(int argc, const char **argv)
{
	int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
	char *session_name = NULL;
	static poptContext pc;

	pc = poptGetContext(NULL, argc, argv, snapshot_opts, 0);
	poptReadDefaultConfig(pc, 0);

	/* 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_snapshot);
		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;
		}
	}

	while ((opt = poptGetNextOpt(pc)) != -1) {
		switch (opt) {
		case OPT_HELP:
			usage(stdout);
			goto end;
		case OPT_LIST_OPTIONS:
			list_cmd_options(stdout, snapshot_opts);
			goto end;
		case OPT_LIST_COMMANDS:
			list_commands(actions, stdout);
			goto end;
		case OPT_MAX_SIZE:
		{
			uint64_t val;
			const char *opt = poptGetOptArg(pc);

			if (utils_parse_size_suffix((char *) opt, &val) < 0) {
				ERR("Unable to handle max-size value %s", opt);
				ret = CMD_ERROR;
				goto end;
			}

			opt_max_size = val;

			break;
		}
		default:
			usage(stderr);
			ret = CMD_UNDEFINED;
			goto end;
		}
	}

	if (!opt_session_name) {
		session_name = get_session_name();
		if (session_name == NULL) {
			ret = CMD_ERROR;
			goto end;
		}
		current_session_name = session_name;
	} else {
		current_session_name = opt_session_name;
	}

	command_ret = handle_command(poptGetArgs(pc));
	if (command_ret) {
		switch (-command_ret) {
		case LTTNG_ERR_EPERM:
			ERR("The session needs to be set in no output mode (--no-output)");
			break;
		case LTTNG_ERR_SNAPSHOT_NODATA:
			WARN("%s", lttng_strerror(command_ret));
			break;
		default:
			ERR("%s", lttng_strerror(command_ret));
			break;
		}
		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;
	}

	if (!opt_session_name) {
		free(session_name);
	}

	/* Overwrite ret if an error occured during handle_command */
	ret = command_ret ? command_ret : ret;
	poptFreeContext(pc);
	return ret;
}
Esempio n. 30
0
static int handle_command(const char **argv)
{
	int ret = CMD_SUCCESS, i = 0, argc, command_ret =  CMD_SUCCESS;
	struct cmd_struct *cmd;

	if (argv == NULL || (!opt_ctrl_url && opt_data_url) ||
			(opt_ctrl_url && !opt_data_url)) {
		usage(stderr);
		command_ret = CMD_ERROR;
		goto end;
	}

	argc = count_arguments(argv);

	cmd = &actions[i];
	while (cmd->func != NULL) {
		/* Find command */
		if (strcmp(argv[0], cmd->name) == 0) {
			if (lttng_opt_mi) {
				/* Action element */
				ret = mi_lttng_writer_open_element(writer,
						mi_lttng_element_command_action);
				if (ret) {
					ret = CMD_ERROR;
					goto end;
				}

				/* Name of the action */
				ret = mi_lttng_writer_write_element_string(writer,
						config_element_name, argv[0]);
				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 = cmd->func(argc, argv);

			if (lttng_opt_mi) {
				/* Close output and action element */
				ret = mi_lttng_close_multi_element(writer, 2);
				if (ret) {
					ret = CMD_ERROR;
					goto end;
				}
			}
			goto end;
		}
		i++;
		cmd = &actions[i];
	}

	ret = CMD_UNDEFINED;

end:
	/* Overwrite ret if an error occurred in cmd->func() */
	ret = command_ret ? command_ret : ret;
	return ret;
}