2011-07-04
first time to use ruby-prof
What's ruby-prof
profiler for ruby. would you see RDoc Documentation
Install
would you see RDoc Documentation. I installed version 0.10.7.
% sudo gem install ruby-prof
Usage
There are three ways of running ruby-prof.
The first : ruby-prof executable
for example.
% ruby-prof --printer=flat --file=result --mode=wall hoge.rb
hoge.rb
for i in 1..10000 p i end
result(cat result)
% cat result Thread ID: -604468348 Total: 0.081816 %self total self wait child calls name 37.88 0.03 0.03 0.00 0.00 20000 IO#write 27.31 0.07 0.02 0.00 0.05 10000 Kernel#p 12.84 0.08 0.01 0.00 0.07 1 Range#each 11.71 0.02 0.01 0.00 0.01 10000 Kernel#inspect 10.14 0.01 0.01 0.00 0.00 10000 Fixnum#to_s 0.08 0.08 0.00 0.00 0.08 1 Kernel#load 0.03 0.08 0.00 0.00 0.08 1 Global#[No method] 0.00 0.00 0.00 0.00 0.00 1 <Class::Object>#allocate
The second : ruby-prof API
% ruby hoge.rb
result(STDOUT)
Thread ID: -604386428 Total: 0.082106 %self total self wait child calls name 32.35 0.03 0.03 0.00 0.00 20000 IO#write 28.93 0.07 0.02 0.00 0.05 10000 Kernel#p 14.90 0.08 0.01 0.00 0.07 1 Range#each 13.02 0.02 0.01 0.00 0.01 10000 Kernel#inspect 10.79 0.01 0.01 0.00 0.00 10000 Fixnum#to_s 0.01 0.08 0.00 0.00 0.08 1 Global#[No method]
hoge.rb
require 'rubygems' require 'ruby-prof' # Profile the code result = RubyProf.profile do for i in 1..10000 p i end end # print a flat profile to text printer = RubyProf::FlatPrinter.new(result) profile_options = { :measure_modes => [RubyProf::WALL_TIME], :min_percent => 0 } printer.print(STDOUT, profile_options)
The third : require unprof
% ruby hoge.rb
result(STDOUT)
Thread ID: -604060798 Total: 0.084379 %self total self wait child calls name 33.02 0.03 0.03 0.00 0.00 20000 IO#write 29.09 0.07 0.02 0.00 0.05 10000 Kernel#p 14.07 0.08 0.01 0.00 0.07 1 Range#each 13.25 0.02 0.01 0.00 0.01 10000 Kernel#inspect 10.55 0.01 0.01 0.00 0.00 10000 Fixnum#to_s 0.02 0.08 0.00 0.00 0.08 1 Global#[No method]
hoge.rb
require 'rubygems' require 'unprof' for i in 1..10000 p i end
Graph html
% ruby-prof --printer=graph_html --file=result.html --mode=wall hoge.rb
hoge.rb
for i in 1..10000 p i end
result
KCacheGrind
% ruby-prof --printer=call_tree --file=callgrind.out --mode=wall hoge.rb
hoge.rb
for i in 1..10000 p i end
result view on Windows.
I'm on
| OS | CentOS release 5.3 (Final) |
| ruby | ruby 1.8.6 (2009-06-08 patchlevel 369) [i686-linux] |
| ruby-prof | 0.10.7 |
Reference
トラックバック - http://d.hatena.ne.jp/japanrock_pg/20110704/1309776724
リンク元
- 1242 http://typex2.wordpress.com/2010/01/30/mac-os-xのfinderではパスワード付きzipが解凍できない!?/
- 774 http://www.google.co.jp/url?sa=t&source=web&cd=1&ved=0CBgQFjAA&url=http://d.hatena.ne.jp/japanrock_pg/20090716/1247729449&rct=j&q=ext3 フォーマット windows&ei=osMRTqnvBsL7mAX9gs3GDg&usg=AFQjCNG9RIO
- 257 http://www.google.co.jp/url?sa=t&source=web&cd=1&ved=0CBkQFjAA&url=http://d.hatena.ne.jp/japanrock_pg/20100212/1265972572&rct=j&q=dev/null ファイル 空&ei=NsYoTvgBhv6YBcuKhYkM&usg=AFQjCNHGMJb
- 237 http://www.google.co.jp/url?sa=t&source=web&cd=2&ved=0CB8QFjAB&url=http://d.hatena.ne.jp/japanrock_pg/20070130/1170131237&rct=j&q=放射性崩壊 ランダム&ei=jaQRTo7YAo7ImAXdxa3
- 230 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4SKPT_jaJP415JP415&q=yamaha+rtx1100+windows+7
- 222 http://www.google.co.jp/url?sa=t&source=web&cd=2&ved=0CCAQFjAB&url=http://d.hatena.ne.jp/japanrock_pg/20090513/1242209829&rct=j&q=mysqlコマンド select 出力結果&ei=qnUSTqDzJc-fmQWexq2w
- 187 http://www.google.co.jp/
- 151 http://search.yahoo.co.jp/search?p=既定のブラウザ&aq=0&oq=既定&ei=UTF-8&fr=top_ga1_sa&x=wrt
- 132 http://www.google.co.jp/url?sa=t&source=web&cd=1&sqi=2&ved=0CBgQFjAA&url=http://d.hatena.ne.jp/japanrock_pg/20090409/1239264163&rct=j&q=会社 thunderbird&ei=68sRTqeyLMeHmQXe1-jADg&usg=AFQjCNGUg8rVi90dJI7wXkRdNWL8rM4V9w&sig
- 111 http://www.google.co.jp/url?sa=t&source=web&cd=1&ved=0CBsQFjAA&url=http://d.hatena.ne.jp/japanrock_pg/20080819/1219147029&rct=j&q=yahoo 検索ボックス javascript&ei=XqERToKGL62OmQXF1KCnDg&usg=A




