xref: /csrg-svn/usr.bin/gprof/hertz.c (revision 34199)
121961Sdist /*
221961Sdist  * Copyright (c) 1983 Regents of the University of California.
3*34199Sbostic  * All rights reserved.
4*34199Sbostic  *
5*34199Sbostic  * Redistribution and use in source and binary forms are permitted
6*34199Sbostic  * provided that this notice is preserved and that due credit is given
7*34199Sbostic  * to the University of California at Berkeley. The name of the University
8*34199Sbostic  * may not be used to endorse or promote products derived from this
9*34199Sbostic  * software without specific prior written permission. This software
10*34199Sbostic  * is provided ``as is'' without express or implied warranty.
1121961Sdist  */
1221961Sdist 
1310247Speter #ifndef lint
14*34199Sbostic static char sccsid[] = "@(#)hertz.c	5.2 (Berkeley) 05/05/88";
15*34199Sbostic #endif /* not lint */
1610247Speter 
1718500Smckusick #include <sys/time.h>
1818500Smckusick 
1910247Speter     /*
2010247Speter      *	discover the tick frequency of the machine
2115909Speter      *	if something goes wrong, we return 0, an impossible hertz.
2210247Speter      */
2315909Speter #define	HZ_WRONG	0
2415906Speter 
2510247Speter hertz()
2610247Speter {
2718500Smckusick 	struct itimerval tim;
2810247Speter 
2918500Smckusick 	tim.it_interval.tv_sec = 0;
3018500Smckusick 	tim.it_interval.tv_usec = 1;
3118500Smckusick 	tim.it_value.tv_sec = 0;
3218500Smckusick 	tim.it_value.tv_usec = 0;
3318500Smckusick 	setitimer(ITIMER_REAL, &tim, 0);
3418500Smckusick 	setitimer(ITIMER_REAL, 0, &tim);
3518500Smckusick 	if (tim.it_interval.tv_usec < 2)
3618500Smckusick 		return(HZ_WRONG);
3718500Smckusick 	return (1000000 / tim.it_interval.tv_usec);
3810247Speter }
39