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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [profiler.c] - Diff between revs 19 and 100

Show entire file | Details | Blame | View Log

Rev 19 Rev 100
Line 25... Line 25...
 
 
/* Command line utility, that displays profiling information, generated
/* Command line utility, that displays profiling information, generated
   by or1ksim. (use profile command interactively, when running or1ksim, or
   by or1ksim. (use profile command interactively, when running or1ksim, or
   separate psim command).  */
   separate psim command).  */
 
 
 
#define PROF_DEBUG 0
 
 
/* Autoconf and/or portability configuration */
/* Autoconf and/or portability configuration */
#include "config.h"
#include "config.h"
#include "port.h"
#include "port.h"
 
 
Line 36... Line 37...
#include "profiler.h"
#include "profiler.h"
#include "sim-config.h"
#include "sim-config.h"
#include "argtable2.h"
#include "argtable2.h"
 
 
/*! Maximum stack frames that can be profiled */
/*! Maximum stack frames that can be profiled */
#define MAX_STACK  1024
#define MAX_STACK  262144
 
 
/*! Data structure representing information about a stack frame */
/*! Data structure representing information about a stack frame */
struct stack_struct
struct stack_struct
{
{
  unsigned int  addr;      /*!< Function address */
  unsigned int  addr;      /*!< Function address */
Line 98... Line 99...
 
 
  if (runtime.sim.fprof)
  if (runtime.sim.fprof)
    {
    {
      fprof = runtime.sim.fprof;
      fprof = runtime.sim.fprof;
      reopened = 1;
      reopened = 1;
 
      if (PROF_DEBUG) printf("reopened=1\n");
      rewind (fprof);
      rewind (fprof);
    }
    }
  else
  else
    fprof = fopen (fprofname, "rt");
    fprof = fopen (fprofname, "rt");
 
 
  if (!fprof)
  if (!fprof)
    {
    {
      fprintf (stderr, "Cannot open profile file: %s\n", fprofname);
      fprintf (stderr, "Cannot open profile file: %s\n", fprofname);
      return 1;
      return 1;
    }
    }
 
  int ctr =0;
  while (1)
  while (1)
    {
    {
 
      if (PROF_DEBUG) printf("%d ",ctr++);
      char dir = fgetc (fprof);
      char dir = fgetc (fprof);
      line++;
      line++;
      if (dir == '+')
      if (dir == '+')
        {
        {
          if (fscanf
          if (fscanf
Line 124... Line 127...
            fprintf (stderr, "Error reading line #%i\n", line);
            fprintf (stderr, "Error reading line #%i\n", line);
          else
          else
            {
            {
              prof_cycles = stack[nstack].cycles;
              prof_cycles = stack[nstack].cycles;
              nstack++;
              nstack++;
 
              if (PROF_DEBUG) printf("+ 0x%.8x nstack %d\n",stack[nstack-1].raddr, nstack);
              if (nstack > maxstack)
              if (nstack > maxstack)
                maxstack = nstack;
                maxstack = nstack;
            }
            }
          ntotcalls++;
          ntotcalls++;
        }
        }
Line 138... Line 142...
            fprintf (stderr, "Error reading line #%i\n", line);
            fprintf (stderr, "Error reading line #%i\n", line);
          else
          else
            {
            {
              int i;
              int i;
              prof_cycles = s.cycles;
              prof_cycles = s.cycles;
 
              if (PROF_DEBUG) printf("- 0x%.8x nstack %d\n",s.raddr ,nstack);
              for (i = nstack - 1; i >= 0; i--)
              for (i = nstack - 1; i >= 0; i--)
                if (stack[i].raddr == s.raddr)
                if (stack[i].raddr == s.raddr)
                  break;
                  break;
              if (i >= 0)
              if (i >= 0)
                {
                {

powered by: WebSVN 2.1.0

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