2010-11-16 95 views
16

我需要分析rake任務。因爲我是noob我只知道如何配置.rb代碼 是這樣的:ruby -Ilib -S ruby-prof -p graph_html profile.rb > profile.html如何分析Rake任務?

但是,如何分析特定的Rake任務?

回答

18

Rake只是一個Ruby腳本,因此您應該能夠像對待其他腳本一樣調用ruby-prof來反對rake。

鑑於你的紅寶石教授的調用,請嘗試:

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 
+0

爲我工作,謝謝! – KIR 2011-05-22 20:17:44

+0

''哪個耙子''做了詭計......我不知道'ruby-prof'需要ruby腳本的完整路徑來描述。 – 2012-04-17 21:07:57

+2

對於那些使用** rbenv **使用'rbenv哪耙' – collimarco 2015-04-15 18:22:11

1

如果你想「粗略」分析,並想找出哪個任務是瓶頸,我建議邁克威廉的優秀片代碼從here。當我分析我的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 seconds\n", name, execution_time_in_seconds) 
    end 

    alias :execute_without_timestamps :execute 
    alias :execute :execute_with_timestamps 
    end 
end