📄 statisticstracker.html
字号:
<a name="288" href="#288">288</a> <strong>long</strong> sampleProcessedBytes =<a name="289" href="#289">289</a> currentProcessedBytes - lastProcessedBytesCount;<a name="290" href="#290">290</a> <a name="291" href="#291">291</a> currentKBPerSec =<a name="292" href="#292">292</a> (<strong>int</strong>)(((sampleProcessedBytes/1024)/(sampleTime/1000)) + .5);<a name="293" href="#293">293</a> <a name="294" href="#294">294</a> lastProcessedBytesCount = currentProcessedBytes;<a name="295" href="#295">295</a> }<a name="296" href="#296">296</a> }<a name="297" href="#297">297</a> <a name="298" href="#298">298</a> <strong>if</strong> (<strong>this</strong>.controller != <strong>null</strong>) {<a name="299" href="#299">299</a> <strong>this</strong>.controller.logProgressStatistics(getProgressStatisticsLine());<a name="300" href="#300">300</a> }<a name="301" href="#301">301</a> lastLogPointTime = System.currentTimeMillis();<a name="302" href="#302">302</a> <strong>super</strong>.progressStatisticsEvent(e);<a name="303" href="#303">303</a> }<a name="304" href="#304">304</a> <a name="305" href="#305">305</a> <em>/**<em>*</em></em><a name="306" href="#306">306</a> <em> * Return one line of current progress-statistics</em><a name="307" href="#307">307</a> <em> * </em><a name="308" href="#308">308</a> <em> * @param now</em><a name="309" href="#309">309</a> <em> * @return String of stats</em><a name="310" href="#310">310</a> <em> */</em><a name="311" href="#311">311</a> <strong>public</strong> String getProgressStatisticsLine(Date now) {<a name="312" href="#312">312</a> <strong>return</strong> <strong>new</strong> <a href="../../../../org/archive/util/PaddingStringBuffer.html">PaddingStringBuffer</a>()<a name="313" href="#313">313</a> .append(ArchiveUtils.TIMESTAMP14ISO8601Z.format(now))<a name="314" href="#314">314</a> .raAppend(32, discoveredUriCount)<a name="315" href="#315">315</a> .raAppend(44, queuedUriCount)<a name="316" href="#316">316</a> .raAppend(57, downloadedUriCount)<a name="317" href="#317">317</a> .raAppend(74, ArchiveUtils.<a name="318" href="#318">318</a> doubleToString(currentDocsPerSecond, 2) +<a name="319" href="#319">319</a> <span class="string">"("</span> + ArchiveUtils.doubleToString(docsPerSecond, 2) + <span class="string">")"</span>)<a name="320" href="#320">320</a> .raAppend(85, currentKBPerSec + <span class="string">"("</span> + totalKBPerSec + <span class="string">")"</span>)<a name="321" href="#321">321</a> .raAppend(99, downloadFailures)<a name="322" href="#322">322</a> .raAppend(113, busyThreads)<a name="323" href="#323">323</a> .raAppend(126, (Runtime.getRuntime().totalMemory() -<a name="324" href="#324">324</a> Runtime.getRuntime().freeMemory()) / 1024)<a name="325" href="#325">325</a> .raAppend(140, Runtime.getRuntime().totalMemory() / 1024)<a name="326" href="#326">326</a> .raAppend(153, ArchiveUtils.doubleToString(congestionRatio, 2))<a name="327" href="#327">327</a> .raAppend(165, deepestUri)<a name="328" href="#328">328</a> .raAppend(177, averageDepth)<a name="329" href="#329">329</a> .toString();<a name="330" href="#330">330</a> }<a name="331" href="#331">331</a> <a name="332" href="#332">332</a> <strong>public</strong> Map getProgressStatistics() {<a name="333" href="#333">333</a> Map stats = <strong>new</strong> HashMap();<a name="334" href="#334">334</a> stats.put(<span class="string">"discoveredUriCount"</span>, <strong>new</strong> Long(discoveredUriCount));<a name="335" href="#335">335</a> stats.put(<span class="string">"queuedUriCount"</span>, <strong>new</strong> Long(queuedUriCount));<a name="336" href="#336">336</a> stats.put(<span class="string">"downloadedUriCount"</span>, <strong>new</strong> Long(downloadedUriCount));<a name="337" href="#337">337</a> stats.put(<span class="string">"currentDocsPerSecond"</span>, <strong>new</strong> Double(currentDocsPerSecond));<a name="338" href="#338">338</a> stats.put(<span class="string">"docsPerSecond"</span>, <strong>new</strong> Double(docsPerSecond));<a name="339" href="#339">339</a> stats.put(<span class="string">"totalKBPerSec"</span>, <strong>new</strong> Long(totalKBPerSec));<a name="340" href="#340">340</a> stats.put(<span class="string">"totalProcessedBytes"</span>, <strong>new</strong> Long(totalProcessedBytes));<a name="341" href="#341">341</a> stats.put(<span class="string">"currentKBPerSec"</span>, <strong>new</strong> Long(currentKBPerSec));<a name="342" href="#342">342</a> stats.put(<span class="string">"downloadFailures"</span>, <strong>new</strong> Long(downloadFailures));<a name="343" href="#343">343</a> stats.put(<span class="string">"busyThreads"</span>, <strong>new</strong> Integer(busyThreads));<a name="344" href="#344">344</a> stats.put(<span class="string">"congestionRatio"</span>, <strong>new</strong> Double(congestionRatio));<a name="345" href="#345">345</a> stats.put(<span class="string">"deepestUri"</span>, <strong>new</strong> Long(deepestUri));<a name="346" href="#346">346</a> stats.put(<span class="string">"averageDepth"</span>, <strong>new</strong> Long(averageDepth));<a name="347" href="#347">347</a> stats.put(<span class="string">"totalMemory"</span>, <strong>new</strong> Long(Runtime.getRuntime().totalMemory()));<a name="348" href="#348">348</a> stats.put(<span class="string">"freeMemory"</span>, <strong>new</strong> Long(Runtime.getRuntime().freeMemory()));<a name="349" href="#349">349</a> <strong>return</strong> stats;<a name="350" href="#350">350</a> }<a name="351" href="#351">351</a> <a name="352" href="#352">352</a> <em>/**<em>*</em></em><a name="353" href="#353">353</a> <em> * Return one line of current progress-statistics</em><a name="354" href="#354">354</a> <em> * </em><a name="355" href="#355">355</a> <em> * @return String of stats</em><a name="356" href="#356">356</a> <em> */</em><a name="357" href="#357">357</a> <strong>public</strong> String getProgressStatisticsLine() {<a name="358" href="#358">358</a> <strong>return</strong> getProgressStatisticsLine(<strong>new</strong> Date());<a name="359" href="#359">359</a> }<a name="360" href="#360">360</a> <a name="361" href="#361">361</a> <strong>public</strong> <strong>double</strong> processedDocsPerSec(){<a name="362" href="#362">362</a> <strong>return</strong> docsPerSecond;<a name="363" href="#363">363</a> }<a name="364" href="#364">364</a> <a name="365" href="#365">365</a> <strong>public</strong> <strong>double</strong> currentProcessedDocsPerSec(){<a name="366" href="#366">366</a> <strong>return</strong> currentDocsPerSecond;<a name="367" href="#367">367</a> }<a name="368" href="#368">368</a> <a name="369" href="#369">369</a> <strong>public</strong> <strong>long</strong> processedKBPerSec(){<a name="370" href="#370">370</a> <strong>return</strong> totalKBPerSec;<a name="371" href="#371">371</a> }<a name="372" href="#372">372</a> <a name="373" href="#373">373</a> <strong>public</strong> <strong>int</strong> currentProcessedKBPerSec(){<a name="374" href="#374">374</a> <strong>return</strong> currentKBPerSec;<a name="375" href="#375">375</a> }<a name="376" href="#376">376</a> <a name="377" href="#377">377</a> <em>/**<em>* Returns a HashMap that contains information about distributions of</em></em><a name="378" href="#378">378</a> <em> * encountered mime types. Key/value pairs represent</em><a name="379" href="#379">379</a> <em> * mime type -> count.</em><a name="380" href="#380">380</a> <em> * <p></em><a name="381" href="#381">381</a> <em> * <b>Note:</b> All the values are wrapped with a {@link LongWrapper LongWrapper}</em><a name="382" href="#382">382</a> <em> * @return mimeTypeDistribution</em><a name="383" href="#383">383</a> <em> */</em><a name="384" href="#384">384</a> <strong>public</strong> Hashtable getFileDistribution() {<a name="385" href="#385">385</a> <strong>return</strong> mimeTypeDistribution;<a name="386" href="#386">386</a> }<a name="387" href="#387">387</a> <a name="388" href="#388">388</a> <a name="389" href="#389">389</a> <em>/**<em>*</em></em><a name="390" href="#390">390</a> <em> * Increment a counter for a key in a given HashMap. Used for various</em><a name="391" href="#391">391</a> <em> * aggregate data.</em><a name="392" href="#392">392</a> <em> * </em><a name="393" href="#393">393</a> <em> * As this is used to change Maps which depend on StatisticsTracker</em><a name="394" href="#394">394</a> <em> * for their synchronization, this method should only be invoked</em><a name="395" href="#395">395</a> <em> * from a a block synchronized on 'this'. </em><a name="396" href="#396">396</a> <em> *</em><a name="397" href="#397">397</a> <em> * @param map The HashMap</em><a name="398" href="#398">398</a> <em> * @param key The key for the counter to be incremented, if it does not</em><a name="399" href="#399">399</a> <em> * exist it will be added (set to 1). If null it will</em><a name="400" href="#400">400</a> <em> * increment the counter "unknown".</em><a name="401" href="#401">401</a> <em> */</em><a name="402" href="#402">402</a> <strong>protected</strong> <strong>static</strong> <strong>void</strong> incrementMapCount(Map map, String key) {<a name="403" href="#403">403</a> incrementMapCount(map,key,1);<a name="404" href="#404">404</a> }<a name="405" href="#405">405</a> <a name="406" href="#406">406</a> <em>/**<em>*</em></em><a name="407" href="#407">407</a> <em> * Increment a counter for a key in a given HashMap by an arbitrary amount.</em><a name="408" href="#408">408</a> <em> * Used for various aggregate data. The increment amount can be negative.</em><a name="409" href="#409">409</a> <em> *</em><a name="410" href="#410">410</a> <em> * As this is used to change Maps which depend on StatisticsTracker</em><a name="411" href="#411">411</a> <em> * for their synchronization, this method should only be invoked</em><a name="412" href="#412">412</a> <em> * from a a block synchronized on 'this'. </em><a name="413" href="#413">413</a> <em> *</em><a name="414" href="#414">414</a> <em> * @param map</em><a name="415" href="#415">415</a> <em> * The HashMap</em><a name="416" href="#416">416</a> <em> * @param key</em><a name="417" href="#417">417</a> <em> * The key for the counter to be incremented, if it does not exist</em><a name="418" href="#418">418</a> <em> * it will be added (set to equal to <code>increment</code>).</em><a name="419" href="#419">419</a> <em> * If null it will increment the counter "unknown".</em><a name="420" href="#420">420</a> <em> * @param increment</em><a name="421" href="#421">421</a> <em> * The amount to increment counter related to the <code>key</code>.</em><a name="422" href="#422">422</a> <em> */</em><a name="423" href="#423">423</a> <strong>protected</strong> <strong>static</strong> <strong>void</strong> incrementMapCount(Map map, String key,<a name="424" href="#424">424</a> <strong>long</strong> increment) {<a name="425" href="#425">425</a> <strong>if</strong> (key == <strong>null</strong>) {<a name="426" href="#426">426</a> key = <span class="string">"unknown"</span>;<a name="427" href="#427">427</a> }<a name="428" href="#428">428</a> <a href="../../../../org/archive/util/LongWrapper.html">LongWrapper</a> lw = (LongWrapper)map.get(key);<a name="429" href="#429">429</a> <strong>if</strong>(lw == <strong>null</strong>) {<a name="430" href="#430">430</a> map.put(key, <strong>new</strong> <a href="../../../../org/archive/util/LongWrapper.html">LongWrapper</a>(increment));<a name="431" href="#431">431</a> } <strong>else</strong> {<a name="432" href="#432">432</a> lw.longValue += increment;<a name="433" href="#433">433</a> }<a name="434" href="#434">434</a> }<a name="435" href="#435">435</a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -