如何描述Rake任务?

我需要描述rake任务。因为我是菜鸟我只知道如何配置.rb代码 像这样:
ruby -Ilib -S ruby-prof -p graph_html profile.rb > profile.html
但是,我如何描述特定的Rake任务?     
已邀请:
Rake只是一个Ruby脚本,所以你应该能够像rake一样调用ruby-prof,就像你描述任何其他脚本一样。 鉴于您调用ruby-prof,请尝试:
ruby -Ilib -S ruby-prof -p graph_html `which rake` TASK > profile.html
我刚刚使用了以下命令行:
ruby-prof -p graph_html /usr/local/bin/rake19 import_from_aws file=~/sourcedata batch=test1 > /tmp/profile.html
分析调用:
rake19 import_from_aws file=~/sourcedata batch=test1
    
如果你想要“粗略”的分析并希望找出哪个任务是瓶颈,我建议Mike William从这里获得优秀的代码。当我分析我的Rake任务时,它工作得很漂亮。
module Rake
  class Task
    def execute_with_timestamps(*args)
      start = Time.now
      execute_without_timestamps(*args)
      execution_time_in_seconds = Time.now - start
      printf("** %s took %.1f secondsn", name, execution_time_in_seconds)
    end

    alias :execute_without_timestamps :execute
    alias :execute :execute_with_timestamps 
  end
end
    
我认为值得一提的是,如果您正在使用bundler,您可能希望使用bundle而不是rake直接对其进行分析。
ruby-prof -p graph_html `which bundle` -- 'exec' 'rake' '-T' > profile.html
    

要回复问题请先登录注册