xref: /csrg-svn/usr.bin/gprof/hertz.c (revision 34199)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)hertz.c	5.2 (Berkeley) 05/05/88";
15 #endif /* not lint */
16 
17 #include <sys/time.h>
18 
19     /*
20      *	discover the tick frequency of the machine
21      *	if something goes wrong, we return 0, an impossible hertz.
22      */
23 #define	HZ_WRONG	0
24 
25 hertz()
26 {
27 	struct itimerval tim;
28 
29 	tim.it_interval.tv_sec = 0;
30 	tim.it_interval.tv_usec = 1;
31 	tim.it_value.tv_sec = 0;
32 	tim.it_value.tv_usec = 0;
33 	setitimer(ITIMER_REAL, &tim, 0);
34 	setitimer(ITIMER_REAL, 0, &tim);
35 	if (tim.it_interval.tv_usec < 2)
36 		return(HZ_WRONG);
37 	return (1000000 / tim.it_interval.tv_usec);
38 }
39