/** * score * * @param integer $unit unit of memory usage * @param integer $precision precision of memory usage * * @return integer now score */ public static function score($handle, $unit = Charcoal_EnumMemoryUnit::UNIT_B, $precision = Charcoal_MemoryUtil::DEFAULT_PRECISION) { $start = isset(self::$benchmarks[$handle]) ? self::$benchmarks[$handle] : NULL; if ($start === NULL) { _throw(new Charcoal_BenchmarkException('not started yet!')); } list($start_usage_1, $start_usage_2) = $start; $score_1 = memory_get_usage(true) - $start_usage_1; $score_2 = memory_get_usage(false) - $start_usage_2; $score_1 = Charcoal_MemoryUtil::convertSize($score_1, $unit, $precision); $score_2 = Charcoal_MemoryUtil::convertSize($score_2, $unit, $precision); return array($score_1, $score_2); }
/** * Get element value as file size * * @param string $key Key string to get * @param string $default_value default value * * @return integer */ public function getSize($key, $default_value = NULL) { // Charcoal_ParamTrait::validateString( 1, $key ); // Charcoal_ParamTrait::validateString( 2, $default_value, TRUE ); $key = us($key); $value = parent::getString($key, $default_value); return Charcoal_MemoryUtil::getByteSizeFromString($value); }
/** * execute framework main code * * @param boolean $debug * @param Charcoal_Sandbox $sandbox */ public static function run($debug = NULL, $sandbox = NULL) { $th_run = Charcoal_Benchmark::start(); $mh_run = Charcoal_MemoryBenchmark::start(); // Charcoal_ParamTrait::validateBoolean( 1, $debug, TRUE ); // Charcoal_ParamTrait::validateSandbox( 2, $sandbox, TRUE ); if ($sandbox === NULL) { $sandbox = new Charcoal_Sandbox(CHARCOAL_PROFILE, $debug); } try { try { //ob_start(); self::_run($sandbox); //ob_end_flush(); } catch (Charcoal_ProcedureNotFoundException $ex) { _catch($ex); switch (CHARCOAL_RUNMODE) { // ランモードがhttpの時は404エラー case 'http': throw new Charcoal_HttpStatusException(404, $ex); break; // それ以外の場合はリスロー // それ以外の場合はリスロー default: _throw($ex); break; } } catch (Exception $ex) { _catch($ex); switch (CHARCOAL_RUNMODE) { // ランモードがhttpの時は500エラー case 'http': throw new Charcoal_HttpStatusException(500, $ex); break; // それ以外の場合はリスロー // それ以外の場合はリスロー default: _throw($ex); break; } } } catch (Charcoal_ProfileLoadingException $e) { echo 'profile loading failed:' . $e->getMessage(); exit; } catch (Exception $e) { _catch($e); // restore error handlers for avoiding infinite loop restore_error_handler(); restore_exception_handler(); self::handleException($e); // display debugtrace if ($debug || $sandbox->isDebug()) { self::$debugtrace_renderers->render($e); } self::$loggers->flush(); } catch (Throwable $e) { _catch($e); // restore error handlers for avoiding infinite loop restore_error_handler(); restore_exception_handler(); self::handleException($e); // display debugtrace if ($debug || $sandbox->isDebug()) { self::$debugtrace_renderers->render($e); } self::$loggers->flush(); } // finally process $timer_score = Charcoal_Benchmark::stop($th_run); log_debug('system, debug', sprintf("total framework process time: [%0.4f] msec", $timer_score)); // memory usage list($usage_1, $usage_2) = Charcoal_MemoryBenchmark::stop($mh_run); log_debug('system, debug', sprintf("used memory: [%d] bytes / [%d] bytes", $usage_1, $usage_2)); // memory peak usage $peak_usage_1 = Charcoal_MemoryUtil::convertSize(memory_get_peak_usage(true), Charcoal_EnumMemoryUnit::UNIT_B); $peak_usage_2 = Charcoal_MemoryUtil::convertSize(memory_get_peak_usage(false), Charcoal_EnumMemoryUnit::UNIT_B); log_debug('system, debug', sprintf("peak memory: [%d] bytes / [%d] bytes", $peak_usage_1, $peak_usage_2)); //Charcoal_Object::dump(); self::terminate(); }