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