1*3d8817e4Smiod /*
2*3d8817e4Smiod * Copyright (c) 1983, 1993
3*3d8817e4Smiod * The Regents of the University of California. All rights reserved.
4*3d8817e4Smiod *
5*3d8817e4Smiod * Redistribution and use in source and binary forms, with or without
6*3d8817e4Smiod * modification, are permitted provided that the following conditions
7*3d8817e4Smiod * are met:
8*3d8817e4Smiod * 1. Redistributions of source code must retain the above copyright
9*3d8817e4Smiod * notice, this list of conditions and the following disclaimer.
10*3d8817e4Smiod * 2. Redistributions in binary form must reproduce the above copyright
11*3d8817e4Smiod * notice, this list of conditions and the following disclaimer in the
12*3d8817e4Smiod * documentation and/or other materials provided with the distribution.
13*3d8817e4Smiod * 3. Neither the name of the University nor the names of its contributors
14*3d8817e4Smiod * may be used to endorse or promote products derived from this software
15*3d8817e4Smiod * without specific prior written permission.
16*3d8817e4Smiod *
17*3d8817e4Smiod * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*3d8817e4Smiod * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*3d8817e4Smiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*3d8817e4Smiod * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*3d8817e4Smiod * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*3d8817e4Smiod * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*3d8817e4Smiod * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*3d8817e4Smiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*3d8817e4Smiod * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*3d8817e4Smiod * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*3d8817e4Smiod * SUCH DAMAGE.
28*3d8817e4Smiod */
29*3d8817e4Smiod #include "gprof.h"
30*3d8817e4Smiod #include "hertz.h"
31*3d8817e4Smiod
32*3d8817e4Smiod
33*3d8817e4Smiod int
hertz()34*3d8817e4Smiod hertz ()
35*3d8817e4Smiod {
36*3d8817e4Smiod #ifdef HERTZ
37*3d8817e4Smiod return HERTZ;
38*3d8817e4Smiod #else /* ! defined (HERTZ) */
39*3d8817e4Smiod #ifdef HAVE_SETITIMER
40*3d8817e4Smiod struct itimerval tim;
41*3d8817e4Smiod
42*3d8817e4Smiod tim.it_interval.tv_sec = 0;
43*3d8817e4Smiod tim.it_interval.tv_usec = 1;
44*3d8817e4Smiod tim.it_value.tv_sec = 0;
45*3d8817e4Smiod tim.it_value.tv_usec = 0;
46*3d8817e4Smiod setitimer (ITIMER_REAL, &tim, 0);
47*3d8817e4Smiod setitimer (ITIMER_REAL, 0, &tim);
48*3d8817e4Smiod if (tim.it_interval.tv_usec >= 2)
49*3d8817e4Smiod {
50*3d8817e4Smiod return 1000000 / tim.it_interval.tv_usec;
51*3d8817e4Smiod }
52*3d8817e4Smiod #endif /* ! defined (HAVE_SETITIMER) */
53*3d8817e4Smiod #if defined (HAVE_SYSCONF) && defined (_SC_CLK_TCK)
54*3d8817e4Smiod return sysconf (_SC_CLK_TCK);
55*3d8817e4Smiod #else /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
56*3d8817e4Smiod #ifdef __MSDOS__
57*3d8817e4Smiod return 18;
58*3d8817e4Smiod #else /* ! defined (__MSDOS__) */
59*3d8817e4Smiod return HZ_WRONG;
60*3d8817e4Smiod #endif /* ! defined (__MSDOS__) */
61*3d8817e4Smiod #endif /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
62*3d8817e4Smiod #endif /* ! defined (HERTZ) */
63*3d8817e4Smiod }
64