示例#1
0
void perf_pretty_print_event(FILE *fff, int fd, int original_pid,
				struct perf_event_attr *pe,
				pid_t pid, int cpu,
				int group_fd, unsigned long flags) {

	fprintf(fff,"/* fd = %d */\n",fd);
	perf_pretty_print_attr(fff,pe,fd);

	fprintf(fff,"\tfd[%d]=perf_event_open(&pe[%d],\n",fd,fd);

	if (pid==original_pid) fprintf(fff,"\t\t\t\tgetpid(), /* current thread */\n");
	else {
		fprintf(fff,"\t\t\t\t%d, ",pid);

		if (pid==0) fprintf(fff,"/* current thread */\n");
		else if (pid==-1) fprintf(fff,"/* all processes */\n");
		else fprintf(fff,"/* Only pid %d */\n",pid);
	}

	fprintf(fff,"\t\t\t\t%d, ",cpu);
	if (cpu>=0) fprintf(fff,"/* Only cpu %d */\n",cpu);
	else if (cpu==-1) fprintf(fff,"/* all cpus */\n");
	else fprintf(fff,"/* Unknown setting? */\n");

	if (group_fd==-1) {
		fprintf(fff,"\t\t\t\t-1, /* New Group Leader */\n");
	}
	else {
		fprintf(fff,"\t\t\t\tfd[%d], /* %d is group leader */\n",
			group_fd,group_fd);
	}

	fprintf(fff,"\t\t\t\t");
	perf_pretty_print_flags(fff,flags);
	fprintf(fff," /*%lx*/ ",flags);

	fprintf(fff,");\n");


	fprintf(fff,"\n");

}
示例#2
0
void trash_random_mmap(void) {

	int i,value;

	stats.mmap_trash_attempts++;

	i=find_random_active_mmap();

	/* Exit if no events */
	if (i<0) return;

//	printf("Found %d %p\n",i,mmaps[i].addr);

	value=rand();

	if (ignore_but_dont_skip.trash_mmap) return;

	/* can't write high pages? */
	//event_data[i].mmap_size);

//	*(event_data[i].mmap)=0xff;

//	printf("Attempting to trash %p: ",mmaps[i].addr);
//	mmap_print_prot(mmaps[i].prot);
//	mmap_print_flags(mmaps[i].flags);
//	printf("\n");

	/* If not writable then we segfault */
	if (!(mmaps[i].prot & PROT_WRITE)) {
//		printf("trash: Not writable, skipping\n");
		return;
	}

	if ( (mmaps[i].aux) && (mmaps[i].prot&PROT_WRITE)) {
//		printf("trash: writable aux, skipping\n");
		return;
	}

	/* Before we attempt to write the mmap, setup a signal handler */
	signal(SIGSEGV, sigsegv_handler);

	/* Save state before the memset */
	/* If the memset segfaults then we will skip it */
	if (!sigsetjmp(j_buf, 1)) {
		memset(mmaps[i].addr,value, 1);//getpagesize());
	}
	else {
		printf("Memset of mmap#%d at %p caused segfault!\n",i,mmaps[i].addr);
		perf_pretty_print_mmap_flags(mmaps[i].flags);
		perf_pretty_print_mmap_prot(mmaps[i].prot);
		printf("size %d fd %d\n",mmaps[i].size,mmaps[i].fd);
		printf("event: cpu=%d pid=%d group_fd=%d flags=%ld ",
			event_data[mmaps[i].which_event].cpu,
			event_data[mmaps[i].which_event].pid,
			event_data[mmaps[i].which_event].group_fd,
			event_data[mmaps[i].which_event].flags
			);
		perf_pretty_print_attr(stdout,
			&event_data[mmaps[i].which_event].attr,
			mmaps[i].fd);
	}

	/* Disable the seigsegv handler */
	signal(SIGSEGV, SIG_DFL);

	if (logging&TYPE_TRASH_MMAP) {
		sprintf(log_buffer,"Q %d %d %d\n",
			value,
			getpagesize(),
			mmaps[i].fd);
		write(log_fd,log_buffer,strlen(log_buffer));
	}

	stats.mmap_trash_successful++;

//	printf("Done trashing\n");
}