2010-11-26 12 views

答えて

4

DTraceはこれを行うことができますが、iPhone Simulator(Snow Leopardではサポートされていますが、まだiOSではサポートされていません)でのみ使用できます。私はMacResearch herehereにこの技術に関する2つの記事を書いています。ここでは、DTraceを使用して特定のメソッドと呼び出しのケーススタディを調べています。

#pragma D option quiet 
#pragma D option aggsortrev 

dtrace:::BEGIN 
{ 
    printf("Sampling Core Plot methods ... Hit Ctrl-C to end.\n"); 
    starttime = timestamp;  
} 

objc$target:CP*::entry 
{ 
    starttimeformethod[probemod,probefunc] = timestamp; 
    methodhasenteredatleastonce[probemod,probefunc] = 1; 
} 

objc$target:CP*::return 
/methodhasenteredatleastonce[probemod,probefunc] == 1/ 
{ 
    this->executiontime = (timestamp - starttimeformethod[probemod,probefunc])/1000; 
    @overallexecutions[probemod,probefunc] = count(); 
    @overallexecutiontime[probemod,probefunc] = sum(this->executiontime); 
    @averageexecutiontime[probemod,probefunc] = avg(this->executiontime); 
} 

dtrace:::END 
{ 
    milliseconds = (timestamp - starttime)/1000000; 
    normalize(@overallexecutiontime, 1000); 
    printf("Ran for %u ms\n", milliseconds); 
    printf("%30s %30s %20s %20s %20s\n", "Class", "Method", "Total CPU time (ms)", "Executions", "Average CPU time (us)"); 
    printa("%30s %30s %[email protected] %[email protected] %[email protected]\n", @overallexecutiontime, @overallexecutions, @averageexecutiontime); 
} 

これが生成します。たとえば、私は倍のメソッドの数を測定するには、次のDTraceスクリプトは、CPの接頭辞を持つクラスで呼び出されるだけでなく、それらのメソッドで費やされた時間を合計して

作成しました次きれいにフォーマットされた出力:

 Class       Method Total CPU time (ms)   Executions Average CPU time (us) 
     CPLayer    -drawInContext:     6995     352    19874 
     CPPlot    -drawInContext:     5312     88    60374 
CPScatterPlot  -renderAsVectorInContext:     4332     44    98455 
CPXYPlotSpace  -viewPointForPlotPoint:     3208     4576     701 
     CPAxis    -layoutSublayers     2050     44    46595 
CPXYPlotSpace -viewCoordinateForViewLength:linearPlotRange:plotCoordinateValue:     1870     9152 
... 

コマンドラインからDTraceのスクリプトを作成して実行することができますが、おそらくあなたの最善の策は楽器でカスタム楽器を作成することと、その機器内の適切なDコードを記入します。 Simulatorでアプリケーションに対して簡単に実行できます。

この場合も、デバイスでは機能しませんが、何かが呼び出された回数の統計と、それが実行されている時間の統計だけが必要な場合は、これがジョブを実行する可能性があります。

+0

Brad Larson - 「あなたの最善の策は、楽器でカスタム楽器を作成し、その楽器内の適切なDコードを入力することです」 - どうすればよいですか?私がしたときに、文法エラーが発生する... – shmim

+0

具体的には、上記のスクリプトを入力すると、私の望む通りになるでしょう:-) – shmim

+0

また、あなたの記事へのリンクは死んでいます... – shmim

関連する問題