xref: /original-bsd/usr.bin/gprof/hertz.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)hertz.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include <sys/time.h>
13 
14     /*
15      *	discover the tick frequency of the machine
16      *	if something goes wrong, we return 0, an impossible hertz.
17      */
18 #define	HZ_WRONG	0
19 
20 hertz()
21 {
22 	struct itimerval tim;
23 
24 	tim.it_interval.tv_sec = 0;
25 	tim.it_interval.tv_usec = 1;
26 	tim.it_value.tv_sec = 0;
27 	tim.it_value.tv_usec = 0;
28 	setitimer(ITIMER_REAL, &tim, 0);
29 	setitimer(ITIMER_REAL, 0, &tim);
30 	if (tim.it_interval.tv_usec < 2)
31 		return(HZ_WRONG);
32 	return (1000000 / tim.it_interval.tv_usec);
33 }
34