diff options
author | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-05-12 18:25:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-12 18:25:10 +0900 |
commit | a1b01e7701f9fc370f8dff777aad6d39a2c5a3e3 (patch) | |
tree | 69bb0c08c139f1c7c5abe9422649f11581f85529 /tool/lrama/lib/lrama/report.rb | |
parent | d314fe42f987fcfaad67f102ec418ee4ca32ee99 (diff) |
Use Lrama LALR parser generator instead of Bisonv3_3_0_preview1
https://bugs.ruby-lang.org/issues/19637
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7798
Merged-By: yui-knk <spiketeika@gmail.com>
Diffstat (limited to 'tool/lrama/lib/lrama/report.rb')
-rw-r--r-- | tool/lrama/lib/lrama/report.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/report.rb b/tool/lrama/lib/lrama/report.rb new file mode 100644 index 0000000000..7016a45171 --- /dev/null +++ b/tool/lrama/lib/lrama/report.rb @@ -0,0 +1,47 @@ +module Lrama + class Report + module Profile + # 1. Wrap target method with Profile.report_profile like below: + # + # Lrama::Report::Profile.report_profile { method } + # + # 2. Run lrama command, for example + # + # $ ./exe/lrama --trace=time spec/fixtures/integration/ruby_3_2_0/parse.tmp.y + # + # 3. Generate html file + # + # $ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html + # + def self.report_profile + require "stackprof" + + StackProf.run(mode: :cpu, raw: true, out: 'tmp/stackprof-cpu-myapp.dump') do + yield + end + end + end + + module Duration + def self.enable + @_report_duration_enabled = true + end + + def self.enabled? + !!@_report_duration_enabled + end + + def report_duration(method_name) + time1 = Time.now.to_f + result = yield + time2 = Time.now.to_f + + if Duration.enabled? + puts sprintf("%s %10.5f s", method_name, time2 - time1) + end + + return result + end + end + end +end |