因为想跟踪ruby代码执行,所以找到了这个功能,我想在别的语言上也找到响应实现,比如PHP、python。先谈谈ruby上的实现。
tr=TracePoint.new(:call) do |tp|
p [tp.lineno,tp.defined_class,tp.path,tp.method_id]
end
tr.enable
运行这么几行,大功告成。运行情况一览无余。
[204, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :notify?]
[198, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :<=>]
[179, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :peek]
[77, RubyToken, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :Token]
[22, RubyToken::Token, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :initialize
]
[276, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :token]
[69, IRB::SLex, "C:/Ruby22/lib/ruby/2.2.0/irb/slex.rb", :match]
[203, IRB::SLex::Node, "C:/Ruby22/lib/ruby/2.2.0/irb/slex.rb", :match_io]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[143, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :ungetc]
[69, IRB::Notifier::AbstractNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :printf]
[204, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :notify?]
[198, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :<=>]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[179, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :peek]
[179, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :peek]
[747, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :identify_identifier]
[179, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :peek]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[143, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :ungetc]
[77, RubyToken, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :Token]
[38, RubyToken::TkId, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :initialize]
[22, RubyToken::Token, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :initialize
]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[276, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :token]
[69, IRB::SLex, "C:/Ruby22/lib/ruby/2.2.0/irb/slex.rb", :match]
[203, IRB::SLex::Node, "C:/Ruby22/lib/ruby/2.2.0/irb/slex.rb", :match_io]
[101, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc]
[203, IRB::SLex::Node, "C:/Ruby22/lib/ruby/2.2.0/irb/slex.rb", :match_io]
[135, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :getc_of_rests]
[69, IRB::Notifier::AbstractNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :printf]
[204, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :notify?]
[198, IRB::Notifier::LeveledNotifier, "C:/Ruby22/lib/ruby/2.2.0/irb/notifier.rb"
, :<=>]
[33, #<Class:RubyLex>, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :debug?]
[77, RubyToken, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :Token]
[22, RubyToken::Token, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-token.rb", :initialize
]
[89, RubyLex, "C:/Ruby22/lib/ruby/2.2.0/irb/ruby-lex.rb", :get_readed]
[185, IRB::ReadlineInputMethod, "C:/Ruby22/lib/ruby/2.2.0/irb/input-method.rb",