134 lines
13 KiB
Plaintext
134 lines
13 KiB
Plaintext
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="generator" content="TempleOS V5.03">
|
||
|
<meta name="viewport" content="width=device-width">
|
||
|
<link rel="stylesheet" href="/style/templeos.css">
|
||
|
<script src="/script/templeos.js"></script>
|
||
|
<style type="text/css">
|
||
|
.cF0{color:#000000;background-color:#ffffff;}
|
||
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
||
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
||
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
||
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
||
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
||
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
||
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
||
|
.cF8{color:#555555;background-color:#ffffff;}
|
||
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
||
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
||
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
||
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
||
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
||
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
||
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<pre id="content">
|
||
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>"Debugging/Profiler;Profiler;Cmd Line (Typically)/Profiler"</span><span class=cF0>
|
||
|
<a name="l2"></a>#</span><span class=cF1>help_file</span><span class=cF0> </span><span class=cF6>"::/Doc/Profiler"</span><span class=cF0>
|
||
|
<a name="l3"></a>
|
||
|
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>PF_ARRAY_CNT</span><span class=cF0> 0x100000
|
||
|
<a name="l5"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFB>pf_jiffy_start</span><span class=cF0>,</span><span class=cFB>pf_jiffy_end</span><span class=cF0>;
|
||
|
<a name="l6"></a></span><span class=cF9>I64</span><span class=cF0> *</span><span class=cFB>pf_array</span><span class=cF0>=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l7"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFB>pf_cpu</span><span class=cF0>=0;
|
||
|
<a name="l8"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>=0,</span><span class=cFB>pf_depth</span><span class=cF0>;
|
||
|
<a name="l9"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFB>pf_prof_active</span><span class=cF0>=0;
|
||
|
<a name="l10"></a>
|
||
|
<a name="l11"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ProfTimerInt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task)
|
||
|
<a name="l12"></a>{</span><span class=cF2>//See </span><a href="/Wb/Kernel/KInts.HC.HTML#l37"><span class=cF4>profiler_timer_irq</span></a><span class=cF2>.</span><span class=cF0>
|
||
|
<a name="l13"></a> </span><span class=cF9>I64</span><span class=cF0> i,k;
|
||
|
<a name="l14"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>pf_prof_active</span><span class=cF0>,0</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l15"></a> </span><span class=cF1>for</span><span class=cF0> (k=0;k<=</span><span class=cFB>pf_depth</span><span class=cF0>;k++) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l16"></a> </span><span class=cF1>if</span><span class=cF0> (task==</span><span class=cF5>Gs</span><span class=cF0>->idle_task)
|
||
|
<a name="l17"></a> i=</span><span class=cFD>SYS_IDLE_PT</span><span class=cF0>;
|
||
|
<a name="l18"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l19"></a> i=</span><span class=cF5>TaskCaller</span><span class=cF0>(task,k,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0><</span><span class=cF3>PF_ARRAY_CNT</span><span class=cF0>) {
|
||
|
<a name="l21"></a> </span><span class=cFB>pf_array</span><span class=cF0>[</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>++]=i;
|
||
|
<a name="l22"></a> </span><span class=cFB>pf_jiffy_end</span><span class=cF0>=</span><span class=cFB>cnts</span><span class=cF0>.jiffies;
|
||
|
<a name="l23"></a> }
|
||
|
<a name="l24"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l25"></a>}
|
||
|
<a name="l26"></a>
|
||
|
<a name="l27"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>Prof</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> depth=0,</span><span class=cF9>I64</span><span class=cF0> cpu_num=0)
|
||
|
<a name="l28"></a>{</span><span class=cF2>/*Start collecting profiler statistics.</span><span class=cF0>
|
||
|
<a name="l29"></a></span><span class=cF2>Profilers report where time is spent</span><span class=cF0>
|
||
|
<a name="l30"></a></span><span class=cF2>by sampling RIP during the 1000Hz</span><span class=cF0>
|
||
|
<a name="l31"></a></span><span class=cF2>timer interrupt.</span><span class=cF0>
|
||
|
<a name="l32"></a>
|
||
|
<a name="l33"></a></span><span class=cF2>Do a </span><a href="/Wb/Adam/Opt/Utils/Profiler.HC.HTML#l57"><span class=cF4>ProfRep</span></a><span class=cF2>(), (profiler report)</span><span class=cF0>
|
||
|
<a name="l34"></a></span><span class=cF2>after you have collected data.</span><span class=cF0>
|
||
|
<a name="l35"></a></span><span class=cF2>*/</span><span class=cF0>
|
||
|
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0<=cpu_num<</span><span class=cFB>mp_cnt</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l37"></a> </span><span class=cF3>ST_ERR_ST</span><span class=cF0> </span><span class=cF6>"Invalid CPU\n"</span><span class=cF0>;
|
||
|
<a name="l38"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l39"></a> </span><span class=cFB>cpu_structs</span><span class=cF0>[</span><span class=cFB>pf_cpu</span><span class=cF0>].profiler_timer_irq=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l40"></a> </span><span class=cFB>pf_cpu</span><span class=cF0>=cpu_num;
|
||
|
<a name="l41"></a>
|
||
|
<a name="l42"></a> </span><span class=cFB>pf_depth</span><span class=cF0>=depth;
|
||
|
<a name="l43"></a> </span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>=0;
|
||
|
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFB>pf_array</span><span class=cF0>)
|
||
|
<a name="l45"></a> </span><span class=cFB>pf_array</span><span class=cF0>=</span><span class=cF5>AMAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>I64</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>PF_ARRAY_CNT</span><span class=cF0>);
|
||
|
<a name="l46"></a> </span><span class=cFB>pf_jiffy_end</span><span class=cF0>=</span><span class=cFB>pf_jiffy_start</span><span class=cF0>=</span><span class=cFB>cnts</span><span class=cF0>.jiffies;
|
||
|
<a name="l47"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cFB>pf_prof_active</span><span class=cF0>,0);
|
||
|
<a name="l48"></a> </span><span class=cFB>cpu_structs</span><span class=cF0>[</span><span class=cFB>pf_cpu</span><span class=cF0>].profiler_timer_irq=&</span><span class=cF5>ProfTimerInt</span><span class=cF0>;
|
||
|
<a name="l49"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l50"></a>}
|
||
|
<a name="l51"></a>
|
||
|
<a name="l52"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ProfCompare</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *i1,</span><span class=cF1>U8</span><span class=cF0> *i2)
|
||
|
<a name="l53"></a>{
|
||
|
<a name="l54"></a> </span><span class=cF1>return</span><span class=cF0> i1-i2;
|
||
|
<a name="l55"></a>}
|
||
|
<a name="l56"></a>
|
||
|
<a name="l57"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>ProfRep</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> filter_cnt=1,</span><span class=cF1>Bool</span><span class=cF0> leave_it=</span><span class=cF3>OFF</span><span class=cF0>)
|
||
|
<a name="l58"></a>{</span><span class=cF2>//Profiler report. Call </span><a href="/Wb/Adam/Opt/Utils/Profiler.HC.HTML#l27"><span class=cF4>Prof</span></a><span class=cF2>() first and collect data.</span><span class=cF0>
|
||
|
<a name="l59"></a> </span><span class=cF9>I64</span><span class=cF0> i,hits,rip,last_rip=0,routine_total=0;
|
||
|
<a name="l60"></a> </span><span class=cF1>F64</span><span class=cF0> total_time;
|
||
|
<a name="l61"></a> </span><span class=cF1>U8</span><span class=cF0> buf[256],buf2[256],last_buf[256];
|
||
|
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>pf_prof_active</span><span class=cF0>,0</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l63"></a> </span><span class=cF6>"Profiler Not Active\n"</span><span class=cF0>;
|
||
|
<a name="l64"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>)
|
||
|
<a name="l65"></a> </span><span class=cF6>"No Profiler Statistic\n"</span><span class=cF0>;
|
||
|
<a name="l66"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l67"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>total_time=</span><span class=cFB>pf_jiffy_end</span><span class=cF0>-</span><span class=cFB>pf_jiffy_start</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l68"></a> total_time=1;
|
||
|
<a name="l69"></a> </span><span class=cF5>QSortI64</span><span class=cF0>(</span><span class=cFB>pf_array</span><span class=cF0>,</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>,&</span><span class=cF5>ProfCompare</span><span class=cF0>);
|
||
|
<a name="l70"></a> *last_buf=0;
|
||
|
<a name="l71"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0>;i+=hits) {
|
||
|
<a name="l72"></a> rip=</span><span class=cFB>pf_array</span><span class=cF0>[i];
|
||
|
<a name="l73"></a> hits=0;
|
||
|
<a name="l74"></a> </span><span class=cF1>do</span><span class=cF0> hits++;
|
||
|
<a name="l75"></a> </span><span class=cF1>while</span><span class=cF0> (i+hits<</span><span class=cFB>pf_buf_in_ptr</span><span class=cF0> && </span><span class=cFB>pf_array</span><span class=cF0>[i+hits]==rip);
|
||
|
<a name="l76"></a>
|
||
|
<a name="l77"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(buf,</span><span class=cF6>"%p"</span><span class=cF0>,rip);
|
||
|
<a name="l78"></a> </span><span class=cF5>StrFirstRem</span><span class=cF0>(buf,</span><span class=cF6>"+"</span><span class=cF0>,buf2);
|
||
|
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>buf2,last_buf</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (*last_buf && routine_total>=filter_cnt)
|
||
|
<a name="l81"></a> </span><span class=cF6>"$GREEN$%6.2f %08X:%s\n$FG$"</span><span class=cF0>,100*routine_total/total_time,
|
||
|
<a name="l82"></a> routine_total,last_buf;
|
||
|
<a name="l83"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(last_buf,buf2);
|
||
|
<a name="l84"></a> routine_total=0;
|
||
|
<a name="l85"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l86"></a> routine_total+=hits;
|
||
|
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (hits>=filter_cnt) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l88"></a> </span><span class=cF6>"%6.2f %08X:%P\n"</span><span class=cF0>,100*hits/total_time,hits,rip;
|
||
|
<a name="l89"></a> last_rip=rip;
|
||
|
<a name="l90"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l91"></a> }
|
||
|
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (*last_buf && routine_total>=filter_cnt)
|
||
|
<a name="l93"></a> </span><span class=cF6>"$GREEN$%6.2f %08X:%s\n$FG$"</span><span class=cF0>,100*routine_total/total_time,
|
||
|
<a name="l94"></a> routine_total,last_buf;
|
||
|
<a name="l95"></a> </span><span class=cF6>"Total Time:%0.6fs\n"</span><span class=cF0>,total_time/</span><span class=cF3>JIFFY_FREQ</span><span class=cF0>;
|
||
|
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (leave_it) {
|
||
|
<a name="l97"></a> </span><span class=cFB>cpu_structs</span><span class=cF0>[</span><span class=cFB>pf_cpu</span><span class=cF0>].profiler_timer_irq=&</span><span class=cF5>ProfTimerInt</span><span class=cF0>;
|
||
|
<a name="l98"></a> </span><span class=cF5>LBts</span><span class=cF0>(&</span><span class=cFB>pf_prof_active</span><span class=cF0>,0);
|
||
|
<a name="l99"></a> } </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l100"></a> </span><span class=cFB>cpu_structs</span><span class=cF0>[</span><span class=cFB>pf_cpu</span><span class=cF0>].profiler_timer_irq=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l102"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|