2014-01-29 28 views
0

說我有OfInterest功能,通過功能A和B調用,調用函數X和Y.我正在尋找觀看的方式:javascript profiling:顯示單個函數的自頂向下樹的方式?

OfInterest -- 200 ms total time 
    X -- 150 ms total time 
    Y -- 50 ms total time 

...,使得它包括兩個打電話給OfInterest由A和B.

在Chrome探查器,這將是放大OfInterest的自上而下的視圖,除了AFAIK無法同時從A + B呼叫OfInterest 。自下而上的觀點獲得了OfInterest的正確總時間,但AFAIK無法在該視圖中看到X + Y。

有沒有辦法讓Chrome瀏覽器吐出來,或者使用不同的Profiler如Firebug來查看?

回答

0

這GitHub的項目給出了jvascript呼叫統計

https://github.com/brucespang/jsprof

當我一直在尋找一個JavaScript函數調用探查我發現了一個小腳本,其中我修改按我的需要,這個腳本自上而下的樹非常簡單,它將顯示窗口對象中所有全局函數的統計信息,儘管它沒有列出名爲嵌套函數的名稱。

功能callLog() {

var functionPool = {} 

for(var func in window) 
{ 

if (typeof(window[func]) === 'function') 

    { 
    functionPool[func] = window[func]; 
    (function(){ 
     var functionName = func; 
     var totalTime= 0; 
     var noOfTimes =0; 
     var minTime= 0; 
     var maxTime =0; 

     window[functionName] = function(){ 
     var args = [].splice.call(arguments,0); 
     var startTime = +new Date;   
     functionPool[functionName].apply(window, args);  
     var duration = new Date - startTime; 

      if (duration> maxTime) 
       maxTime= duration; 
      if (duration< minTime) 
       minTime= duration; 

     totalTime = totalTime + duration; 
     noOfTimes++ ; 
     console.log('Executed: ' + functionName + '('+args.join(',')+')' + " Time[" + duration + "ms]"+" Total Time[" + totalTime +"ms]" +" No of Times[" + noOfTimes + "]" + "max Time [" + maxTime+ "ms]" + "min Time [" +minTime +"ms]");    

     } 
     })(); 
    } 
} 

}