xref: /openbsd-src/gnu/usr.bin/binutils/gprof/hertz.c (revision c074d1c999f3e07019cd5e9a2f190b057ef3b935)
12159047fSniklas /*
2*c074d1c9Sdrahn  * Copyright (c) 1983, 1993
36e421504Sfgsch  *      The Regents of the University of California.  All rights reserved.
42159047fSniklas  *
56e421504Sfgsch  * Redistribution and use in source and binary forms, with or without
66e421504Sfgsch  * modification, are permitted provided that the following conditions
76e421504Sfgsch  * are met:
86e421504Sfgsch  * 1. Redistributions of source code must retain the above copyright
96e421504Sfgsch  *    notice, this list of conditions and the following disclaimer.
106e421504Sfgsch  * 2. Redistributions in binary form must reproduce the above copyright
116e421504Sfgsch  *    notice, this list of conditions and the following disclaimer in the
126e421504Sfgsch  *    documentation and/or other materials provided with the distribution.
136e421504Sfgsch  * 3. Neither the name of the University nor the names of its contributors
146e421504Sfgsch  *    may be used to endorse or promote products derived from this software
156e421504Sfgsch  *    without specific prior written permission.
166e421504Sfgsch  *
176e421504Sfgsch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
186e421504Sfgsch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
196e421504Sfgsch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
206e421504Sfgsch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
216e421504Sfgsch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
226e421504Sfgsch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
236e421504Sfgsch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
246e421504Sfgsch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
256e421504Sfgsch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
266e421504Sfgsch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
276e421504Sfgsch  * SUCH DAMAGE.
282159047fSniklas  */
29*c074d1c9Sdrahn #include "gprof.h"
302159047fSniklas #include "hertz.h"
312159047fSniklas 
322159047fSniklas 
332159047fSniklas int
hertz()342159047fSniklas hertz ()
352159047fSniklas {
362159047fSniklas #ifdef HERTZ
372159047fSniklas   return HERTZ;
384361b62eSniklas #else /* ! defined (HERTZ) */
394361b62eSniklas #ifdef HAVE_SETITIMER
402159047fSniklas   struct itimerval tim;
412159047fSniklas 
422159047fSniklas   tim.it_interval.tv_sec = 0;
432159047fSniklas   tim.it_interval.tv_usec = 1;
442159047fSniklas   tim.it_value.tv_sec = 0;
452159047fSniklas   tim.it_value.tv_usec = 0;
462159047fSniklas   setitimer (ITIMER_REAL, &tim, 0);
472159047fSniklas   setitimer (ITIMER_REAL, 0, &tim);
48b305b0f1Sespie   if (tim.it_interval.tv_usec >= 2)
492159047fSniklas     {
502159047fSniklas       return 1000000 / tim.it_interval.tv_usec;
51b305b0f1Sespie     }
52b305b0f1Sespie #endif /* ! defined (HAVE_SETITIMER) */
534361b62eSniklas #if defined (HAVE_SYSCONF) && defined (_SC_CLK_TCK)
544361b62eSniklas   return sysconf (_SC_CLK_TCK);
554361b62eSniklas #else /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
56b305b0f1Sespie #ifdef __MSDOS__
57b305b0f1Sespie   return 18;
58b305b0f1Sespie #else  /* ! defined (__MSDOS__) */
594361b62eSniklas   return HZ_WRONG;
60b305b0f1Sespie #endif /* ! defined (__MSDOS__) */
614361b62eSniklas #endif /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
624361b62eSniklas #endif /* ! defined (HERTZ) */
632159047fSniklas }
64