OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [libgloss/] [rx/] [mcount.c] - Diff between revs 207 and 345

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*-
/*-
 * Copyright (c) 1983, 1992, 1993
 * Copyright (c) 1983, 1992, 1993
 *      The Regents of the University of California.  All rights reserved.
 *      The Regents of the University of California.  All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of its contributors
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *    without specific prior written permission.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
/* This file implements a subset of the profiling support functions.
/* This file implements a subset of the profiling support functions.
   It has been copied and adapted from mcount.c, gmon.c and gmon.h in
   It has been copied and adapted from mcount.c, gmon.c and gmon.h in
   the glibc sources.
   the glibc sources.
   Since we do not have access to a timer interrupt in the simulator
   Since we do not have access to a timer interrupt in the simulator
   the histogram and basic block information is not generated.  */
   the histogram and basic block information is not generated.  */
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
 
 
/* Fraction of text space to allocate for histogram counters here, 1/2.  */
/* Fraction of text space to allocate for histogram counters here, 1/2.  */
#define HISTFRACTION    2
#define HISTFRACTION    2
 
 
/* Fraction of text space to allocate for from hash buckets.
/* Fraction of text space to allocate for from hash buckets.
   The value of HASHFRACTION is based on the minimum number of bytes
   The value of HASHFRACTION is based on the minimum number of bytes
   of separation between two subroutine call points in the object code.
   of separation between two subroutine call points in the object code.
   Given MIN_SUBR_SEPARATION bytes of separation the value of
   Given MIN_SUBR_SEPARATION bytes of separation the value of
   HASHFRACTION is calculated as:
   HASHFRACTION is calculated as:
 
 
        HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof (short) - 1);
        HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof (short) - 1);
 
 
   For example, on the VAX, the shortest two call sequence is:
   For example, on the VAX, the shortest two call sequence is:
 
 
        calls   $0,(r0)
        calls   $0,(r0)
        calls   $0,(r0)
        calls   $0,(r0)
 
 
   which is separated by only three bytes, thus HASHFRACTION is
   which is separated by only three bytes, thus HASHFRACTION is
   calculated as:
   calculated as:
 
 
        HASHFRACTION = 3 / (2 * 2 - 1) = 1
        HASHFRACTION = 3 / (2 * 2 - 1) = 1
 
 
   Note that the division above rounds down, thus if MIN_SUBR_FRACTION
   Note that the division above rounds down, thus if MIN_SUBR_FRACTION
   is less than three, this algorithm will not work!
   is less than three, this algorithm will not work!
 
 
   In practice, however, call instructions are rarely at a minimal
   In practice, however, call instructions are rarely at a minimal
   distance.  Hence, we will define HASHFRACTION to be 2 across all
   distance.  Hence, we will define HASHFRACTION to be 2 across all
   architectures.  This saves a reasonable amount of space for
   architectures.  This saves a reasonable amount of space for
   profiling data structures without (in practice) sacrificing
   profiling data structures without (in practice) sacrificing
   any granularity.  */
   any granularity.  */
#define HASHFRACTION    2
#define HASHFRACTION    2
 
 
/* Percent of text space to allocate for tostructs.
/* Percent of text space to allocate for tostructs.
   This is a heuristic; we will fail with a warning when profiling
   This is a heuristic; we will fail with a warning when profiling
   programs with a very large number of very small functions, but
   programs with a very large number of very small functions, but
   that's normally OK.
   that's normally OK.
   2 is probably still a good value for normal programs.
   2 is probably still a good value for normal programs.
   Profiling a test case with 64000 small functions will work if
   Profiling a test case with 64000 small functions will work if
   you raise this value to 3 and link statically (which bloats the
   you raise this value to 3 and link statically (which bloats the
   text size, thus raising the number of arcs expected by the heuristic).  */
   text size, thus raising the number of arcs expected by the heuristic).  */
#define ARCDENSITY      3
#define ARCDENSITY      3
 
 
/* Always allocate at least this many tostructs.  This hides the
/* Always allocate at least this many tostructs.  This hides the
   inadequacy of the ARCDENSITY heuristic, at least for small programs.  */
   inadequacy of the ARCDENSITY heuristic, at least for small programs.  */
