#include <stdio.h>
#define BUF_SIZE 20000000

int pos;
int len;
int* buf;

void _init_trace_buffer()
{
	FILE* f;
	len = BUF_SIZE;
	pos = 0;
	buf = (int*) malloc(len * 8);
	f = fopen("trace.out", "w+");
	fclose(f);
}


void _flush_trace_buffer()
{
	FILE* f;
	int i;

	if(pos <= 0) return;
	f = fopen("trace.out", "a+");
	if(f == NULL) {
		fprintf(stderr, "error writing to trace file\n");
		return;
	}
	for(i = 0; i < pos; i += 2) {
		fprintf(f, "%d:%d\n", buf[i], buf[i+1]);
	}
	fclose(f);
	pos = 0;
}

void _inc_count(int counter_index, int path_index)
{
	if(pos >= len)
		_flush_trace_buffer();
	//printf("take path %d in fct %d\n", path_index, counter_index);
	buf[pos++] = counter_index;
	buf[pos++] = path_index;
	/*int* count;
	count = counts[counter_index];
	count[path_index]++;*/
}
