Skip to content

Commit

Permalink
Merge pull request sysprog21#337 from ChinYikMing/pf_basename
Browse files Browse the repository at this point in the history
Refine file naming scheme for profiling data
  • Loading branch information
jserv authored Jan 29, 2024
2 parents a593b23 + 0b8a712 commit 176e121
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Features:
## Build and Verify

`rv32emu` relies on certain third-party packages for full functionality and access to all its features.
To ensure proper operation, the target system should have the [SDL2 library](https://www.libsdl.org/)
To ensure proper operation, the target system should have the [SDL2 library](https://www.libsdl.org/)
and [SDL2_Mixer library](https://wiki.libsdl.org/SDL2_mixer) installed.
* macOS: `brew install sdl2 sdl2_mixer`
* Ubuntu Linux / Debian: `sudo apt install libsdl2-dev libsdl2-mixer-dev`
Expand Down Expand Up @@ -269,7 +269,7 @@ For macOS users, it might be necessary to install additional dependencies:
$ brew install graphviz
```

First, users need to create a directory named prof and then build the profiling data by executing `rv32emu`.
Build the profiling data by executing `rv32emu`.
This can be done as follows:
```shell
$ build/rv32emu -p build/[test_program].elf
Expand Down
23 changes: 18 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* "LICENSE" for information on usage and redistribution of this file.
*/

#include <assert.h>
#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -32,7 +35,7 @@ static char *signature_out_file;
static bool opt_quiet_outputs = false;

/* target executable */
static const char *opt_prog_name = "a.out";
static char *opt_prog_name = "a.out";

/* target argc and argv */
static int prog_argc;
Expand Down Expand Up @@ -166,11 +169,21 @@ static bool parse_args(int argc, char **args)
*/
prog_args = &args[optind];
opt_prog_name = prog_args[0];

if (opt_prof_data) {
char *prog_name = malloc(strlen(opt_prog_name) - 11);
strncpy(prog_name, opt_prog_name + 8, strlen(opt_prog_name) - 12);
prof_out_file = malloc(strlen(opt_prog_name) + 1);
sprintf(prof_out_file, "./prof/%s.prof", prog_name);
char cwd_path[PATH_MAX] = {0};
assert(getcwd(cwd_path, PATH_MAX));

char rel_path[PATH_MAX] = {0};
memcpy(rel_path, args[0], strlen(args[0]) - 7 /* strlen("rv32emu")*/);

char *prog_basename = basename(opt_prog_name);
prof_out_file = malloc(strlen(cwd_path) + 1 + strlen(rel_path) +
strlen(prog_basename) + 5 + 1);
assert(prof_out_file);

sprintf(prof_out_file, "%s/%s%s.prof", cwd_path, rel_path,
prog_basename);
}
return true;
}
Expand Down
24 changes: 12 additions & 12 deletions tools/rv_profiler
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Block:
def printTable(table):
col_widths = getLongestWordLength(table)
if len(table):
if len(table[0]) == 9:
if len(table[0]) == 9:
print("PC_start".rjust(col_widths[0]), end=' ')
print("PC_end".rjust(col_widths[0]), end=' ')
print("frequency".rjust(col_widths[0]), end=' ')
Expand Down Expand Up @@ -95,7 +95,7 @@ parser.add_argument('--graph-ir', type=str,
help='visualize graph IR')
args = parser.parse_args()

f = open(f'prof/{args.filename}.prof', 'r')
f = open(f'build/{args.filename}.prof', 'r')
fileds = f.readline()
raw_datas = f.read().split("\n")
profile_datas = []
Expand All @@ -104,23 +104,23 @@ for data in raw_datas:
if len(tmp) == 9:
d = {
"PC_start": tmp[0].strip(),
"PC_end": tmp[1].strip(),
"frequency": tmp[2].strip(),
"PC_end": tmp[1].strip(),
"frequency": tmp[2].strip(),
"hot": tmp[3].strip(),
"backward": tmp[4].strip(),
"loop": tmp[5].strip(),
"untaken": tmp[6].strip(),
"taken": tmp[7].strip(),
"backward": tmp[4].strip(),
"loop": tmp[5].strip(),
"untaken": tmp[6].strip(),
"taken": tmp[7].strip(),
"IR_list": tmp[8].strip(),
}
profile_datas.append(d)
profile_dict[d["PC_start"]] = d;
elif len(tmp) == 5:
d = {
"PC_start": tmp[0].strip(),
"PC_end": tmp[1].strip(),
"untaken": tmp[2].strip(),
"taken": tmp[3].strip(),
"PC_end": tmp[1].strip(),
"untaken": tmp[2].strip(),
"taken": tmp[3].strip(),
"IR_list": tmp[4].strip(),
}
profile_datas.append(d)
Expand All @@ -144,4 +144,4 @@ if args.start_address or args.stop_address:
if args.graph_ir:
block = print_graph_IR(args.graph_ir)
g = objviz(block)
g.view() # render and show graphviz.files.Source object
g.view() # render and show graphviz.files.Source object

0 comments on commit 176e121

Please sign in to comment.