bin/bmde in markdown_exec-1.4.1 vs bin/bmde in markdown_exec-1.5

- old
+ new

@@ -6,6 +6,108 @@ require 'bundler/setup' Bundler.require(:default) require_relative '../lib/markdown_exec' -MarkdownExec::MarkParse.new.run +if true + + MarkdownExec::MarkParse.new.run +else + + def trace_event_properties(tp) + # TracePoint.new(:call, :return, :c_call, :c_return, :raise) do |tp| + # puts "Event information:" + # puts "Event type: #{tp.event}" + # puts "File: #{tp.path}" + # puts "Line: #{tp.lineno}" + # puts "Defined class: #{tp.defined_class}" + # puts "Method ID: #{tp.method_id}" + # puts "Class method ID: #{tp.defined_class} #{tp.method_id}" + # puts "Binding: #{tp.binding.inspect}" + # puts "Return value: #{tp.return_value.inspect}" if [:return, :c_return].include?(tp.event) + puts "Raised exception: #{tp.raised_exception.inspect}" if tp.event == :raise + # puts "---------------------------------" + # binding.pry + # print format("\n%-20.20s %-20.20s % 5.5d %20s %s", tp.method_id, tp.defined_class, tp.lineno, tp.path.split('/').last, caller[1].split('/').last) + + # print format("\n%-20.20s %-30.30s %s", tp.method_id, tp.defined_class, caller[1].split('/').last.split(':', 3)[0..1].join(':')) +# print __LINE__, '.' + return if %i[method_missing present?].include?(tp.method_id) + return unless %r(/markdown_exec/lib/) =~ caller[1] + + if [:return, :c_return].include?(tp.event) + print format("%1.1s %-20.20s %s\n", tp.event, tp.method_id, tp.return_value) + else + print format("%1.1s %-20.20s %-30.30s %20s\n", tp.event, tp.method_id, tp.defined_class, $~.post_match) + end + # end.enable + end + + def start_trace(events = [:call]) + trace = TracePoint.new(*events) do |tp| + trace_event_properties(tp) + end + + trace.enable + yield + trace.disable + end + + start_trace([:call, :return]) { MarkdownExec::MarkParse.new.run } + +end + + + +=begin + +To filter what is traced, you can pass any of the following as events: + +:line +execute an expression or statement on a new line + +:class +start a class or module definition + +:end +finish a class or module definition + +:call +call a Ruby method + +:return +return from a Ruby method + +:c_call +call a C-language routine + +:c_return +return from a C-language routine + +:raise +raise an exception + +:b_call +event hook at block entry + +:b_return +event hook at block ending + +:a_call +event hook at all calls (call, b_call, and c_call) + +:a_return +event hook at all returns (return, b_return, and c_return) + +:thread_begin +event hook at thread beginning + +:thread_end +event hook at thread ending + +:fiber_switch +event hook at fiber switch + +:script_compiled +new Ruby code compiled (with eval, load or require) + +=end