Skip to content

Commit

Permalink
Merge pull request #432 from ydah/memory-prof
Browse files Browse the repository at this point in the history
Change to allow verification of memory usage
  • Loading branch information
ydah authored Jun 6, 2024
2 parents 3fafbc2 + d7a1f95 commit 2e908e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "rake"
gem "rspec"
gem "simplecov", require: false
gem "stackprof", platforms: [:ruby] # stackprof doesn't support Windows
gem "memory_profiler"

# Recent steep requires Ruby >= 3.0.0.
# Then skip install on some CI jobs.
Expand Down
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 2e908e9

Please sign in to comment.