Skip to content

Commit

Permalink
Add a way for memory profiling of Lrama to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jun 5, 2024
1 parent da60771 commit d7a1f95
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $ bundle install
$ bundle exec rake
```

### Profiling Lrama
### Call-stack Profiling Lrama

#### 1. Create parse.tmp.y in ruby/ruby

Expand Down Expand Up @@ -166,6 +166,41 @@ $ exe/lrama -o parse.tmp.c --header=parse.tmp.h tmp/parse.tmp.y
$ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html
```

### Memory Profiling Lrama

#### 1. Create parse.tmp.y in ruby/ruby

```shell
$ ruby tool/id2token.rb parse.y > parse.tmp.y
$ cp parse.tmp.y dir/lrama/tmp
```

#### 2. Enable Profiler

```diff
diff --git a/exe/lrama b/exe/lrama
index 1aece5d141..f5f94cf7fa 100755
--- a/exe/lrama
+++ b/exe/lrama
@@ -3,5 +3,9 @@

$LOAD_PATH << File.join(__dir__, "../lib")
require "lrama"
+require 'memory_profiler'

-Lrama::Command.new.run(ARGV.dup)
+report = MemoryProfiler.report do
+ Lrama::Command.new.run(ARGV.dup)
+end
+report.pretty_print
```

#### 3. Run Lrama

```shell
$ exe/lrama -o parse.tmp.c --header=parse.tmp.h tmp/parse.tmp.y > report.txt
```

### Build Ruby

1. Install Lrama
Expand Down

0 comments on commit d7a1f95

Please sign in to comment.