Skip to content

Instantly share code, notes, and snippets.

@ono-max
Created February 15, 2023 14:36
Show Gist options
  • Save ono-max/ad76cfe83cb3ec1e8c05dad76b46e8f9 to your computer and use it in GitHub Desktop.
Save ono-max/ad76cfe83cb3ec1e8c05dad76b46e8f9 to your computer and use it in GitHub Desktop.
  1. ブロックのみ
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
end
  1. skip? メソッド()を追加
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
  next if skip?(tp)
end
  1. depth を取得
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
  next if skip?(tp)
  depth = caller.size
end
  1. call_identifier_str を取得
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
  next if skip?(tp)
  depth = caller.size
  
  call_identifier_str =
          if tp.defined_class
            minfo(tp)
          else
            "block"
          end
end
  1. :call, :c_call, :b_call のみ配列に挿入
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
  next if skip?(tp)
  depth = caller.size
  
  call_identifier_str =
          if tp.defined_class
            minfo(tp)
          else
            "block"
          end

  case tp.event
    when :call, :c_call, :b_call
      depth += 1 if tp.event == :c_call
      sp = ' ' * depth
      out tp, ">#{sp}#{call_identifier_str}", depth
    end
  end
  1. :return, :c_return, :b_return のみ配列に挿入
@tracer = TracePoint.new(:a_call, :a_return, :line){|tp|
  next if skip?(tp)
  depth = caller.size
  
  call_identifier_str =
          if tp.defined_class
            minfo(tp)
          else
            "block"
          end

  case tp.event
    when :return, :c_return, :b_return
      depth += 1 if tp.event == :c_return
      sp = ' ' * depth
      return_str = DEBUGGER__.safe_inspect(tp.return_value, short: true)
      out tp, "<#{sp}#{call_identifier_str} #=> #{return_str}", depth
    end
  end
トレースなし 0.006943000014871359 0.0072929998859763145 0.013362000230699778 0.007668000180274248 0.007089999970048666
1. ブロックのみ 0.0077840001322329044 0.009405000135302544 0.006493999622762203 0.008220999967306852 0.007183999754488468
2. skip? メソッド追加 0.0473340000025928 0.04438699968159199 0.04924699990078807 0.04245599964633584 0.04979000007733703
3. depth を取得 0.8388209999538958 0.8334289998747408 0.8361980002373457 0.8419610001146793 0.8316079997457564
4. call_identifier_str を取得 0.8489760002121329 0.8583479998633265 0.8502550004050136 0.8412570003420115 0.8319780002348125
5. :call, :c_call, :b_call のみ配列に挿入 0.8854970000684261 0.884879999794066 0.8771480000577867 0.8847179999575019 0.8872270002029836
6. :return, :c_return, :b_return のみ配列に挿入 0.9496829998679459 0.9501910000108182 0.9565590000711381 0.9573569996282458 0.9502260000444949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment