Blame gprof/hertz.c

Packit bbfece
/*
Packit bbfece
 * Copyright (c) 1983, 1993
Packit bbfece
 *      The Regents of the University of California.  All rights reserved.
Packit bbfece
 *
Packit bbfece
 * Redistribution and use in source and binary forms, with or without
Packit bbfece
 * modification, are permitted provided that the following conditions
Packit bbfece
 * are met:
Packit bbfece
 * 1. Redistributions of source code must retain the above copyright
Packit bbfece
 *    notice, this list of conditions and the following disclaimer.
Packit bbfece
 * 2. Redistributions in binary form must reproduce the above copyright
Packit bbfece
 *    notice, this list of conditions and the following disclaimer in the
Packit bbfece
 *    documentation and/or other materials provided with the distribution.
Packit bbfece
 * 3. Neither the name of the University nor the names of its contributors
Packit bbfece
 *    may be used to endorse or promote products derived from this software
Packit bbfece
 *    without specific prior written permission.
Packit bbfece
 *
Packit bbfece
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit bbfece
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit bbfece
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit bbfece
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit bbfece
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit bbfece
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit bbfece
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit bbfece
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit bbfece
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit bbfece
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit bbfece
 * SUCH DAMAGE.
Packit bbfece
 */
Packit bbfece
#include "gprof.h"
Packit bbfece
#include "hertz.h"
Packit bbfece
Packit bbfece
Packit bbfece
int
Packit bbfece
hertz (void)
Packit bbfece
{
Packit bbfece
#ifdef HERTZ
Packit bbfece
  return HERTZ;
Packit bbfece
#else /* ! defined (HERTZ) */
Packit bbfece
#ifdef HAVE_SETITIMER
Packit bbfece
  struct itimerval tim;
Packit bbfece
Packit bbfece
  tim.it_interval.tv_sec = 0;
Packit bbfece
  tim.it_interval.tv_usec = 1;
Packit bbfece
  tim.it_value.tv_sec = 0;
Packit bbfece
  tim.it_value.tv_usec = 0;
Packit bbfece
  setitimer (ITIMER_REAL, &tim, 0);
Packit bbfece
  setitimer (ITIMER_REAL, 0, &tim);
Packit bbfece
  if (tim.it_interval.tv_usec >= 2)
Packit bbfece
    {
Packit bbfece
      return 1000000 / tim.it_interval.tv_usec;
Packit bbfece
    }
Packit bbfece
#endif /* ! defined (HAVE_SETITIMER) */
Packit bbfece
#if defined (HAVE_SYSCONF) && defined (_SC_CLK_TCK)
Packit bbfece
  return sysconf (_SC_CLK_TCK);
Packit bbfece
#else /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
Packit bbfece
#ifdef __MSDOS__
Packit bbfece
  return 18;
Packit bbfece
#else  /* ! defined (__MSDOS__) */
Packit bbfece
  return HZ_WRONG;
Packit bbfece
#endif /* ! defined (__MSDOS__) */
Packit bbfece
#endif /* ! defined (HAVE_SYSCONF) || ! defined (_SC_CLK_TCK) */
Packit bbfece
#endif /* ! defined (HERTZ) */
Packit bbfece
}