📄 profilertimerfilter.html
字号:
<a name="265" href="#265">265</a> <a href="../../../../../org/apache/mina/common/IdleStatus.html">IdleStatus</a> status) <strong class="jxr_keyword">throws</strong> Exception {<a name="266" href="#266">266</a> <strong class="jxr_keyword">long</strong> start = timeUnit.timeNow();<a name="267" href="#267">267</a> nextFilter.sessionIdle(session, status);<a name="268" href="#268">268</a> <strong class="jxr_keyword">long</strong> end = timeUnit.timeNow();<a name="269" href="#269">269</a> <a name="270" href="#270">270</a> <strong class="jxr_keyword">if</strong> (getEventsToProfile().contains(IoEventType.SESSION_IDLE)) {<a name="271" href="#271">271</a> timerManager.get(IoEventType.SESSION_IDLE).addNewReading(<a name="272" href="#272">272</a> end - start);<a name="273" href="#273">273</a> }<a name="274" href="#274">274</a> }<a name="275" href="#275">275</a> <a name="276" href="#276">276</a> @Override<a name="277" href="#277">277</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> sessionOpened(<a href="../../../../../org/apache/mina/common/IoFilter.html">NextFilter</a> nextFilter, <a href="../../../../../org/apache/mina/common/IoSession.html">IoSession</a> session)<a name="278" href="#278">278</a> <strong class="jxr_keyword">throws</strong> Exception {<a name="279" href="#279">279</a> <strong class="jxr_keyword">long</strong> start = timeUnit.timeNow();<a name="280" href="#280">280</a> nextFilter.sessionOpened(session);<a name="281" href="#281">281</a> <strong class="jxr_keyword">long</strong> end = timeUnit.timeNow();<a name="282" href="#282">282</a> <a name="283" href="#283">283</a> <strong class="jxr_keyword">if</strong> (getEventsToProfile().contains(IoEventType.SESSION_OPENED)) {<a name="284" href="#284">284</a> timerManager.get(IoEventType.SESSION_OPENED).addNewReading(<a name="285" href="#285">285</a> end - start);<a name="286" href="#286">286</a> }<a name="287" href="#287">287</a> }<a name="288" href="#288">288</a> <a name="289" href="#289">289</a> <em class="jxr_javadoccomment">/**</em><a name="290" href="#290">290</a> <em class="jxr_javadoccomment"> * Get the average time for the specified method represented by the {@link IoEventType}</em><a name="291" href="#291">291</a> <em class="jxr_javadoccomment"> *</em><a name="292" href="#292">292</a> <em class="jxr_javadoccomment"> * @param type</em><a name="293" href="#293">293</a> <em class="jxr_javadoccomment"> * The {@link IoEventType} that the user wants to get the average method call time</em><a name="294" href="#294">294</a> <em class="jxr_javadoccomment"> * @return</em><a name="295" href="#295">295</a> <em class="jxr_javadoccomment"> * The average time it took to execute the method represented by the {@link IoEventType}</em><a name="296" href="#296">296</a> <em class="jxr_javadoccomment"> */</em><a name="297" href="#297">297</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">double</strong> getAverageTime(<a href="../../../../../org/apache/mina/common/IoEventType.html">IoEventType</a> type) {<a name="298" href="#298">298</a> <strong class="jxr_keyword">if</strong> (!timerManager.containsKey(type)) {<a name="299" href="#299">299</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="300" href="#300">300</a> <span class="jxr_string">"You are not monitoring this event. Please add this event first."</span>);<a name="301" href="#301">301</a> }<a name="302" href="#302">302</a> <a name="303" href="#303">303</a> <strong class="jxr_keyword">return</strong> timerManager.get(type).getAverage();<a name="304" href="#304">304</a> }<a name="305" href="#305">305</a> <a name="306" href="#306">306</a> <em class="jxr_javadoccomment">/**</em><a name="307" href="#307">307</a> <em class="jxr_javadoccomment"> * Gets the total number of times the method has been called that is represented by the</em><a name="308" href="#308">308</a> <em class="jxr_javadoccomment"> * {@link IoEventType}</em><a name="309" href="#309">309</a> <em class="jxr_javadoccomment"> *</em><a name="310" href="#310">310</a> <em class="jxr_javadoccomment"> * @param type</em><a name="311" href="#311">311</a> <em class="jxr_javadoccomment"> * The {@link IoEventType} that the user wants to get the total number of method calls</em><a name="312" href="#312">312</a> <em class="jxr_javadoccomment"> * @return</em><a name="313" href="#313">313</a> <em class="jxr_javadoccomment"> * The total number of method calls for the method represented by the {@link IoEventType}</em><a name="314" href="#314">314</a> <em class="jxr_javadoccomment"> */</em><a name="315" href="#315">315</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getTotalCalls(<a href="../../../../../org/apache/mina/common/IoEventType.html">IoEventType</a> type) {<a name="316" href="#316">316</a> <strong class="jxr_keyword">if</strong> (!timerManager.containsKey(type)) {<a name="317" href="#317">317</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="318" href="#318">318</a> <span class="jxr_string">"You are not monitoring this event. Please add this event first."</span>);<a name="319" href="#319">319</a> }<a name="320" href="#320">320</a> <a name="321" href="#321">321</a> <strong class="jxr_keyword">return</strong> timerManager.get(type).getCalls();<a name="322" href="#322">322</a> }<a name="323" href="#323">323</a> <a name="324" href="#324">324</a> <em class="jxr_javadoccomment">/**</em><a name="325" href="#325">325</a> <em class="jxr_javadoccomment"> * The total time this method has been executing</em><a name="326" href="#326">326</a> <em class="jxr_javadoccomment"> *</em><a name="327" href="#327">327</a> <em class="jxr_javadoccomment"> * @param type</em><a name="328" href="#328">328</a> <em class="jxr_javadoccomment"> * The {@link IoEventType} that the user wants to get the total time this method has</em><a name="329" href="#329">329</a> <em class="jxr_javadoccomment"> * been executing</em><a name="330" href="#330">330</a> <em class="jxr_javadoccomment"> * @return</em><a name="331" href="#331">331</a> <em class="jxr_javadoccomment"> * The total time for the method represented by the {@link IoEventType}</em><a name="332" href="#332">332</a> <em class="jxr_javadoccomment"> */</em><a name="333" href="#333">333</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getTotalTime(<a href="../../../../../org/apache/mina/common/IoEventType.html">IoEventType</a> type) {<a name="334" href="#334">334</a> <strong class="jxr_keyword">if</strong> (!timerManager.containsKey(type)) {<a name="335" href="#335">335</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="336" href="#336">336</a> <span class="jxr_string">"You are not monitoring this event. Please add this event first."</span>);<a name="337" href="#337">337</a> }<a name="338" href="#338">338</a> <a name="339" href="#339">339</a> <strong class="jxr_keyword">return</strong> timerManager.get(type).getTotal();<a name="340" href="#340">340</a> }<a name="341" href="#341">341</a> <a name="342" href="#342">342</a> <em class="jxr_javadoccomment">/**</em><a name="343" href="#343">343</a> <em class="jxr_javadoccomment"> * The minimum time the method represented by {@link IoEventType} has executed</em><a name="344" href="#344">344</a> <em class="jxr_javadoccomment"> *</em><a name="345" href="#345">345</a> <em class="jxr_javadoccomment"> * @param type</em><a name="346" href="#346">346</a> <em class="jxr_javadoccomment"> * The {@link IoEventType} that the user wants to get the minimum time this method has</em><a name="347" href="#347">347</a> <em class="jxr_javadoccomment"> * executed</em><a name="348" href="#348">348</a> <em class="jxr_javadoccomment"> * @return</em><a name="349" href="#349">349</a> <em class="jxr_javadoccomment"> * The minimum time this method has executed represented by the {@link IoEventType}</em><a name="350" href="#350">350</a> <em class="jxr_javadoccomment"> */</em><a name="351" href="#351">351</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getMinimumTime(<a href="../../../../../org/apache/mina/common/IoEventType.html">IoEventType</a> type) {<a name="352" href="#352">352</a> <strong class="jxr_keyword">if</strong> (!timerManager.containsKey(type)) {<a name="353" href="#353">353</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="354" href="#354">354</a> <span class="jxr_string">"You are not monitoring this event. Please add this event first."</span>);<a name="355" href="#355">355</a> }<a name="356" href="#356">356</a> <a name="357" href="#357">357</a> <strong class="jxr_keyword">return</strong> timerManager.get(type).getMinimum();<a name="358" href="#358">358</a> }<a name="359" href="#359">359</a> <a name="360" href="#360">360</a> <em class="jxr_javadoccomment">/**</em><a name="361" href="#361">361</a> <em class="jxr_javadoccomment"> * The maximum time the method represented by {@link IoEventType} has executed</em><a name="362" href="#362">362</a> <em class="jxr_javadoccomment"> *</em><a name="363" href="#363">363</a> <em class="jxr_javadoccomment"> * @param type</em><a name="364" href="#364">364</a> <em class="jxr_javadoccomment"> * The {@link IoEventType} that the user wants to get the maximum time this method has</em><a name="365" href="#365">365</a> <em class="jxr_javadoccomment"> * executed</em><a name="366" href="#366">366</a> <em class="jxr_javadoccomment"> * @return</em><a name="367" href="#367">367</a> <em class="jxr_javadoccomment"> * The maximum time this method has executed represented by the {@link IoEventType}</em><a name="368" href="#368">368</a> <em class="jxr_javadoccomment"> */</em><a name="369" href="#369">369</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">long</strong> getMaximumTime(<a href="../../../../../org/apache/mina/common/IoEventType.html">IoEventType</a> type) {<a name="370" href="#370">370</a> <strong class="jxr_keyword">if</strong> (!timerManager.containsKey(type)) {<a name="371" href="#371">371</a> <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> IllegalArgumentException(<a name="372" href="#372">372</a> <span class="jxr_string">"You are not monitoring this event. Please add this event first."</span>);<a name="373" href="#373">373</a> }<a name="374" href="#374">374</a> <a name="375" href="#375">375</a> <strong class="jxr_keyword">return</strong> timerManager.get(type).getMaximum();<a name="376" href="#376">376</a> }<a name="377" href="#377">377</a> <a name="378" href="#378">378</a> <em class="jxr_javadoccomment">/**</em><a name="379" href="#379">379</a> <em class="jxr_javadoccomment"> * Class that will track the time each method takes and be able to provide information</em><a name="380" href="#380">380</a> <em class="jxr_javadoccomment"> * for each method.</em><a name="381" href="#381">381</a> <em class="jxr_javadoccomment"> *</em><a name="382" href="#382">382</a> <em class="jxr_javadoccomment"> */</em><a name="383" href="#383">383</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../../org/apache/mina/filter/statistic/ProfilerTimerFilter.html">TimerWorker</a> {<a name="384" href="#384">384</a> <a name="385" href="#385">385</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> AtomicLong total;<a name="386" href="#386">386</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> AtomicLong calls;<a name="387" href="#387">387</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> AtomicLong minimum;<a name="388" href="#388">388</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> AtomicLong maximum;<a name="389" href="#389">389</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">final</strong> Object lock = <strong class="jxr_keyword">new</strong> Object();<a name="390" href="#390">390</a> <a name="391" href="#391">391</a> <em class="jxr_javadoccomment">/**</em><a name="392" href="#392">392</a> <em class="jxr_javadoccomment"> * Creates a new instance of TimerWorker.</em><a name="393" href="#393">393</a> <em class="jxr_javadoccomment"> *</em><a name="394" href="#394">394</a> <em class="jxr_javadoccomment"> */</em><a name="395" href="#395">395</a> <strong class="jxr_keyword">public</strong> <a href="../../../../../org/apache/mina/filter/statistic/ProfilerTimerFilter.html">TimerWorker</a>() {<a name="396" href="#396">396</a> total = <strong class="jxr_keyword">new</strong> AtomicLong();<a name="397" href="#397">397</a> calls = <strong class="jxr_keyword">new</strong> AtomicLong();<a name="398" href="#398">398</a> minimum = <strong class="jxr_keyword">new</strong> AtomicLong();<a name="399" href="#399">399</a> maximum = <strong class="jxr_keyword">new</strong> AtomicLong();<a name="400" href="#400">400</a> }<a name="401" href="#401">401</a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -