update from rfg
[unix-history] / usr / src / usr.bin / gprof / hertz.c
CommitLineData
c0bc4ef7
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
551f2768 7#ifndef lint
c0bc4ef7
DF
8static char sccsid[] = "@(#)hertz.c 5.1 (Berkeley) %G%";
9#endif not lint
551f2768 10
39bd51fe
KM
11#include <sys/time.h>
12
551f2768
PK
13 /*
14 * discover the tick frequency of the machine
648db063 15 * if something goes wrong, we return 0, an impossible hertz.
551f2768 16 */
648db063 17#define HZ_WRONG 0
10ac51bc 18
551f2768
PK
19hertz()
20{
39bd51fe 21 struct itimerval tim;
551f2768 22
39bd51fe
KM
23 tim.it_interval.tv_sec = 0;
24 tim.it_interval.tv_usec = 1;
25 tim.it_value.tv_sec = 0;
26 tim.it_value.tv_usec = 0;
27 setitimer(ITIMER_REAL, &tim, 0);
28 setitimer(ITIMER_REAL, 0, &tim);
29 if (tim.it_interval.tv_usec < 2)
30 return(HZ_WRONG);
31 return (1000000 / tim.it_interval.tv_usec);
551f2768 32}