Skip to content

Commit

Permalink
Merge pull request sysprog21#193 from ChinYikMing/pr
Browse files Browse the repository at this point in the history
Fix calculation of percentage and update README
  • Loading branch information
jserv authored Aug 15, 2023
2 parents f268fcb + 005a7ad commit 76cd32e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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

0 comments on commit 76cd32e

Please sign in to comment.