Example #1
0
void report_simple_stat(struct selfish_data *sd)
{
	int i;
	struct selfish_rec *sr;

	printf("# cpuid detour[%%] mean[usec] niterated nrecorded \n");
	for (i = 0; i < sd->nth; i++) {
		analyze(sd, i);

		sr = sd->srs[i];

		printf("%2d %lf %lf %lu %d\n", i,
		       sr->sum * 100.0 / (double)sr->elapsed,
		       ticks2usec(sd, sr->mean),
		       sr->niterated,
		       sr->nrecorded
		       );
	}
}
Example #2
0
static void parse_event() {
	int i = 0;
	int tick = 0;
	int ctick = 0;
	int tempo = 500000;
	unsigned long ts, tu;
	struct timeval tp;
	
	gettimeofday(&tp, NULL);
	ts = tp.tv_sec;
	tu = tp.tv_usec;
	
	while(TRUE) {
		/* pause / stop check */
		if (cmd_stop) {
			break;
		}
		
		if (cmd_pause) {
			gettimeofday(&tp, NULL);
			ts = tp.tv_sec;
			tu = tp.tv_usec;
			usleep(50*1000);
			continue;
		}
		
		while(tick == midi->event[i].ctime) {
			/* delta wait */
			if (ctick != midi->event[i].ctime) {
				int delta, stime;
				
				delta = midi->event[i].ctime - ctick;
				stime = ticks2usec(delta, midi->division, tempo) - myflush();
				if (stime > 0) {
					long j;
					struct timespec ttmp, *req;
					
					req = &ttmp;
					req->tv_sec = (time_t)stime / 1000000;
					req->tv_nsec = (long)(stime % 1000000) * 1000;
					nanosleep(req, NULL);
					
					gettimeofday(&tp, NULL);
					j = (tp.tv_sec * 1000000 + tp.tv_usec) - (ts * 1000000 + tu);
					if (j != stime) {
						extratime += (j - stime);
					}
				} else {
					gettimeofday(&tp, NULL);
					extratime +=  -stime;
				}
				ts = tp.tv_sec;
				tu = tp.tv_usec;
				ctick = midi->event[i].ctime;
			}
			if (midi->event[i].type == 0) {
				/* ordinary data */
				mywrite(midi->event[i].data, midi->event[i].n, midi->event[i].port);
				i++;
			} else if (midi->event[i].type == 2) {
				/* tempo change */
				int *p;
				p = (int*)midi->event[i].data;
				tempo = (unsigned int)*p;
				i++;
			} else if (midi->event[i].type == 3) {
				/* system35 maker */
				int vn1 = midi->event[i+1].data[2];
				int vn2 = midi->event[i+2].data[2];
				int vn3 = midi->event[i+3].data[2];
				
				switch(vn1) {
				case 0:
					/* set label */
					i += 6;
					break;
				case 1:
					/* jump */
					mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					i = midi->sys35_label[vn2];
					ctick = tick = midi->event[i].ctime;
					break;
				case 2:
					/* set flag */
					flags->midi_flag[vn2] = vn3;
					i += 6;
					break;
				case 3:
					/* flag jump */
					if (flags->midi_flag[vn2] == 1) {
						i = midi->sys35_label[vn3];
						ctick = 
						tick = midi->event[i].ctime;
						mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					} else {
						i += 6;
					}
					break;
				case 4:
					/* set variable */
					flags->midi_variable[vn2] = vn3;
					i += 6;
					break;
				case 5:
					/* variable jump */
					if (--(flags->midi_variable[vn2]) == 0) {
						i = midi->sys35_label[vn3];
						ctick =
						tick  = midi->event[i].ctime;
						mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					} else {
						i += 6;
					}
					break;
				}
			} else {
				WARNING("Unknown type of event %x (NEVER!).\n", midi->event[i].type);
			}
			if (i >= midi->eventsize) return;
		}
		tick++;
	}
}