OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [gprof/] [bb_exit_func.c] - Diff between revs 156 and 816

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

Rev 156 Rev 816
/*  bb_exit_func.c - dumps all the basic-block statistics linked into
/*  bb_exit_func.c - dumps all the basic-block statistics linked into
    the bb_head chain to .d files.
    the bb_head chain to .d files.
 
 
   Copyright 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
   Copyright 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
 
 
   This file is part of GNU Binutils.
   This file is part of GNU Binutils.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.
   02110-1301, USA.
 
 
   This code was contributed by:
   This code was contributed by:
 
 
     David Mosberger-Tang <David.Mosberger@acm.org>  */
     David Mosberger-Tang <David.Mosberger@acm.org>  */


#include <stdio.h>
#include <stdio.h>
#include <strings.h>
#include <strings.h>
#include "bfd.h"
#include "bfd.h"
#include "gmon_out.h"
#include "gmon_out.h"
 
 
/* structure emitted by -a */
/* structure emitted by -a */
struct bb
struct bb
{
{
  long zero_word;
  long zero_word;
  const char *filename;
  const char *filename;
  long *counts;
  long *counts;
  long ncounts;
  long ncounts;
  struct bb *next;
  struct bb *next;
  const unsigned long *addresses;
  const unsigned long *addresses;
};
};
 
 
struct bb *__bb_head = (struct bb *) 0;
struct bb *__bb_head = (struct bb *) 0;
 
 
 
 
void
void
__bb_exit_func ()
__bb_exit_func ()
{
{
  const int version = GMON_VERSION;
  const int version = GMON_VERSION;
  struct gmon_hdr ghdr;
  struct gmon_hdr ghdr;
  struct bb *ptr;
  struct bb *ptr;
  FILE *fp;
  FILE *fp;
  /* GEN_GMON_CNT_FILE should be defined on systems with mcleanup()
  /* GEN_GMON_CNT_FILE should be defined on systems with mcleanup()
     functions that do not write basic-block to gmon.out.  In such
     functions that do not write basic-block to gmon.out.  In such
     cases profiling with "-pg -a" would result in a gmon.out file
     cases profiling with "-pg -a" would result in a gmon.out file
     without basic-block info (because the file written here would be
     without basic-block info (because the file written here would be
     overwritten.  Thus, a separate file is generated instead.  The
     overwritten.  Thus, a separate file is generated instead.  The
     two files can easily be combined by specifying them on gprof's
     two files can easily be combined by specifying them on gprof's
     command line (and possibly generating a gmon.sum file with "gprof
     command line (and possibly generating a gmon.sum file with "gprof
     -s"). */
     -s"). */
#ifndef GEN_GMON_CNT_FILE
#ifndef GEN_GMON_CNT_FILE
#   define OUT_NAME     "gmon.out"
#   define OUT_NAME     "gmon.out"
#else
#else
#   define OUT_NAME     "gmon.cnt"
#   define OUT_NAME     "gmon.cnt"
#endif
#endif
  fp = fopen (OUT_NAME, "wb");
  fp = fopen (OUT_NAME, "wb");
  if (!fp)
  if (!fp)
    {
    {
      perror (OUT_NAME);
      perror (OUT_NAME);
      return;
      return;
    }
    }
  memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
  memcpy (&ghdr.cookie[0], GMON_MAGIC, 4);
  memcpy (&ghdr.version, &version, sizeof (version));
  memcpy (&ghdr.version, &version, sizeof (version));
  fwrite (&ghdr, sizeof (ghdr), 1, fp);
  fwrite (&ghdr, sizeof (ghdr), 1, fp);
 
 
  for (ptr = __bb_head; ptr != 0; ptr = ptr->next)
  for (ptr = __bb_head; ptr != 0; ptr = ptr->next)
    {
    {
      u_int ncounts = ptr->ncounts;
      u_int ncounts = ptr->ncounts;
      u_char tag;
      u_char tag;
      u_int i;
      u_int i;
 
 
      tag = GMON_TAG_BB_COUNT;
      tag = GMON_TAG_BB_COUNT;
      fwrite (&tag, sizeof (tag), 1, fp);
      fwrite (&tag, sizeof (tag), 1, fp);
      fwrite (&ncounts, sizeof (ncounts), 1, fp);
      fwrite (&ncounts, sizeof (ncounts), 1, fp);
 
 
      for (i = 0; i < ncounts; ++i)
      for (i = 0; i < ncounts; ++i)
        {
        {
          fwrite (&ptr->addresses[i], sizeof (ptr->addresses[0]), 1, fp);
          fwrite (&ptr->addresses[i], sizeof (ptr->addresses[0]), 1, fp);
          fwrite (&ptr->counts[i], sizeof (ptr->counts[0]), 1, fp);
          fwrite (&ptr->counts[i], sizeof (ptr->counts[0]), 1, fp);
        }
        }
    }
    }
  fclose (fp);
  fclose (fp);
}
}
 
 

powered by: WebSVN 2.1.0

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