Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refine file naming scheme for profiling data #337

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
@@ -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
23 changes: 18 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -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>
@@ -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;
@@ -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;
}
24 changes: 12 additions & 12 deletions tools/rv_profiler
Original file line number Diff line number Diff line change
@@ -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=' ')
@@ -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 = []
@@ -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)
@@ -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