#define MINARCS         50
#define MINARCS         50
 
 
/* Maximum number of arcs we want to allow.
/* Maximum number of arcs we want to allow.
   Used to be max representable value of ARCINDEX minus 2, but now
   Used to be max representable value of ARCINDEX minus 2, but now
   that ARCINDEX is a long, that's too large; we don't really want
   that ARCINDEX is a long, that's too large; we don't really want
   to allow a 48 gigabyte table.
   to allow a 48 gigabyte table.
   The old value of 1<<16 wasn't high enough in practice for large C++
   The old value of 1<<16 wasn't high enough in practice for large C++
   programs; will 1<<20 be adequate for long?  FIXME  */
   programs; will 1<<20 be adequate for long?  FIXME  */
#define MAXARCS         (1 << 20)
#define MAXARCS         (1 << 20)
 
 
#define SCALE_1_TO_1    0x10000L
#define SCALE_1_TO_1    0x10000L
 
 
#define GMON_MAGIC      "gmon"  /* Magic cookie.  */
#define GMON_MAGIC      "gmon"  /* Magic cookie.  */
#define GMON_VERSION    1       /* Version number.  */
#define GMON_VERSION    1       /* Version number.  */
 
 
 
 
/* General rounding functions.  */
/* General rounding functions.  */
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
#define ROUNDUP(x, y)   ((((x) + (y) - 1) / (y)) * (y))
#define ROUNDUP(x, y)   ((((x) + (y) - 1) / (y)) * (y))
 
 
struct tostruct
struct tostruct
{
{
  unsigned long selfpc;
  unsigned long selfpc;
  unsigned long count;
  unsigned long count;
  unsigned long link;
  unsigned long link;
};
};
 
 
/* Possible states of profiling.  */
/* Possible states of profiling.  */
enum profiling_state
enum profiling_state
{
{
  GMON_PROF_OFF,
  GMON_PROF_OFF,
  GMON_PROF_ON,
  GMON_PROF_ON,
  GMON_PROF_BUSY,
  GMON_PROF_BUSY,
  GMON_PROF_ERROR
  GMON_PROF_ERROR
};
};
 
 
/* The profiling data structures are housed in this structure.  */
/* The profiling data structures are housed in this structure.  */
struct gmonparam
struct gmonparam
{
{
  enum profiling_state state;
  enum profiling_state state;
  unsigned short *     kcount;
  unsigned short *     kcount;
  unsigned long        kcountsize;
  unsigned long        kcountsize;
  unsigned long *      froms;
  unsigned long *      froms;
  unsigned long        fromssize;
  unsigned long        fromssize;
  struct tostruct *    tos;
  struct tostruct *    tos;
  unsigned long        tossize;
  unsigned long        tossize;
  long                 tolimit;
  long                 tolimit;
  unsigned long        lowpc;
  unsigned long        lowpc;
  unsigned long        highpc;
  unsigned long        highpc;
  unsigned long        textsize;
  unsigned long        textsize;
  unsigned long        hashfraction;
  unsigned long        hashfraction;
  long                 log_hashfraction;
  long                 log_hashfraction;
};
};
 
 
/* Raw header as it appears in the gmon.out file (without padding).
/* Raw header as it appears in the gmon.out file (without padding).
   This header always comes first and is then followed by a series
   This header always comes first and is then followed by a series
   records defined below.  */
   records defined below.  */
