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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc3/] [or1ksim/] [profiler.c] - Diff between revs 879 and 940

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 879 Rev 940
Line 20... Line 20...
/* Command line utility, that displays profiling information, generated
/* Command line utility, that displays profiling information, generated
   by or1ksim. (use --profile option at command line, when running or1ksim.  */
   by or1ksim. (use --profile option at command line, when running or1ksim.  */
 
 
#include <stdio.h>
#include <stdio.h>
#include "profiler.h"
#include "profiler.h"
 
#include "sim-config.h"
 
 
static struct stack_struct stack[MAX_STACK];
static struct stack_struct stack[MAX_STACK];
 
 
struct func_struct prof_func[MAX_FUNCS];
struct func_struct prof_func[MAX_FUNCS];
 
 
Line 67... Line 68...
 
 
/* Acquire data from profiler file */
/* Acquire data from profiler file */
int prof_acquire (char *fprofname)
int prof_acquire (char *fprofname)
{
{
  int line = 0;
  int line = 0;
  fprof = fopen (fprofname, "rt");
  int reopened = 0;
 
 
 
  if (runtime.sim.fprof) {
 
    fprof = runtime.sim.fprof;
 
    reopened = 1;
 
    rewind (fprof);
 
  } else 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;
  }
  }
Line 139... Line 146...
        } else if (!quiet) fprintf (stderr, "WARNING: Cannot find return call for (%08X), ignoring.\n", s.raddr);
        } else if (!quiet) fprintf (stderr, "WARNING: Cannot find return call for (%08X), ignoring.\n", s.raddr);
      }
      }
    } else
    } else
      break;
      break;
  }
  }
  fclose(fprof);
 
 
  /* If we have reopened the file, we need to add end of "[outside functions]" */
 
  if (reopened) {
 
    prof_cycles = runtime.sim.cycles;
 
    /* pop everything above current from stack,
 
       if more than one, something went wrong */
 
    while (nstack > 0) {
 
      int j;
 
      long time;
 
      nstack--;
 
      time = runtime.sim.cycles - stack[nstack].cycles;
 
      /* Whether in normal mode, we must substract called function from execution time.  */
 
      if (!cumulative)
 
        for (j = 0; j < nstack; j++) stack[j].cycles += time;
 
 
 
      for (j = 0; j < prof_nfuncs; j++)
 
        if (stack[nstack].addr == prof_func[j].addr) { /* function exists, append. */
 
          prof_func[j].cum_cycles += time;
 
          prof_func[j].calls++;
 
          nfunccalls++;
 
          break;
 
        }
 
      if (j >= prof_nfuncs) { /* function does not yet exist, create new. */
 
        prof_func[prof_nfuncs].cum_cycles = time;
 
        prof_func[prof_nfuncs].calls = 1;
 
        nfunccalls++;
 
        prof_func[prof_nfuncs].addr = stack[nstack].addr;
 
        strcpy (prof_func[prof_nfuncs].name, stack[nstack].name);
 
        prof_nfuncs++;
 
      }
 
    }
 
  } else fclose(fprof);
 
  return 0;
}
}
 
 
/* Print out profiling data */
/* Print out profiling data */
void prof_print ()
void prof_print ()
{
{

powered by: WebSVN 2.1.0

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