Beispiel #1
0
 /**
  * Analyzes the processor runtime and shutdowns when no activity is
  * detected.
  *
  * @param  object  $sig_awake  SIG_Awake
  *
  * @return  void
  */
 public function anaylze_runtime(SIG_Awake $sig_awake)
 {
     if (!isset($sig_awake->analysis)) {
         $sig_awake->analysis = microseconds();
         $sig_awake->count = 0;
     } else {
         if (XPSPL_DEBUG) {
             logger(XPSPL_LOG)->debug('Analyzing runtime');
         }
         if (0 === $sig_awake - microseconds() >> 10) {
             if ($sig_awake->count > 5) {
                 $this->shutdown();
             }
             $sig_awake->count = $sig_awake->count + 1;
         } else {
             $sig_awake->count = 0;
         }
         $sig_awake->analysis = microseconds();
     }
 }
Beispiel #2
0
 public function handle_action($action)
 {
     $start_timer = microseconds();
     $this->load_session();
     $this->handle_flash_messages();
     $methods = get_class_methods($this);
     # call before filter methods before calling action method
     $this->run_filter_methods($this->before_filter, $action, $methods);
     # Search for action Methods
     if (array_key_exists($action, array_flip($methods))) {
         $this->{$action}();
     }
     # call after filter methods after calling action method
     $this->run_filter_methods($this->after_filter, $action, $methods);
     $this->render();
     Logger::info("Controller Action: " . (microseconds() - $start_timer) . " ms");
 }
Beispiel #3
0
/**
 * Returns the current time since epox in milliseconds.
 *
 * @return  integer
 */
function milliseconds()
{
    return microseconds() * 1000;
}
Beispiel #4
0
 /**
  * Runs a method with the provided arguments for profiling.
  *
  * Runs a method with the provided arguments, and returns profilingDetails about how long it took.
  * Works with instance methods and static methods.
  *
  * @param mixed      $class           Name of the class to profile or an existing instance
  * @param string     $methodName      Name of the method to profile
  * @param array|null $methodArguments Arguments to pass to the function
  * @param int        $invocations     Number of times to call the method
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return $this Instance for chaining
  *
  * @throws Doozr_Exception
  */
 public function profile($class, $methodName, array $methodArguments = null, $invocations = 1)
 {
     if (true === is_object($class)) {
         $className = get_class($class);
     } else {
         $className = $class;
         if (false === class_exists($className)) {
             throw new Doozr_Exception(sprintf('%s does not exist.', $className));
         }
     }
     $method = new \ReflectionMethod($className, $methodName);
     $instance = null;
     if (true === $method->isStatic()) {
         // mark last profiling session as static
         $this->profileStatic = true;
     } elseif (false === $method->isStatic() && !$class instanceof $className) {
         $class = new \ReflectionClass($className);
         $instance = $class->newInstance();
     } else {
         $instance = $class;
     }
     $durations = [];
     for ($i = 0; $i < $invocations; ++$i) {
         $start = microseconds();
         if (is_null($methodArguments)) {
             $method->invoke($instance);
         } else {
             $method->invokeArgs($instance, $methodArguments);
         }
         $durations[] = microseconds() - $start;
     }
     $total = round(array_sum($durations), 8);
     return $this->profilingDetails(['class' => $className, 'method' => $methodName, 'arguments' => $methodArguments, 'duration' => ['microseconds' => ['total' => $total, 'average' => round($total / count($durations), 8), 'worst' => round(max($durations), 8)], 'seconds' => ['total' => $total / 1000, 'average' => round($total / 1000 / count($durations), 8), 'worst' => round(max($durations) / 1000, 8)]], 'invocations' => $invocations]);
 }
Beispiel #5
0
<?php

print microseconds();
xp_import('time');
$precision = 500;
$signal = new \time\SIG_Awake($precision, TIME_MICROSECONDS);
$precision_timing = [];
xp_signal($signal, xp_exhaust(5500, function ($signal) use($precision, &$precision_timing) {
    if (!isset($signal->time)) {
        $signal->time = microseconds();
        return true;
    }
    $timing = floatval((microseconds() - $signal->time) * 1000000) - $precision;
    if ($timing > 1000 || $timing < 0) {
        // Second change
        $signal->time = microseconds();
        return;
    }
    $precision_timing[] = [$timing, 0];
    $signal->time = microseconds();
}));
xp_on_shutdown(function () use(&$precision_timing) {
    array_shift($precision_timing);
    $results = ['usPrecision' => $precision_timing];
    ob_start();
    include dirname(realpath(__FILE__)) . '/chart.php';
    $data = ob_get_contents();
    ob_end_clean();
    file_put_contents('microsecond_precision.html', $data);
    echo "Performance chart in precision.html" . PHP_EOL;
});
Beispiel #6
0
 public function render_partial($partial_name, $options = array())
 {
     $start = microseconds();
     $params = $this->view_params();
     if (array_key_exists("locals", $options)) {
         if (is_array($options["locals"])) {
             $params = array_merge($params, $options["locals"]);
         }
     }
     # When partial_name has a slash assume they
     # know what template they are looking for.
     # Otherwise look for the partial name in the default location.
     if (strpos($partial_name, "/") > 0) {
         $segments = explode("/", $partial_name);
         $segments[count($segments) - 1] = "_" . end($segments);
         $partial = join("/", $segments);
     } else {
         $partial = $params["params"]["controller"] . "/" . "_{$partial_name}";
     }
     ob_start();
     Import::view($partial, $this->file_extension(), $params);
     $output = ob_get_contents();
     ob_end_clean();
     Logger::render("Rendering {$partial} (" . (microseconds() - $start) . " ms)\n");
     return $output;
 }