Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix calculation of percentage and update README #193

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ You can use the option with `-q` to use the output directly.
$ build/rv32emu -d - out.elf -q | jq .x10
```

## Tools

```shell
make tool
```
### rv_histogram
This is a static analysis tool of RV32 instructions/registers usage
in the target program.
```shell
build/rv_histogram [-ar] [target_program_path]
```
It has two optional options:
* `-a`: output the analysis in ascending order(default is descending order)
* `-r`: output usage of registers(default is usage of instructions)

_Example Instructions Histogram_
![Instructions Hisrogram Example](/docs/histogram_instructions.png)

_Example Registers Histogram_
![Registers Hisrogram Example](/docs/histogram_registers.png)

## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.

Expand Down
Binary file added docs/histogram_instructions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/histogram_registers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tools/rv_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void print_hist_stats(const rv_hist_t *stats, size_t stats_size)
insn_reg = stats[i].insn_reg;
freq = stats[i].freq;

percent = (float) freq / total_freq;
if (percent < 0.01)
percent = ((float) freq / total_freq) * 100;
if (percent < 1.00)
continue;

printf(fmt, idx, insn_reg, percent, freq,
Expand Down