xref: /original-bsd/usr.bin/gprof/hertz.c (revision 4c01ad61)
1 #ifndef lint
2     static	char *sccsid = "@(#)hertz.c	1.4 (Berkeley) 03/24/85";
3 #endif lint
4 
5 #include <sys/time.h>
6 
7     /*
8      *	discover the tick frequency of the machine
9      *	if something goes wrong, we return 0, an impossible hertz.
10      */
11 #define	HZ_WRONG	0
12 
13 hertz()
14 {
15 	struct itimerval tim;
16 
17 	tim.it_interval.tv_sec = 0;
18 	tim.it_interval.tv_usec = 1;
19 	tim.it_value.tv_sec = 0;
20 	tim.it_value.tv_usec = 0;
21 	setitimer(ITIMER_REAL, &tim, 0);
22 	setitimer(ITIMER_REAL, 0, &tim);
23 	if (tim.it_interval.tv_usec < 2)
24 		return(HZ_WRONG);
25 	return (1000000 / tim.it_interval.tv_usec);
26 }
27