Class: RubyProf::CallStackPrinter
- Inherits:
-
AbstractPrinter
- Object
- AbstractPrinter
- RubyProf::CallStackPrinter
- Includes:
- ERB::Util
- Defined in:
- lib/ruby-prof/printers/call_stack_printer.rb
Overview
prints a HTML visualization of the call tree
Instance Method Summary collapse
- #application ⇒ Object
- #arguments ⇒ Object
- #color(p) ⇒ Object
- #copy_image_files ⇒ Object
- #dump(ci) ⇒ Object
- #expansion ⇒ Object
- #graph_link(call_info) ⇒ Object
- #link(call_info) ⇒ Object
- #method_href(method) ⇒ Object
- #name(call_info) ⇒ Object
-
#print(output = STDOUT, options = {}) ⇒ Object
Specify print options.
- #print_commands ⇒ Object
- #print_css ⇒ Object
- #print_footer ⇒ Object
- #print_header ⇒ Object
- #print_help ⇒ Object
- #print_java_script ⇒ Object
- #print_stack(call_info, parent_time) ⇒ Object
- #print_title_bar ⇒ Object
- #sum(a) ⇒ Object
- #threshold ⇒ Object
- #title ⇒ Object
- #total_time(call_infos) ⇒ Object
Methods inherited from AbstractPrinter
#initialize, #method_name, #min_percent, #print_file, #print_thread, #print_threads, #setup_options, #sort_method
Constructor Details
This class inherits a constructor from RubyProf::AbstractPrinter
Instance Method Details
#application ⇒ Object
163 164 165 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 163 def application [:application] || $PROGRAM_NAME end |
#arguments ⇒ Object
167 168 169 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 167 def arguments ARGV.join(' ') end |
#color(p) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 150 def color(p) case i = p.to_i when 0..5 "01" when 5..10 "05" when 100 "9" else "#{i/10}" end end |
#copy_image_files ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 183 def copy_image_files if @output.is_a?(File) target_dir = File.dirname(@output.path) image_dir = File.join(File.dirname(__FILE__), '..', 'images') %w(empty plus minus).each do |img| source_file = "#{image_dir}/#{img}.png" target_file = "#{target_dir}/#{img}.png" FileUtils.cp(source_file, target_file) unless File.exist?(target_file) end end end |
#dump(ci) ⇒ Object
146 147 148 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 146 def dump(ci) $stderr.printf "%s/%d t:%f s:%f w:%f \n", ci, ci.object_id, ci.total_time, ci.self_time, ci.wait_time end |
#expansion ⇒ Object
179 180 181 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 179 def expansion [:expansion] || 10.0 end |
#graph_link(call_info) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 127 def graph_link(call_info) total_calls = call_info.target.call_infos.inject(0){|t, ci| t += ci.called} href = "#{@graph_html}##{method_href(call_info.target)}" totals = @graph_html ? "<a href='#{href}'>#{total_calls}</a>" : total_calls.to_s "[#{call_info.called} calls, #{totals} total]" end |
#link(call_info) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 113 def link(call_info) method = call_info.target file = File.(method.source_file) if file =~ /\/ruby_runtime$/ h(name(call_info)) else if RUBY_PLATFORM =~ /darwin/ "<a href=\"txmt://open?url=file://#{file}&line=#{method.line}\">#{h(name(call_info))}</a>" else "<a href=\"file://#{file}##{method.line}\">#{h(name(call_info))}</a>" end end end |
#method_href(method) ⇒ Object
134 135 136 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 134 def method_href(method) h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + @current_thread_id.to_s) end |
#name(call_info) ⇒ Object
108 109 110 111 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 108 def name(call_info) method = call_info.target method.full_name end |
#print(output = STDOUT, options = {}) ⇒ Object
Specify print options.
options - Hash table
:min_percent - Number 0 to 100 that specifes the minimum
self (the methods self time divided by the
overall total time) that a method must take
for it to be printed out in the report.
Default value is 0.
:print_file - True or false. Specifies if a method's source
file should be printed. Default value if false.
:threshold - a float from 0 to 100 that sets the threshold of
results displayed.
Default value is 1.0
:title - a String to overide the default "ruby-prof call tree"
title of the report.
:expansion - a float from 0 to 100 that sets the threshold of
results that are expanded, if the percent_total
exceeds it.
Default value is 10.0
:application - a String to overide the name of the application,
as it appears on the report.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 38 def print(output = STDOUT, = {}) @output = output () if @graph_html = .delete(:graph) @graph_html = "file://" + @graph_html if @graph_html[0]=="/" end print_header @overall_threads_time = @result.threads.inject(0) do |val, thread| val += thread.total_time end @result.threads.each do |thread| @current_thread_id = thread.fiber_id @overall_time = thread.total_time thread_info = "Thread: #{thread.id}" thread_info << ", Fiber: #{thread.fiber_id}" unless thread.id == thread.fiber_id thread_info << " (#{"%4.2f%%" % ((@overall_time/@overall_threads_time)*100)} ~ #{@overall_time})" @output.print "<div class=\"thread\">#{thread_info}</div>" @output.print "<ul name=\"thread\">" thread.methods.each do |m| # $stderr.print m.dump next unless m.root? m.call_infos.each do |ci| next unless ci.root? print_stack ci, thread.total_time end end @output.print "</ul>" end copy_image_files end |
#print_commands ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 741 def print_commands @output.puts "<div id=\\\"commands\\\">\n<span style=\\\"font-size: 11pt; font-weight: bold;\\\">Threshold:</span>\n<input value=\\\"\#{h threshold}\\\" size=\\\"3\\\" id=\\\"threshold\\\" type=\\\"text\\\">\n<input value=\\\"Apply\\\" onclick=\\\"setThreshold();\\\" type=\\\"submit\\\">\n<input value=\\\"Expand All\\\" onclick=\\\"expandAll(event);\\\" type=\\\"submit\\\">\n<input value=\\\"Collapse All\\\" onclick=\\\"collapseAll(event);\\\" type=\\\"submit\\\">\n<input value=\\\"Show Help\\\" onclick=\\\"toggleHelp(this);\\\" type=\\\"submit\\\">\n</div>\n" end |
#print_css ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 211 def print_css @output.puts "<style type=\"text/css\">\n<!--\nbody {\nfont-size:70%;\npadding:0px;\nmargin:5px;\nmargin-right:0px;\nmargin-left:0px;\nbackground: #ffffff;\n}\nul {\nmargin-left:0px;\nmargin-top:0px;\nmargin-bottom:0px;\npadding-left:0px;\nlist-style-type:none;\n}\nli {\nmargin-left:11px;\npadding:0px;\nwhite-space:nowrap;\nborder-top:1px solid #cccccc;\nborder-left:1px solid #cccccc;\nborder-bottom:none;\n}\n.thread {\nmargin-left:11px;\nbackground:#708090;\npadding-top:3px;\npadding-left:12px;\npadding-bottom:2px;\nborder-left:1px solid #CCCCCC;\nborder-top:1px solid #CCCCCC;\nfont-weight:bold;\n}\n.hidden {\ndisplay:none;\nwidth:0px;\nheight:0px;\nmargin:0px;\npadding:0px;\nborder-style:none;\n}\n.color01 { background:#adbdeb }\n.color05 { background:#9daddb }\n.color0 { background:#8d9dcb }\n.color1 { background:#89bccb }\n.color2 { background:#56e3e7 }\n.color3 { background:#32cd70 }\n.color4 { background:#a3d53c }\n.color5 { background:#c4cb34 }\n.color6 { background:#dcb66d }\n.color7 { background:#cda59e }\n.color8 { background:#be9d9c }\n.color9 { background:#cf947a }\n#commands {\nfont-size:10pt;\npadding:10px;\nmargin-left:11px;\nmargin-bottom:0px;\nmargin-top:0px;\nbackground:#708090;\nborder-top:1px solid #cccccc;\nborder-left:1px solid #cccccc;\nborder-bottom:none;\n}\n#titlebar {\nfont-size:10pt;\npadding:10px;\nmargin-left:11px;\nmargin-bottom:0px;\nmargin-top:10px;\nbackground:#8090a0;\nborder-top:1px solid #cccccc;\nborder-left:1px solid #cccccc;\nborder-bottom:none;\n}\n#help {\nfont-size:10pt;\npadding:10px;\nmargin-left:11px;\nmargin-bottom:0px;\nmargin-top:0px;\nbackground:#8090a0;\ndisplay:none;\nborder-top:1px solid #cccccc;\nborder-left:1px solid #cccccc;\nborder-bottom:none;\n}\n#sentinel {\nheight: 400px;\nmargin-left:11px;\nbackground:#8090a0;\nborder-top:1px solid #cccccc;\nborder-left:1px solid #cccccc;\nborder-bottom:none;\n}\ninput { margin-left:10px; }\n-->\n</style>\n" end |
#print_footer ⇒ Object
207 208 209 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 207 def @output.puts '<div id="sentinel"></div></div></body></html>' end |
#print_header ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 195 def print_header @output.puts "<html><head>" @output.puts '<meta http-equiv="content-type" content="text/html; charset=utf-8">' @output.puts "<title>#{h title}</title>" print_css print_java_script @output.puts '</head><body><div style="display: inline-block;">' print_commands print_help end |
#print_help ⇒ Object
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 754 def print_help @output.puts "<div style=\"display: none;\" id=\"help\">\n<img src=\"empty.png\"> Enter a decimal value <i>d</i> into the threshold field and click \"Apply\"\nto hide all nodes marked with time values lower than <i>d</i>.<br>\n<img src=\"empty.png\"> Click on \"Expand All\" for full tree expansion.<br>\n<img src=\"empty.png\"> Click on \"Collapse All\" to show only top level nodes.<br>\n<img src=\"empty.png\"> Use a, s, d, w as in Quake or Urban Terror to navigate the tree.<br>\n<img src=\"empty.png\"> Use f and b to navigate the tree in preorder forward and backwards.<br>\n<img src=\"empty.png\"> Use x to toggle visibility of a subtree.<br>\n<img src=\"empty.png\"> Use * to expand/collapse a whole subtree.<br>\n<img src=\"empty.png\"> Use h to navigate to thread root.<br>\n<img src=\"empty.png\"> Use n and p to navigate between threads.<br>\n<img src=\"empty.png\"> Click on background to move focus to a subtree.<br>\n</div>\n" end |
#print_java_script ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 316 def print_java_script @output.puts "<script type=\"text/javascript\">\n/*\nCopyright (C) 2005,2009 Stefan Kaes\[email protected]\n*/\n\nfunction rootNode() {\nreturn currentThread;\n}\n\nfunction hideUL(node) {\nvar lis = node.childNodes\nvar l = lis.length;\nfor (var i=0; i < l ; i++ ) {\nhideLI(lis[i]);\n}\n}\n\nfunction showUL(node) {\nvar lis = node.childNodes;\nvar l = lis.length;\nfor (var i=0; i < l ; i++ ) {\nshowLI(lis[i]);\n}\n}\n\nfunction findUlChild(li){\nvar ul = li.childNodes[2];\nwhile (ul && ul.nodeName != \"UL\") {\nul = ul.nextSibling;\n}\nreturn ul;\n}\n\nfunction isLeafNode(li) {\nvar img = li.firstChild;\nreturn (img.src.indexOf('empty.png') > -1);\n}\n\nfunction hideLI(li) {\nif (isLeafNode(li))\nreturn;\n\nvar img = li.firstChild;\nimg.src = 'plus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'none';\nhideUL(ul);\n}\n}\n\nfunction showLI(li) {\nif (isLeafNode(li))\nreturn;\n\nvar img = li.firstChild;\nimg.src = 'minus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'block';\nshowUL(ul);\n}\n}\n\nfunction toggleLI(li) {\nvar img = li.firstChild;\nif (img.src.indexOf(\"minus.png\")>-1)\nhideLI(li);\nelse {\nif (img.src.indexOf(\"plus.png\")>-1)\nshowLI(li);\n}\n}\n\nfunction aboveThreshold(text, threshold) {\nvar match = text.match(/\\d+[.,]\\d+/);\nreturn (match && parseFloat(match[0].replace(/,/, '.'))>=threshold);\n}\n\nfunction setThresholdLI(li, threshold) {\nvar img = li.firstChild;\nvar text = img.nextSibling;\nvar ul = findUlChild(li);\n\nvar visible = aboveThreshold(text.nodeValue, threshold) ? 1 : 0;\n\nvar count = 0;\nif (ul) {\ncount = setThresholdUL(ul, threshold);\n}\nif (count>0) {\nimg.src = 'minus.png';\n}\nelse {\nimg.src = 'empty.png';\n}\nif (visible) {\nli.style.display = 'block'\n}\nelse {\nli.style.display = 'none'\n}\nreturn visible;\n}\n\nfunction setThresholdUL(node, threshold) {\nvar lis = node.childNodes;\nvar l = lis.length;\n\nvar count = 0;\nfor ( var i = 0; i < l ; i++ ) {\ncount = count + setThresholdLI(lis[i], threshold);\n}\n\nvar visible = (count > 0) ? 1 : 0;\nif (visible) {\nnode.style.display = 'block';\n}\nelse {\nnode.style.display = 'none';\n}\nreturn visible;\n}\n\nfunction toggleChildren(img, event) {\nevent.cancelBubble=true;\n\nif (img.src.indexOf('empty.png') > -1)\nreturn;\n\nvar minus = (img.src.indexOf('minus.png') > -1);\n\nif (minus) {\nimg.src = 'plus.png';\n}\nelse\nimg.src = 'minus.png';\n\nvar li = img.parentNode;\nvar ul = findUlChild(li);\nif (ul) {\nif (minus)\nul.style.display = 'none';\nelse\nul.style.display = 'block';\n}\nif (minus)\nmoveSelectionIfNecessary(li);\n}\n\nfunction showChildren(li) {\nvar img = li.firstChild;\nif (img.src.indexOf('empty.png') > -1)\nreturn;\nimg.src = 'minus.png';\n\nvar ul = findUlChild(li);\nif (ul) {\nul.style.display = 'block';\n}\n}\n\nfunction setThreshold() {\nvar tv = document.getElementById(\"threshold\").value;\nif (tv.match(/[0-9]+([.,][0-9]+)?/)) {\nvar f = parseFloat(tv.replace(/,/, '.'));\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nsetThresholdUL(threads[i], f);\n}\nvar p = selectedNode;\nwhile (p && p.style.display=='none')\np=p.parentNode.parentNode;\nif (p && p.nodeName==\"LI\")\nselectNode(p);\n}\nelse {\nalert(\"Please specify a decimal number as threshold value!\");\n}\n}\n\nfunction collapseAll(event) {\nevent.cancelBubble=true;\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nhideUL(threads[i]);\n}\nselectNode(rootNode(), null);\n}\n\nfunction expandAll(event) {\nevent.cancelBubble=true;\nvar threads = document.getElementsByName(\"thread\");\nvar l = threads.length;\nfor ( var i = 0; i < l ; i++ ) {\nshowUL(threads[i]);\n}\n}\n\nfunction toggleHelp(node) {\nvar help = document.getElementById(\"help\");\nif (node.value == \"Show Help\") {\nnode.value = \"Hide Help\";\nhelp.style.display = 'block';\n}\nelse {\nnode.value = \"Show Help\";\nhelp.style.display = 'none';\n}\n}\n\nvar selectedNode = null;\nvar selectedColor = null;\nvar selectedThread = null;\n\nfunction descendentOf(a,b){\nwhile (a!=b && b!=null)\nb=b.parentNode;\nreturn (a==b);\n}\n\nfunction moveSelectionIfNecessary(node){\nif (descendentOf(node, selectedNode))\nselectNode(node, null);\n}\n\nfunction selectNode(node, event) {\nif (event) {\nevent.cancelBubble = true;\nthread = findThread(node);\nselectThread(thread);\n}\nif (selectedNode) {\nselectedNode.style.background = selectedColor;\n}\nselectedNode = node;\nselectedColor = node.style.background;\nselectedNode.style.background = \"red\";\nselectedNode.scrollIntoView();\nwindow.scrollBy(0,-400);\n}\n\nfunction moveUp(){\nvar p = selectedNode.previousSibling;\nwhile (p && p.style.display == 'none')\np = p.previousSibling;\nif (p && p.nodeName == \"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveDown(){\nvar p = selectedNode.nextSibling;\nwhile (p && p.style.display == 'none')\np = p.nextSibling;\nif (p && p.nodeName == \"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveLeft(){\nvar p = selectedNode.parentNode.parentNode;\nif (p && p.nodeName==\"LI\") {\nselectNode(p, null);\n}\n}\n\nfunction moveRight(){\nif (!isLeafNode(selectedNode)) {\nshowChildren(selectedNode);\nvar ul = findUlChild(selectedNode);\nif (ul) {\nselectNode(ul.firstChild, null);\n}\n}\n}\n\nfunction moveForward(){\nif (isLeafNode(selectedNode)) {\nvar p = selectedNode;\nwhile ((p.nextSibling == null || p.nextSibling.style.display=='none') && p.nodeName==\"LI\") {\np = p.parentNode.parentNode;\n}\nif (p.nodeName==\"LI\")\nselectNode(p.nextSibling, null);\n}\nelse {\nmoveRight();\n}\n}\n\nfunction isExpandedNode(li){\nvar img = li.firstChild;\nreturn(img.src.indexOf('minus.png')>-1);\n}\n\nfunction moveBackward(){\nvar p = selectedNode;\nvar q = p.previousSibling;\nwhile (q != null && q.style.display=='none')\nq = q.previousSibling;\nif (q == null) {\np = p.parentNode.parentNode;\n} else {\nwhile (!isLeafNode(q) && isExpandedNode(q)) {\nq = findUlChild(q).lastChild;\nwhile (q.style.display=='none')\nq = q.previousSibling;\n}\np = q;\n}\nif (p.nodeName==\"LI\")\nselectNode(p, null);\n}\n\nfunction moveHome() {\nselectNode(currentThread);\n}\n\nvar currentThreadIndex = null;\n\nfunction findThread(node){\nwhile (node && node.parentNode.nodeName!=\"BODY\") {\nnode = node.parentNode;\n}\nreturn node.firstChild;\n}\n\nfunction selectThread(node){\nvar threads = document.getElementsByName(\"thread\");\ncurrentThread = node;\nfor (var i=0; i<threads.length; i++) {\nif (threads[i]==currentThread.parentNode)\ncurrentThreadIndex = i;\n}\n}\n\nfunction nextThread(){\nvar threads = document.getElementsByName(\"thread\");\nif (currentThreadIndex==threads.length-1)\ncurrentThreadIndex = 0;\nelse\ncurrentThreadIndex += 1\ncurrentThread = threads[currentThreadIndex].firstChild;\nselectNode(currentThread, null);\n}\n\nfunction previousThread(){\nvar threads = document.getElementsByName(\"thread\");\nif (currentThreadIndex==0)\ncurrentThreadIndex = threads.length-1;\nelse\ncurrentThreadIndex -= 1\ncurrentThread = threads[currentThreadIndex].firstChild;\nselectNode(currentThread, null);\n}\n\nfunction switchThread(node, event){\nevent.cancelBubble = true;\nselectThread(node.nextSibling.firstChild);\nselectNode(currentThread, null);\n}\n\nfunction handleKeyEvent(event){\nvar code = event.charCode ? event.charCode : event.keyCode;\nvar str = String.fromCharCode(code);\nswitch (str) {\ncase \"a\": moveLeft(); break;\ncase \"s\": moveDown(); break;\ncase \"d\": moveRight(); break;\ncase \"w\": moveUp(); break;\ncase \"f\": moveForward(); break;\ncase \"b\": moveBackward(); break;\ncase \"x\": toggleChildren(selectedNode.firstChild, event); break;\ncase \"*\": toggleLI(selectedNode); break;\ncase \"n\": nextThread(); break;\ncase \"h\": moveHome(); break;\ncase \"p\": previousThread(); break;\n}\n}\ndocument.onkeypress=function(event){ handleKeyEvent(event) };\n\nwindow.onload=function(){\nvar images = document.getElementsByTagName(\"img\");\nfor (var i=0; i<images.length; i++) {\nvar img = images[i];\nif (img.className == \"toggle\") {\nimg.onclick = function(event){ toggleChildren(this, event); };\n}\n}\nvar divs = document.getElementsByTagName(\"div\");\nfor (i=0; i<divs.length; i++) {\nvar div = divs[i];\nif (div.className == \"thread\")\ndiv.onclick = function(event){ switchThread(this, event) };\n}\nvar lis = document.getElementsByTagName(\"li\");\nfor (var i=0; i<lis.length; i++) {\nlis[i].onclick = function(event){ selectNode(this, event); };\n}\nvar threads = document.getElementsByName(\"thread\");\ncurrentThreadIndex = 0;\ncurrentThread = threads[0].firstChild;\nselectNode(currentThread, null);\n}\n</script>\n" end |
#print_stack(call_info, parent_time) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 75 def print_stack(call_info, parent_time) total_time = call_info.total_time percent_parent = (total_time/parent_time)*100 percent_total = (total_time/@overall_time)*100 return unless percent_total > min_percent color = self.color(percent_total) kids = call_info.children visible = percent_total >= threshold = percent_total >= expansion display = visible ? "block" : "none" @output.print "<li class=\"color#{color}\" style=\"display:#{display}\">" if kids.empty? @output.print "<img src=\"empty.png\">" else visible_children = kids.any?{|ci| (ci.total_time/@overall_time)*100 >= threshold} image = visible_children ? ( ? "minus" : "plus") : "empty" @output.print "<img class=\"toggle\" src=\"#{image}.png\">" end @output.printf " %4.2f%% (%4.2f%%) %s %s\n", percent_total, percent_parent, link(call_info), graph_link(call_info) unless kids.empty? if @output.print "<ul>" else @output.print '<ul style="display:none">' end kids.sort_by{|c| -c.total_time}.each do |callinfo| print_stack callinfo, total_time end @output.print "</ul>" end @output.print "</li>" end |
#print_title_bar ⇒ Object
732 733 734 735 736 737 738 739 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 732 def @output.puts "<div id=\"titlebar\">\nCall tree for application <b>\#{h application} \#{h arguments}</b><br/>\nGenerated on \#{Time.now} with options \#{h @options.inspect}<br/>\n</div>\n" end |
#sum(a) ⇒ Object
142 143 144 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 142 def sum(a) a.inject(0.0){|s,t| s+=t} end |
#threshold ⇒ Object
175 176 177 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 175 def threshold [:threshold] || 1.0 end |
#title ⇒ Object
171 172 173 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 171 def title @title ||= .delete(:title) || "ruby-prof call tree" end |
#total_time(call_infos) ⇒ Object
138 139 140 |
# File 'lib/ruby-prof/printers/call_stack_printer.rb', line 138 def total_time(call_infos) sum(call_infos.map{|ci| ci.total_time}) end |