global last_dispatch;
global times;

probe glib.main_before_dispatch
{
	if (target() == pid()) {
  		last_dispatch[source] = gettimeofday_us();
 	}
}

probe glib.main_after_dispatch
{
	if (target() == pid()) {
		t = gettimeofday_us();
		s = last_dispatch[source];
		times[source] <<< t - s;
	}
}

probe timer.sec(1), end {
	ansi_clear_screen()
	printf("%30s %10s %10s %10s\n",
	       "Source", "Total (us)", "Count", "Avg (us)")
	foreach(a in times) {
		printf ("%30s %10d %10d %10d\n",
			a, @sum(times[a]), @count(times[a]), @avg(times[a]));
	}
	delete times;
}
