Example #1
0
ktap_eventdef_info *ktapc_parse_events(const char *eventdef)
{
	char *str = strdup(eventdef);
	char *sys, *event, *filter, *next;
	ktap_eventdef_info *evdef_info;
	int ret;

	idmap_init();

 parse_next_eventdef:
	next = get_next_eventdef(str);

	if (get_sys_event_filter_str(str, &sys, &event, &filter))
		goto error;

	verbose_printf("parse_eventdef: sys[%s], event[%s], filter[%s]\n",
		       sys, event, filter);

	if (!strcmp(sys, "probe"))
		ret = parse_events_add_probe(event);
	else if (!strcmp(sys, "sdt"))
		ret = parse_events_add_sdt(event);
	else
		ret = parse_events_add_tracepoint(sys, event);

	if (ret)
		goto error;

	/* don't trace ftrace:function when all tracepoints enabled */
	if (!strcmp(sys, "*"))
		idmap_clear(1);


	if (filter && *next != '\0') {
		fprintf(stderr, "Error: eventdef only can append one filter\n");
		goto error;
	}

	str = next;
	if (*next != '\0')
		goto parse_next_eventdef;

	evdef_info = malloc(sizeof(*evdef_info));
	if (!evdef_info)
		goto error;

	evdef_info->nr = id_nr;
	evdef_info->id_arr = get_id_array();
	evdef_info->filter = filter;

	idmap_free();
	return evdef_info;
 error:
	idmap_free();
	cleanup_event_resources();
	return NULL;
}
Example #2
0
File: main.c Project: cfregly/ktap
int main(int argc, char **argv)
{
	char **ktapvm_argv;
	int new_index, i;
	int ret;

	if (argc == 1)
		usage("");

	parse_option(argc, argv);

	if (oneline_src[0] != '\0')
		script_file = "one-liner";

	compile(script_file);

	ktapvm_argv = (char **)malloc(sizeof(char *)*(script_args_end -
					script_args_start + 1));
	if (!ktapvm_argv) {
		fprintf(stderr, "canno allocate ktapvm_argv\n");
		return -1;
	}

	ktapvm_argv[0] = malloc(strlen(script_file) + 1);
	if (!ktapvm_argv[0]) {
		fprintf(stderr, "canno allocate memory\n");
		return -1;
	}
	strcpy(ktapvm_argv[0], script_file);
	ktapvm_argv[0][strlen(script_file)] = '\0';

	/* pass rest argv into ktapvm */
	new_index = 1;
	for (i = script_args_start; i < script_args_end; i++) {
		ktapvm_argv[new_index] = malloc(strlen(argv[i]) + 1);
		if (!ktapvm_argv[new_index]) {
			fprintf(stderr, "canno allocate memory\n");
			return -1;
		}
		strcpy(ktapvm_argv[new_index], argv[i]);
		ktapvm_argv[new_index][strlen(argv[i])] = '\0';
		new_index++;
	}

	uparm.argv = ktapvm_argv;
	uparm.argc = new_index;
	uparm.verbose = verbose;
	uparm.trace_pid = trace_pid;
	uparm.trace_cpu = trace_cpu;
	uparm.print_timestamp = print_timestamp;

	/* start running into kernel ktapvm */
	ret = run_ktapvm();

	cleanup_event_resources();
	return ret;
}