示例#1
0
文件: Debug.php 项目: ksst/kf
 /**
  * The method
  * - lists all currently included and required files
  * - counts all includes files
  * - calculates the total size (combined filesize) of all inclusions.
  */
 public static function getIncludedFiles($returnArray = false)
 {
     // init vars
     $includedFiles = $files = $result = [];
     $totalSize = 0;
     // fetch all included files
     $files = get_included_files();
     // loop over all included files and sum up filesize
     foreach ($files as $file) {
         // if system under test, skip virtual file system files,
         // as they might be already deleted by tearDown() methods.
         if (defined('UNIT_TEST_RUN') or UNIT_TEST_RUN) {
             if (stripos($file, 'vfs:/') !== false) {
                 continue;
             }
         }
         $size = filesize($file);
         $includedFiles[] = ['name' => $file, 'size' => $size];
         $totalSize += $size;
     }
     $result = ['count' => count($files), 'size' => \Koch\Functions\Functions::getSize($totalSize), 'files' => $includedFiles];
     return $returnArray === true ? $result : self::printR($result);
 }
示例#2
0
文件: Apc.php 项目: ksst/kf
 /**
  * Get stats and usage Informations for display from APC
  * 1. Shared Memory Allocation
  * 2. Cache Infos / Meta-Data.
  */
 public function stats()
 {
     $info = [];
     // Retrieve APC Version
     $info['version'] = phpversion('apc');
     $info['phpversion'] = phpversion();
     /*
      * ========================================================
      *   Retrieves APC's Shared Memory Allocation information
      * ========================================================
      */
     $info['sma_info'] = [];
     if (true === function_exists('apc_sma_info')) {
         $info['sma_info'] = apc_sma_info(true);
         // Calculate "APC Memory Size" (Number of Segments * Size of Segment)
         $memsize = $info['sma_info']['num_seg'] * $info['sma_info']['seg_size'];
         $info['sma_info']['mem_size'] = $memsize;
         // Calculate "APC Memory Usage" ( mem_size - avail_mem )
         $memusage = $info['sma_info']['mem_size'] - $info['sma_info']['avail_mem'];
         $info['sma_info']['mem_used'] = $memusage;
         // Calculate "APC Free Memory Percentage" ( mem_size*100/mem_used )
         $memsize_total = $info['sma_info']['avail_mem'] * 100;
         $avail_mem_percent = sprintf('(%.1f%%)', $memsize_total / $info['sma_info']['mem_size']);
         $info['sma_info']['mem_avail_percentage'] = $avail_mem_percent;
     }
     if (true === function_exists('apc_cache_info')) {
         // Retrieves cached information and meta-data from APC's data store
         $info['cache_info'] = apc_cache_info();
         #\Koch\Debug\Debug::printR(apc_cache_info());
         $info['cache_info']['cached_files'] = count($info['cache_info']['cache_list']);
         $info['cache_info']['deleted_files'] = count($info['cache_info']['deleted_list']);
         /*
          * ========================================================
          *   System Cache Informations
          * ========================================================
          */
         $info['system_cache_info'] = apc_cache_info('system', false);
         // set "false" for details
         // Calculate "APC Hit Rate Percentage"
         $hits = $info['system_cache_info']['num_hits'] + $info['system_cache_info']['num_misses'];
         // div by zero fix
         if ($hits === 0) {
             $hits = 1;
         }
         $hit_rate_percentage = $info['system_cache_info']['num_hits'] * 100 / $hits;
         $info['system_cache_info']['hit_rate_percentage'] = sprintf('(%.1f%%)', $hit_rate_percentage);
         // Calculate "APC Miss Rate Percentage"
         $miss_percentage = $info['system_cache_info']['num_misses'] * 100 / $hits;
         $info['system_cache_info']['miss_rate_percentage'] = sprintf('(%.1f%%)', $miss_percentage);
         $info['system_cache_info']['files_cached'] = count($info['system_cache_info']['cache_list']);
         $info['system_cache_info']['files_deleted'] = count($info['system_cache_info']['deleted_list']);
         // Request Rate (hits, misses) / cache requests/second
         $start_time = time() - $info['system_cache_info']['start_time'];
         // div by zero fix
         if ($start_time === 0) {
             $start_time = 1;
         }
         $rate = ($info['system_cache_info']['num_hits'] + $info['system_cache_info']['num_misses']) / $start_time;
         $info['system_cache_info']['req_rate'] = sprintf('%.2f', $rate);
         $hit_rate = $info['system_cache_info']['num_hits'] / $start_time;
         $info['system_cache_info']['hit_rate'] = sprintf('%.2f', $hit_rate);
         $miss_rate = $info['system_cache_info']['num_misses'] / $start_time;
         $info['system_cache_info']['miss_rate'] = sprintf('%.2f', $miss_rate);
         $insert_rate = $info['system_cache_info']['num_inserts'] / $start_time;
         $info['system_cache_info']['insert_rate'] = sprintf('%.2f', $insert_rate);
         // size
         if (isset($info['system_cache_info']['mem_size']) and $info['system_cache_info']['mem_size'] > 0) {
             $info['system_cache_info']['size_files'] = Functions::getSize($info['system_cache_info']['mem_size']);
         } else {
             $info['system_cache_info']['size_files'] = 0;
         }
     }
     $info['settings'] = ini_get_all('apc');
     /*
      * ini_get_all array mod: for each accessvalue
      * add the name of the PHP ACCESS CONSTANTS as 'accessname'
      * @todo: cleanup?
      */
     foreach ($info['settings'] as $key => $value) {
         foreach ($value as $key2 => $value2) {
             if ($key2 === 'access') {
                 $name = '';
                 // accessvalue => constantname
                 if ($value2 === '1') {
                     $name = 'PHP_INI_USER';
                 }
                 if ($value2 === '2') {
                     $name = 'PHP_INI_PERDIR';
                 }
                 if ($value2 === '4') {
                     $name = 'PHP_INI_SYSTEM';
                 }
                 if ($value2 === '7') {
                     $name = 'PHP_INI_ALL';
                 }
                 // add accessname to the original array
                 $info['settings'][$key]['accessname'] = $name;
                 unset($name);
             }
         }
     }
     #$info['sma_info']['size_vars']  = Functions::getsize($cache_user['mem_size']);
     return $info;
 }