struct gmon_hdr
struct gmon_hdr
{
{
  char cookie[4];
  char cookie[4];
  char version[4];
  char version[4];
  char spare[3 * 4];
  char spare[3 * 4];
};
};
 
 
/* Types of records in this file.  */
/* Types of records in this file.  */
typedef enum
typedef enum
{
{
  GMON_TAG_TIME_HIST = 0,
  GMON_TAG_TIME_HIST = 0,
  GMON_TAG_CG_ARC = 1,
  GMON_TAG_CG_ARC = 1,
} GMON_Record_Tag;
} GMON_Record_Tag;
 
 
struct gmon_cg_arc_record
struct gmon_cg_arc_record
{
{
  char tag;                             /* Set to GMON_TAG_CG_ARC.  */
  char tag;                             /* Set to GMON_TAG_CG_ARC.  */
  char from_pc[sizeof (char *)];        /* Address within caller's body.  */
  char from_pc[sizeof (char *)];        /* Address within caller's body.  */
  char self_pc[sizeof (char *)];        /* Address within callee's body.  */
  char self_pc[sizeof (char *)];        /* Address within callee's body.  */
  char count[4];                        /* Number of arc traversals.  */
  char count[4];                        /* Number of arc traversals.  */
};
};
 
 
 
 
/* Forward declarations.  */
/* Forward declarations.  */
void _mcount_internal (unsigned long);
void _mcount_internal (unsigned long);
void _monstartup (unsigned long, unsigned long);
void _monstartup (unsigned long, unsigned long);
void _mcleanup (void);
void _mcleanup (void);
 
 
static struct gmonparam _gmonparam;
static struct gmonparam _gmonparam;
 
 
void
void
_mcount_internal (unsigned long frompc)
_mcount_internal (unsigned long frompc)
{
{
  unsigned long      selfpc = frompc;
  unsigned long      selfpc = frompc;
  unsigned long *    frompcindex;
  unsigned long *    frompcindex;
  struct tostruct *  top;
  struct tostruct *  top;
  struct tostruct *  prevtop;
  struct tostruct *  prevtop;
  struct gmonparam * p;
  struct gmonparam * p;
  unsigned long      toindex;
  unsigned long      toindex;
  int                i;
  int                i;
 
 
  p = & _gmonparam;
  p = & _gmonparam;
 
 
  /* Check that we are profiling and that we aren't recursively invoked.
  /* Check that we are profiling and that we aren't recursively invoked.
     NB/ This version is not thread-safe.  */
     NB/ This version is not thread-safe.  */
  if (p->state != GMON_PROF_ON)
  if (p->state != GMON_PROF_ON)
    return;
    return;
  p->state = GMON_PROF_BUSY;
  p->state = GMON_PROF_BUSY;
 
 
  /* Check that frompcindex is a reasonable pc value.
  /* Check that frompcindex is a reasonable pc value.
     For example: signal catchers get called from the stack,
     For example: signal catchers get called from the stack,
     not from text space.  Too bad.  */
     not from text space.  Too bad.  */
  frompc -= p->lowpc;
  frompc -= p->lowpc;
  if (frompc > p->textsize)
  if (frompc > p->textsize)
    goto done;
    goto done;
 
 
  i = frompc >> p->log_hashfraction;
  i = frompc >> p->log_hashfraction;
 
 
  frompcindex = p->froms + i;
  frompcindex = p->froms + i;
  toindex = * frompcindex;
  toindex = * frompcindex;
 
 
  if (toindex == 0)
  if (toindex == 0)
    {
    {
      /* First time traversing this arc.  */
      /* First time traversing this arc.  */
      toindex = ++ p->tos[0].link;
      toindex = ++ p->tos[0].link;
      if (toindex >= p->tolimit)
      if (toindex >= p->tolimit)
        /* Halt further profiling.  */
        /* Halt further profiling.  */
        goto overflow;
        goto overflow;
 
 
      * frompcindex = toindex;
      * frompcindex = toindex;
      top = p->tos + toindex;
      top = p->tos + toindex;
      top->selfpc = selfpc;
      top->selfpc = selfpc;
      top->count = 1;
      top->count = 1;
      top->link = 0;
      top->link = 0;
      goto done;
      goto done;
    }
    }
 
 
  top = p->tos + toindex;
  top = p->tos + toindex;
 
 
  if (top->selfpc == selfpc)
  if (top->selfpc == selfpc)
    {
    {
      /* Arc at front of chain: usual case.  */
      /* Arc at front of chain: usual case.  */
      top->count ++;
      top->count ++;
      goto done;
      goto done;
    }
    }
 
 
  /* Have to go looking down chain for it.
  /* Have to go looking down chain for it.
     Top points to what we are looking at,
     Top points to what we are looking at,
     prevtop points to previous top.
     prevtop points to previous top.
     We know it is not at the head of the chain.  */
     We know it is not at the head of the chain.  */
  for (;;)
  for (;;)
    {
    {
      if (top->link == 0)
      if (top->link == 0)
        {
        {
          /* Top is end of the chain and none of the chain
          /* Top is end of the chain and none of the chain
             had top->selfpc == selfpc.  So we allocate a
             had top->selfpc == selfpc.  So we allocate a
             new tostruct and link it to the head of the
             new tostruct and link it to the head of the
             chain.  */
             chain.  */
          toindex = ++ p->tos[0].link;
          toindex = ++ p->tos[0].link;
          if (toindex >= p->tolimit)
          if (toindex >= p->tolimit)
            goto overflow;
            goto overflow;
 
 
          top = p->tos + toindex;
          top = p->tos + toindex;
          top->selfpc = selfpc;
          top->selfpc = selfpc;
          top->count = 1;
          top->count = 1;
          top->link = * frompcindex;
          top->link = * frompcindex;
          * frompcindex = toindex;
          * frompcindex = toindex;
          goto done;
          goto done;
        }
        }
 
 
      /* Otherwise, check the next arc on the chain.  */
      /* Otherwise, check the next arc on the chain.  */
      prevtop = top;
      prevtop = top;
      top = p->tos + top->link;
      top = p->tos + top->link;
 
 
      if (top->selfpc == selfpc)
      if (top->selfpc == selfpc)
        {
        {
          /* There it is.  Increment its count
          /* There it is.  Increment its count
             move it to the head of the chain.  */
             move it to the head of the chain.  */
          top->count ++;
          top->count ++;
          toindex = prevtop->link;
          toindex = prevtop->link;
          prevtop->link = top->link;
          prevtop->link = top->link;
          top->link = * frompcindex;
          top->link = * frompcindex;
          * frompcindex = toindex;
          * frompcindex = toindex;
          goto done;
          goto done;
        }
        }
    }
    }
 
 
 done:
 done:
  p->state = GMON_PROF_ON;
  p->state = GMON_PROF_ON;
  return;
  return;
 
 
 overflow:
 overflow:
  p->state = GMON_PROF_ERROR;
  p->state = GMON_PROF_ERROR;
  return;
  return;
}
}
 
 
void
void
_monstartup (unsigned long lowpc, unsigned long highpc)
_monstartup (unsigned long lowpc, unsigned long highpc)
{
{
  char * cp;
  char * cp;
  struct gmonparam * p = & _gmonparam;
  struct gmonparam * p = & _gmonparam;
 
 
  /* If the calloc() function has been instrumented we must make sure
  /* If the calloc() function has been instrumented we must make sure
     that it is not profiled until we are ready.  */
     that it is not profiled until we are ready.  */
  p->state = GMON_PROF_BUSY;
  p->state = GMON_PROF_BUSY;
 
 
  /* Round lowpc and highpc to multiples of the density we're using
  /* Round lowpc and highpc to multiples of the density we're using
     so the rest of the scaling (here and in gprof) stays in ints.  */
     so the rest of the scaling (here and in gprof) stays in ints.  */
  p->lowpc            = ROUNDDOWN (lowpc, HISTFRACTION * sizeof (* p->kcount));
  p->lowpc            = ROUNDDOWN (lowpc, HISTFRACTION * sizeof (* p->kcount));
  p->highpc           = ROUNDUP (highpc, HISTFRACTION * sizeof (* p->kcount));
  p->highpc           = ROUNDUP (highpc, HISTFRACTION * sizeof (* p->kcount));
  p->textsize         = p->highpc - p->lowpc;
  p->textsize         = p->highpc - p->lowpc;
  p->kcountsize       = ROUNDUP (p->textsize / HISTFRACTION, sizeof (*p->froms));
  p->kcountsize       = ROUNDUP (p->textsize / HISTFRACTION, sizeof (*p->froms));
  p->hashfraction     = HASHFRACTION;
  p->hashfraction     = HASHFRACTION;
  p->log_hashfraction = -1;
  p->log_hashfraction = -1;
  p->log_hashfraction = ffs (p->hashfraction * sizeof (*p->froms)) - 1;
  p->log_hashfraction = ffs (p->hashfraction * sizeof (*p->froms)) - 1;
  p->fromssize        = p->textsize / HASHFRACTION;
  p->fromssize        = p->textsize / HASHFRACTION;
  p->tolimit          = p->textsize * ARCDENSITY / 100;
  p->tolimit          = p->textsize * ARCDENSITY / 100;
 
 
  if (p->tolimit < MINARCS)
  if (p->tolimit < MINARCS)
    p->tolimit = MINARCS;
    p->tolimit = MINARCS;
  else if (p->tolimit > MAXARCS)
  else if (p->tolimit > MAXARCS)
    p->tolimit = MAXARCS;
    p->tolimit = MAXARCS;
 
 
  p->tossize          = p->tolimit * sizeof (struct tostruct);
  p->tossize          = p->tolimit * sizeof (struct tostruct);
 
 
  cp = calloc (p->kcountsize + p->fromssize + p->tossize, 1);
  cp = calloc (p->kcountsize + p->fromssize + p->tossize, 1);
  if (cp == NULL)
  if (cp == NULL)
    {
    {
      write (2, "monstartup: out of memory\n", 26);
      write (2, "monstartup: out of memory\n", 26);
      p->tos = NULL;
      p->tos = NULL;
      p->state = GMON_PROF_ERROR;
      p->state = GMON_PROF_ERROR;
      return;
      return;
    }
    }
 
 
  p->tos = (struct tostruct *) cp;
  p->tos = (struct tostruct *) cp;
  cp += p->tossize;
  cp += p->tossize;
  p->kcount = (unsigned short *) cp;
  p->kcount = (unsigned short *) cp;
  cp += p->kcountsize;
  cp += p->kcountsize;
  p->froms = (unsigned long *) cp;
  p->froms = (unsigned long *) cp;
 
 
  p->tos[0].link = 0;
  p->tos[0].link = 0;
  p->state = GMON_PROF_ON;
  p->state = GMON_PROF_ON;
}
}
 
 
 
 
static void
static void
write_call_graph (int fd)
write_call_graph (int fd)
{
{
#define NARCS_PER_WRITE 32
#define NARCS_PER_WRITE 32
 
 
  struct gmon_cg_arc_record raw_arc[NARCS_PER_WRITE]
  struct gmon_cg_arc_record raw_arc[NARCS_PER_WRITE]
    __attribute__ ((aligned (__alignof__ (char *))));
    __attribute__ ((aligned (__alignof__ (char *))));
  unsigned long from_index;
  unsigned long from_index;
  unsigned long to_index;
  unsigned long to_index;
  unsigned long from_len;
  unsigned long from_len;
  unsigned long frompc;
  unsigned long frompc;
  int nfilled;
  int nfilled;
 
 
  for (nfilled = 0; nfilled < NARCS_PER_WRITE; ++ nfilled)
  for (nfilled = 0; nfilled < NARCS_PER_WRITE; ++ nfilled)
    raw_arc[nfilled].tag = GMON_TAG_CG_ARC;
    raw_arc[nfilled].tag = GMON_TAG_CG_ARC;
 
 
  nfilled = 0;
  nfilled = 0;
  from_len = _gmonparam.fromssize / sizeof (*_gmonparam.froms);
  from_len = _gmonparam.fromssize / sizeof (*_gmonparam.froms);
 
 
  for (from_index = 0; from_index < from_len; ++from_index)
  for (from_index = 0; from_index < from_len; ++from_index)
    {
    {
      if (_gmonparam.froms[from_index] == 0)
      if (_gmonparam.froms[from_index] == 0)
        continue;
        continue;
 
 
      frompc = _gmonparam.lowpc;
      frompc = _gmonparam.lowpc;
      frompc += (from_index * _gmonparam.hashfraction
      frompc += (from_index * _gmonparam.hashfraction
                 * sizeof (*_gmonparam.froms));
                 * sizeof (*_gmonparam.froms));
 
 
      for (to_index = _gmonparam.froms[from_index];
      for (to_index = _gmonparam.froms[from_index];
           to_index != 0;
           to_index != 0;
           to_index = _gmonparam.tos[to_index].link)
           to_index = _gmonparam.tos[to_index].link)
        {
        {
          struct gmon_cg_arc_record * arc = raw_arc + nfilled;
          struct gmon_cg_arc_record * arc = raw_arc + nfilled;
 
 
          memcpy (arc->from_pc, & frompc, sizeof (arc->from_pc));
          memcpy (arc->from_pc, & frompc, sizeof (arc->from_pc));
          memcpy (arc->self_pc, & _gmonparam.tos[to_index].selfpc, sizeof (arc->self_pc));
          memcpy (arc->self_pc, & _gmonparam.tos[to_index].selfpc, sizeof (arc->self_pc));
          memcpy (arc->count,   & _gmonparam.tos[to_index].count, sizeof (arc->count));
          memcpy (arc->count,   & _gmonparam.tos[to_index].count, sizeof (arc->count));
 
 
          if (++ nfilled == NARCS_PER_WRITE)
          if (++ nfilled == NARCS_PER_WRITE)
            {
            {
              write (fd, raw_arc, sizeof raw_arc);
              write (fd, raw_arc, sizeof raw_arc);
              nfilled = 0;
              nfilled = 0;
            }
            }
        }
        }
    }
    }
 
 
  if (nfilled > 0)
  if (nfilled > 0)
    write (fd, raw_arc, nfilled * sizeof (raw_arc[0]));
    write (fd, raw_arc, nfilled * sizeof (raw_arc[0]));
}
}
 
 
#include <errno.h>
#include <errno.h>
 
 
static void
static void
write_gmon (void)
write_gmon (void)
{
{
  struct gmon_hdr ghdr __attribute__ ((aligned (__alignof__ (int))));
  struct gmon_hdr ghdr __attribute__ ((aligned (__alignof__ (int))));
  int fd;
  int fd;
 
 
  fd = open ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY, 0666);
  fd = open ("gmon.out", O_CREAT|O_TRUNC|O_WRONLY, 0666);
  if (fd < 0)
  if (fd < 0)
    {
    {
      write (2, "_mcleanup: could not create gmon.out\n", 37);
      write (2, "_mcleanup: could not create gmon.out\n", 37);
      return;
      return;
    }
    }
 
 
  /* Write gmon.out header: */
  /* Write gmon.out header: */
  memset (& ghdr, '\0', sizeof (ghdr));
  memset (& ghdr, '\0', sizeof (ghdr));
  memcpy (ghdr.cookie, GMON_MAGIC, sizeof (ghdr.cookie));
  memcpy (ghdr.cookie, GMON_MAGIC, sizeof (ghdr.cookie));
  * (unsigned long *) ghdr.version = GMON_VERSION;
  * (unsigned long *) ghdr.version = GMON_VERSION;
  write (fd, & ghdr, sizeof (ghdr));
  write (fd, & ghdr, sizeof (ghdr));
 
 
  /* We do not have histogram or basic block information,
  /* We do not have histogram or basic block information,
     so we do not generate these parts of the gmon.out file.  */
     so we do not generate these parts of the gmon.out file.  */
 
 
  /* Write call-graph.  */
  /* Write call-graph.  */
  write_call_graph (fd);
  write_call_graph (fd);
 
 
  close (fd);
  close (fd);
}
}
 
 
void
void
_mcleanup (void)
_mcleanup (void)
{
{
  if (_gmonparam.state != GMON_PROF_ERROR)
  if (_gmonparam.state != GMON_PROF_ERROR)
    {
    {
      _gmonparam.state = GMON_PROF_OFF;
      _gmonparam.state = GMON_PROF_OFF;
      write_gmon ();
      write_gmon ();
    }
    }
 
 
  /* Free the memory.  */
  /* Free the memory.  */
  if (_gmonparam.tos != NULL)
  if (_gmonparam.tos != NULL)
    {
    {
      free (_gmonparam.tos);
      free (_gmonparam.tos);
      _gmonparam.tos = NULL;
      _gmonparam.tos = NULL;
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.