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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_40/] [or1ksim/] [mprofiler.c] - Diff between revs 848 and 997

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

Rev 848 Rev 997
Line 22... Line 22...
 
 
#include <stdio.h>
#include <stdio.h>
#include <malloc.h>
#include <malloc.h>
#include "support/profile.h"
#include "support/profile.h"
#include "mprofiler.h"
#include "mprofiler.h"
 
#include "sim-config.h"
 
 
struct memory_hash {
struct memory_hash {
  struct memory_hash *next;
  struct memory_hash *next;
  unsigned long addr;
  unsigned long addr;
  unsigned long cnt[3];    /* Various counters */
  unsigned long cnt[3];    /* Various counters */
Line 43... Line 44...
/* File to read from */
/* File to read from */
static FILE *fprof = 0;
static FILE *fprof = 0;
 
 
void mp_help ()
void mp_help ()
{
{
  printf ("mprofiler <-d|-p|-a|-w> [-f filename] [-g group] from to\n");
  PRINTF ("mprofiler <-d|-p|-a|-w> [-f filename] [-g group] from to\n");
  printf ("\t-d\t--detail\t\tdetailed output\n");
  PRINTF ("\t-d\t--detail\t\tdetailed output\n");
  printf ("\t-p\t--pretty\t\tpretty output\n");
  PRINTF ("\t-p\t--pretty\t\tpretty output\n");
  printf ("\t-a\t--access\t\toutput accesses only\n");
  PRINTF ("\t-a\t--access\t\toutput accesses only\n");
  printf ("\t-w\t--width\t\t\toutput by width\n");
  PRINTF ("\t-w\t--width\t\t\toutput by width\n");
  printf ("\t-f\t--filename filename\tspecify mprofile file [sim.mprofile]\n");
  PRINTF ("\t-f\t--filename filename\tspecify mprofile file [sim.mprofile]\n");
  printf ("\t-g\t--group bits\t\tgroup 2^bits successive\n");
  PRINTF ("\t-g\t--group bits\t\tgroup 2^bits successive\n");
  printf ("\t\t\t\t\taddresses together [2]\n");
  PRINTF ("\t\t\t\t\taddresses together [2]\n");
  printf ("\t-h\t--help\t\t\toutput this screen\n");
  PRINTF ("\t-h\t--help\t\t\toutput this screen\n");
}
}
 
 
void hash_add (unsigned long addr, int index)
void hash_add (unsigned long addr, int index)
{
{
  struct memory_hash *h = hash[HASH_FUNC(addr)];
  struct memory_hash *h = hash[HASH_FUNC(addr)];
Line 96... Line 97...
    num_read = fread (buf, sizeof (struct mprofentry_struct), BUF_SIZE, f);
    num_read = fread (buf, sizeof (struct mprofentry_struct), BUF_SIZE, f);
    for (i = 0; i < num_read; i++) if (buf[i].addr >= start_addr && buf[i].addr <= end_addr) {
    for (i = 0; i < num_read; i++) if (buf[i].addr >= start_addr && buf[i].addr <= end_addr) {
      int index;
      int index;
      unsigned t = buf[i].type;
      unsigned t = buf[i].type;
      if (t > 64) {
      if (t > 64) {
        printf ("!");
        PRINTF ("!");
        t = 0;
        t = 0;
      }
      }
      if (mode == MODE_WIDTH) t >>= 3;
      if (mode == MODE_WIDTH) t >>= 3;
      else t &= 0x7;
      else t &= 0x7;
 
 
Line 108... Line 109...
        case 1: index = 0; break;
        case 1: index = 0; break;
        case 2: index = 1; break;
        case 2: index = 1; break;
        case 4: index = 2; break;
        case 4: index = 2; break;
        default:
        default:
          index = 0;
          index = 0;
          printf ("!!!!");
          PRINTF ("!!!!");
          break;
          break;
      }
      }
      hash_add (buf[i].addr >> group_bits, index);
      hash_add (buf[i].addr >> group_bits, index);
    }
    }
  } while (num_read > 0);
  } while (num_read > 0);
Line 134... Line 135...
}
}
 
 
void printout (int mode)
void printout (int mode)
{
{
  unsigned long addr = start_addr & ~((1 << group_bits) - 1);
  unsigned long addr = start_addr & ~((1 << group_bits) - 1);
  printf ("start = %08x (%08x); end = %08x; group_bits = %08x\n", start_addr, addr, end_addr, (1 << group_bits) - 1);
  PRINTF ("start = %08x (%08x); end = %08x; group_bits = %08x\n", start_addr, addr, end_addr, (1 << group_bits) - 1);
  for (; addr <= end_addr; addr += (1 << group_bits)) {
  for (; addr <= end_addr; addr += (1 << group_bits)) {
    int i;
    int i;
    unsigned long a = hash_get (addr >> group_bits, 0);
    unsigned long a = hash_get (addr >> group_bits, 0);
    unsigned long b = hash_get (addr >> group_bits, 1);
    unsigned long b = hash_get (addr >> group_bits, 1);
    unsigned long c = hash_get (addr >> group_bits, 2);
    unsigned long c = hash_get (addr >> group_bits, 2);
    printf ("%08x:", addr);
    PRINTF ("%08x:", addr);
    switch (mode) {
    switch (mode) {
      case MODE_DETAIL:
      case MODE_DETAIL:
        if (a) printf (" %10i R", a);
        if (a) PRINTF (" %10i R", a);
        else printf ("            R");
        else PRINTF ("            R");
        if (b) printf (" %10i W", b);
        if (b) PRINTF (" %10i W", b);
        else printf ("            W");
        else PRINTF ("            W");
        if (c) printf (" %10i F", c);
        if (c) PRINTF (" %10i F", c);
        else printf ("            F");
        else PRINTF ("            F");
        break;
        break;
      case MODE_ACCESS:
      case MODE_ACCESS:
        printf (" %10i", a + b + c);
        PRINTF (" %10i", a + b + c);
        break;
        break;
      case MODE_PRETTY:
      case MODE_PRETTY:
        printf (" %10i ", a + b + c);
        PRINTF (" %10i ", a + b + c);
        for (i = 0; i < nbits (a + b + c); i++)
        for (i = 0; i < nbits (a + b + c); i++)
          printf ("#");
          PRINTF ("#");
#if 0
#if 0
        for (; i < 64; i++)
        for (; i < 64; i++)
          printf (".");
          PRINTF (".");
#endif
#endif
        break;
        break;
      case MODE_WIDTH:
      case MODE_WIDTH:
        if (a) printf (" %10i B", a);
        if (a) PRINTF (" %10i B", a);
        else printf ("            B");
        else PRINTF ("            B");
        if (b) printf (" %10i H", b);
        if (b) PRINTF (" %10i H", b);
        else printf ("            H");
        else PRINTF ("            H");
        if (c) printf (" %10i W", c);
        if (c) PRINTF (" %10i W", c);
        else printf ("            W");
        else PRINTF ("            W");
        break;
        break;
    }
    }
    printf ("\n");
    PRINTF ("\n");
    if (addr >= addr + (1 << group_bits)) break; /* Overflow? */
    if (addr >= addr + (1 << group_bits)) break; /* Overflow? */
  }
  }
}
}
 
 
int main_mprofiler (int argc, char *argv[])
int main_mprofiler (int argc, char *argv[])

powered by: WebSVN 2.1.0

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