Blame gprof/hertz.c

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