PageRenderTime 3211ms CodeModel.GetById 29ms RepoModel.GetById 19ms app.codeStats 0ms

/extensions/APC/APCHostMode.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 202 lines | 160 code | 39 blank | 3 comment | 18 complexity | 835f698c8576ed1764b2bd23af6a6d24 MD5 | raw file
  1. <?php
  2. class APCHostMode {
  3. public static function doGeneralInfoTable( $c, $mem ) {
  4. global $wgLang;
  5. $r = 1;
  6. return
  7. APCUtils::tableHeader( wfMsg( 'viewapc-info-general' ) ) .
  8. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-apc-version' ), phpversion( 'apc' ) ) .
  9. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-php-version' ), phpversion() ) .
  10. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-shared-memory' ),
  11. wfMsgExt( 'viewapc-shared-memory-details', 'parsemag',
  12. $wgLang->formatNum( $mem['num_seg'] ),
  13. $wgLang->formatSize( $mem['seg_size'] ),
  14. $c['memory_type'], $c['locking_type'] ) ) .
  15. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-start-time' ),
  16. $wgLang->timeanddate( $c['start_time'] ) ) .
  17. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-uptime' ),
  18. $wgLang->formatTimePeriod( time() - $c['start_time'] ) ) .
  19. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-upload-support' ), $c['file_upload_progress'] ) .
  20. APCUtils::tableFooter();
  21. }
  22. public static function doCacheTable( $c, $user = false ) {
  23. global $wgLang;
  24. // Calculate rates
  25. $numHits = $wgLang->formatNum( $c['num_hits'] );
  26. $numMiss = $wgLang->formatNum( $c['num_misses'] );
  27. $numReqs = $c['num_hits'] + $c['num_misses'];
  28. $cPeriod = time() - $c['start_time'];
  29. if ( !$cPeriod ) $cPeriod = 1;
  30. $rateReqs = APCUtils::formatReqPerS( $numReqs / $cPeriod );
  31. $rateHits = APCUtils::formatReqPerS( $c['num_hits'] / $cPeriod );
  32. $rateMiss = APCUtils::formatReqPerS( $c['num_misses'] / $cPeriod );
  33. $rateInsert = APCUtils::formatReqPerS( $c['num_inserts'] / $cPeriod );
  34. $cachedFiles = wfMsgExt( 'viewapc-cached-files-d', 'parsemag',
  35. $wgLang->formatNum( $c['num_entries'] ),
  36. $wgLang->formatSize( $c['mem_size'] ) );
  37. $cacheFullCount = $wgLang->formatNum( $c['expunges'] );
  38. $contentType = !$user ? wfMsg( 'viewapc-filecache-info' ) : wfMsg( 'viewapc-usercache-info' );
  39. return
  40. APCUtils::tableHeader( $contentType ) .
  41. APCUtils::tableRow( $r = 0, wfMsgHtml( 'viewapc-cached-files' ), $cachedFiles ) .
  42. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-hits' ), $numHits ) .
  43. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-misses' ), $numMiss ) .
  44. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-requests' ), $rateReqs ) .
  45. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-hitrate' ), $rateHits ) .
  46. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-missrate' ), $rateMiss ) .
  47. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-insertrate' ), $rateInsert ) .
  48. APCUtils::tableRow( $r = 1 - $r, wfMsgHtml( 'viewapc-cachefull' ), $cacheFullCount ) .
  49. APCUtils::tableFooter();
  50. }
  51. public static function doRuntimeInfoTable( $mem ) {
  52. $s = APCUtils::tableHeader( wfMsg( 'viewapc-info-runtime' ) );
  53. $r = 1;
  54. foreach ( ini_get_all( 'apc' ) as $k => $v ) {
  55. $s .= APCUtils::tableRow( $r = 1 - $r,
  56. htmlspecialchars( $k ),
  57. str_replace( ',', ',<br />', htmlspecialchars( $v['local_value'] ) ) );
  58. }
  59. $s .= APCUtils::tableFooter();
  60. return $s;
  61. }
  62. public static function doMemoryInfoTable( $c, $mem, $title ) {
  63. global $wgLang;
  64. $s = APCUtils::tableHeader( wfMsg( 'viewapc-info-memory' ), 'mw-apc-img-table' );
  65. if ( $mem['num_seg'] > 1 || $mem['num_seg'] == 1 && count( $mem['block_lists'][0] ) > 1 ) {
  66. $memHeader = wfMsgExt( 'viewapc-memory-usage-detailed', 'parseinline' );
  67. } else {
  68. $memHeader = wfMsgExt( 'viewapc-memory-usage', 'parseinline' );
  69. }
  70. $hitHeader = wfMsgExt( 'viewapc-cache-efficiency', 'parseinline' );
  71. $s .= APCUtils::tableRow( null, $memHeader, $hitHeader );
  72. if ( APCImages::graphics_avail() ) {
  73. $attribs = array(
  74. 'alt' => '',
  75. 'width' => APCImages::GRAPH_SIZE + 10,
  76. 'height' => APCImages::GRAPH_SIZE + 10,
  77. );
  78. $param1 = wfArrayToCGI( array( 'image' => APCImages::IMG_MEM_USAGE ) );
  79. $param2 = wfArrayToCGI( array( 'image' => APCImages::IMG_HITS ) );
  80. $attribs1 = array( 'src' => $title->getLocalURL( $param1 ) ) + $attribs;
  81. $attribs2 = array( 'src' => $title->getLocalURL( $param2 ) ) + $attribs;
  82. $s .= APCUtils::tableRow( null, Xml::element( 'img', $attribs1 ), Xml::element( 'img', $attribs2 ) );
  83. }
  84. $size = $mem['num_seg'] * $mem['seg_size'];
  85. $free = $mem['avail_mem'];
  86. $used = $size - $free;
  87. $freeMem = wfMsgExt( 'viewapc-memory-free', 'parseinline',
  88. $wgLang->formatSize( $free ),
  89. $wgLang->formatNum( sprintf( '%.1f%%', $free * 100 / $size ) ) );
  90. $usedMem = wfMsgExt( 'viewapc-memory-used', 'parseinline',
  91. $wgLang->formatSize( $used ),
  92. $wgLang->formatNum( sprintf( '%.1f%%', $used * 100 / $size ) ) );
  93. $hits = $c['num_hits'];
  94. $miss = $c['num_misses'];
  95. $reqs = $hits + $miss;
  96. $greenbox = Xml::element( 'span', array( 'class' => 'green box' ), ' ' );
  97. $redbox = Xml::element( 'span', array( 'class' => 'red box' ), ' ' );
  98. $memHits = wfMsgExt( 'viewapc-memory-hits', 'parseinline',
  99. $wgLang->formatNum( $hits ),
  100. $wgLang->formatNum( @sprintf( '%.1f%%', $hits * 100 / $reqs ) ) );
  101. $memMiss = wfMsgExt( 'viewapc-memory-miss', 'parseinline',
  102. $wgLang->formatNum( $miss ),
  103. $wgLang->formatNum( @sprintf( '%.1f%%', $miss * 100 / $reqs ) ) );
  104. $s .= APCUtils::tableRow( null, $greenbox . $freeMem, $greenbox . $memHits );
  105. $s .= APCUtils::tableRow( null, $redbox . $usedMem, $redbox . $memMiss );
  106. $s .= APCUtils::tableFooter();
  107. return $s;
  108. }
  109. public static function doFragmentationTable( $mem, $title ) {
  110. global $wgLang;
  111. $s = APCUtils::tableHeader( wfMsg( 'viewapc-memoryfragmentation' ), 'mw-apc-img-table' );
  112. $s .= Xml::openElement( 'tr' ) . Xml::openElement( 'td' );
  113. // Fragementation: (freeseg - 1) / total_seg
  114. $nseg = $freeseg = $fragsize = $freetotal = 0;
  115. for ( $i = 0; $i < $mem['num_seg']; $i++ ) {
  116. $ptr = 0;
  117. foreach ( $mem['block_lists'][$i] as $block ) {
  118. if ( $block['offset'] != $ptr ) {
  119. ++$nseg;
  120. }
  121. $ptr = $block['offset'] + $block['size'];
  122. /* Only consider blocks <5M for the fragmentation % */
  123. if ( $block['size'] < ( 5 * 1024 * 1024 ) ) $fragsize += $block['size'];
  124. $freetotal += $block['size'];
  125. }
  126. $freeseg += count( $mem['block_lists'][$i] );
  127. }
  128. if ( APCImages::graphics_avail() ) {
  129. $attribs = array(
  130. 'alt' => '',
  131. 'width' => 2 * APCImages::GRAPH_SIZE + 150,
  132. 'height' => APCImages::GRAPH_SIZE + 10,
  133. 'src' => $title->getLocalURL( 'image=' . APCImages::IMG_FRAGMENTATION )
  134. );
  135. $s .= Xml::element( 'img', $attribs );
  136. }
  137. if ( $freeseg > 1 ) {
  138. $fragPercent = sprintf( '%.2f%%', ( $fragsize / $freetotal ) * 100 );
  139. $s .= wfMsgExt( 'viewapc-fragmentation-info', 'parse',
  140. $wgLang->formatNum( $fragPercent, true ),
  141. $wgLang->formatSize( $fragsize ),
  142. $wgLang->formatSize( $freetotal ),
  143. $wgLang->formatNum( $freeseg )
  144. );
  145. } else {
  146. $s .= wfMsgExt( 'viewapc-fragmentation-none', 'parse' );
  147. }
  148. $s .= Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' );
  149. if ( isset( $mem['adist'] ) ) {
  150. foreach ( $mem['adist'] as $i => $v ) {
  151. $cur = pow( 2, $i ); $nxt = pow( 2, $i + 1 ) - 1;
  152. if ( $i == 0 ) $range = "1";
  153. else $range = "$cur - $nxt";
  154. $s .= Xml::tags( 'tr', null,
  155. Xml::tags( 'th', array( 'align' => 'right' ), $range ) .
  156. Xml::tags( 'td', array( 'align' => 'right' ), $v )
  157. );
  158. }
  159. }
  160. $s .= APCUtils::tableFooter();
  161. return $s;
  162. }
  163. }