Line 21... |
Line 21... |
by or1ksim. (use --mprofile option at command line, when running or1ksim. */
|
by or1ksim. (use --mprofile option at command line, when running or1ksim. */
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <malloc.h>
|
#include <malloc.h>
|
#include "support/profile.h"
|
#include "support/profile.h"
|
|
#include "mprofiler.h"
|
|
|
/* output modes */
|
|
#define MODE_DETAIL 0
|
|
#define MODE_PRETTY 1
|
|
#define MODE_ACCESS 2
|
|
#define MODE_WIDTH 3
|
|
|
|
/* Input buffer size */
|
|
#define BUF_SIZE 100
|
|
|
|
/* HASH */
|
|
#define HASH_SIZE 0x10000
|
|
#define HASH_FUNC(x) ((x) & 0xffff)
|
|
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 */
|
} *hash[HASH_SIZE];
|
} *hash[HASH_SIZE];
|
Line 54... |
Line 43... |
int end_addr = 0xffffffff;
|
int end_addr = 0xffffffff;
|
|
|
/* File to read from */
|
/* File to read from */
|
static FILE *fprof = 0;
|
static FILE *fprof = 0;
|
|
|
void help ()
|
void mp_help ()
|
{
|
{
|
printf ("USAGE: mprofiler <-d|-p|-a|-w> [-f filename] [-g group] from to\n");
|
printf ("USAGE: 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");
|
Line 194... |
Line 183... |
}
|
}
|
printf ("\n");
|
printf ("\n");
|
}
|
}
|
}
|
}
|
|
|
int main (int argc, char *argv[])
|
int main_mprofiler (int mode, int group, char *fname)
|
{
|
{
|
char fmprofname[50] = "sim.mprofile";
|
char fmprofname[50] = "sim.mprofile";
|
int param = 0;
|
int param = 0;
|
int mode = MODE_DETAIL;
|
/*int mode = MODE_DETAIL;*/
|
|
|
argv++; argc--;
|
if (!fname) fname = fmprofname;
|
while (argc > 0) {
|
group_bits = group;
|
if (!strcmp(argv[0], "-d") || !strcmp(argv[0], "--detail")) {
|
|
mode = MODE_DETAIL;
|
/*
|
argv++; argc--;
|
argv++; argc--;
|
} else if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--pretty")) {
|
while (argc > 0) {
|
mode = MODE_PRETTY;
|
if (!strcmp(argv[0], "-d") || !strcmp(argv[0], "--detail")) {
|
argv++; argc--;
|
mode = MODE_DETAIL;
|
} else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--access")) {
|
argv++; argc--;
|
mode = MODE_ACCESS;
|
} else if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--pretty")) {
|
argv++; argc--;
|
mode = MODE_PRETTY;
|
} else if (!strcmp(argv[0], "-w") || !strcmp(argv[0], "--width")) {
|
argv++; argc--;
|
mode = MODE_WIDTH;
|
} else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--access")) {
|
argv++; argc--;
|
mode = MODE_ACCESS;
|
} else if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--group")) {
|
argv++; argc--;
|
argv++; argc--;
|
} else if (!strcmp(argv[0], "-w") || !strcmp(argv[0], "--width")) {
|
group_bits = strtoul (argv[0], NULL, 0);
|
mode = MODE_WIDTH;
|
argv++; argc--;
|
argv++; argc--;
|
} else if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
|
} else if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--group")) {
|
help ();
|
argv++; argc--;
|
exit (0);
|
group_bits = strtoul (argv[0], NULL, 0);
|
} else if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--filename")) {
|
argv++; argc--;
|
argv++; argc--;
|
} else if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
|
strcpy (&fmprofname[0], argv[0]);
|
mp_help ();
|
argv++; argc--;
|
exit (0);
|
} else {
|
} else if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--filename")) {
|
switch (param) {
|
argv++; argc--;
|
case 0:
|
strcpy (&fmprofname[0], argv[0]);
|
start_addr = strtoul (argv[0], NULL, 0);
|
argv++; argc--;
|
break;
|
} else {
|
case 1:
|
switch (param) {
|
end_addr = strtoul (argv[0], NULL, 0);
|
case 0:
|
break;
|
start_addr = strtoul (argv[0], NULL, 0);
|
default:
|
break;
|
fprintf (stderr, "Invalid number of parameters.\n");
|
case 1:
|
exit (-1);
|
end_addr = strtoul (argv[0], NULL, 0);
|
}
|
break;
|
argv++; argc--; param++;
|
default:
|
}
|
fprintf (stderr, "Invalid number of parameters.\n");
|
}
|
exit (-1);
|
|
}
|
|
argv++; argc--; param++;
|
|
}
|
|
}
|
|
*/
|
|
|
fprof = fopen (&fmprofname[0], "rm");
|
fprof = fopen (fname, "rm");
|
|
|
if (!fprof) {
|
if (!fprof) {
|
fprintf (stderr, "Cannot open profile file: %s\n", &fmprofname[0]);
|
fprintf (stderr, "Cannot open profile file: %s\n", fname);
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
init ();
|
init ();
|
read_file (fprof, mode);
|
read_file (fprof, mode);
|