Exemplo n.º 1
0
function __profiler__($cmd = false)
{
    static $log, $last_time, $total;
    list($usec, $sec) = explode(" ", microtime());
    $now = (double) $usec + (double) $sec;
    if ($cmd) {
        if ($cmd == 'get') {
            unregister_tick_function('__profile__');
            foreach ($log as $function => $time) {
                if ($function != '__profile__') {
                    $by_function[$function] = round($time / $total * 100, 2);
                }
            }
            arsort($by_function);
            return $by_function;
        } else {
            if ($cmd == 'init') {
                $last_time = $now;
                return;
            }
        }
    }
    $delta = $now - $last_time;
    $last_time = $now;
    $trace = debug_backtrace();
    $caller = $trace[1]['function'];
    if (!isset($log[$caller])) {
        $log[$caller] = 0;
    }
    // Aral: Added to remove undefined index errors.
    @($log[$caller] += $delta);
    $total += $delta;
}
Exemplo n.º 2
0
 /**
  * Stop profiler
  */
 public function stop()
 {
     $this->_endTime = microtime(true);
     $this->tick();
     if (Sys::isFunc('unregister_tick_function')) {
         unregister_tick_function(array($this, 'tick'));
     }
 }
Exemplo n.º 3
0
 public function stop()
 {
     unregister_tick_function(array($this, "tick"));
     $this->timeUsed = microtime(true) - $this->timeUsed;
     if ($this->logFileHandler) {
         fclose($this->logFileHandler);
     }
 }
Exemplo n.º 4
0
 /**
  * Stop
  */
 public static function stop()
 {
     unregister_tick_function('alive_tick');
     if (self::$ob_start) {
         ob_start();
         echo self::$buffer;
     }
 }
Exemplo n.º 5
0
 /**
  * 
  * @param callable $function A function to be measured
  * @param array $args Parameters to be passed for measured function
  * @return array Result currently contains one value: used memory space
  */
 public function benchmarkMemory(callable $function, array $args = array())
 {
     declare (ticks=1);
     $this->memory = memory_get_usage();
     $this->max = 0;
     register_tick_function('call_user_func', array($this, 'memoryTick'));
     $this->measureFunction($function, $args, 1);
     unregister_tick_function('call_user_func');
     return array(self::MEMORY_VALUE => $this->max);
 }
Exemplo n.º 6
0
 public static function __appprofiler_ontick()
 {
     static $time, $ltrace, $tick;
     $tick = (int) $tick + 1;
     if ($tick == 10) {
         $tick = 0;
         $exec = round(microtime(true) - self::$tracestart, 2) . "sec";
         $info = round(memory_get_usage(true) / 1024 / 1024, 2) . "MiB";
         echo "7{$exec}/{$info}8";
     }
     if (!$time) {
         $time = microtime(true);
     }
     $trace = debug_backtrace(0, 2);
     if (count($trace) < 2) {
         $trace[1] = $trace[0];
     }
     if ($trace[1] == $ltrace[1]) {
         return;
     }
     array_walk_recursive($trace[1], function (&$v, $k) {
         if (is_object($v)) {
             $v = "[object:" . get_class($v) . "]";
         }
     });
     $ltrace = $trace;
     if (count($trace) == 0) {
         var_dump($trace);
     }
     $exe_time = (microtime(true) - $time) * 1000;
     if (memory_get_usage(true) > 10000000) {
         \debug("Memory usage > 10MB. Disabling profiling.");
         unregister_tick_function("Cherry\\Util\\AppProfiler::__appprofiler_ontick");
     }
     $stats = array("current_time" => microtime(true) - self::$tracestart, "memory" => memory_get_usage(false), "ns" => $exe_time);
     $stats = array_merge((array) $stats, (array) $trace[1]);
     if (self::$binlog) {
         self::$tracelog->write($stats);
     } else {
         fwrite(self::$tracelog, json_encode($stats) . "\n");
     }
     $time = microtime(true);
 }
Exemplo n.º 7
0
 private function checkForDeclareDirective()
 {
     // PHP7 appears to exhibit different behavior with ticks than
     // 5. Basically, >=7 requires the tick handler at the top of this
     // file for this to execute at all (making the detection
     // pointless), but it doesn't persist in the rest of the script.
     if (version_compare(\PHP_VERSION, '7.0.0', '>=')) {
         return;
     }
     register_tick_function([$this, 'didTick']);
     usleep(1);
     if (!$this->didTick) {
         // Try a bunch of no-ops in case the directive is set as > 1
         $i = 1000;
         while ($i--) {
         }
     }
     unregister_tick_function([$this, 'didTick']);
     if (!$this->didTick) {
         fwrite(STDERR, "It looks like `declare(ticks=1);` has not been " . "called, so signals to stop the daemon will fail. Ensure " . "that the root-level script calls this.\n");
         exit(1);
     }
 }
<?php

unregister_tick_function('profile');
Exemplo n.º 9
0
 /**
  * Stops counting
  *
  * @return void
  */
 public function stopCounting()
 {
     \unregister_tick_function(array($this, "countSplit"));
 }
Exemplo n.º 10
0
<?php

declare (ticks=1);
register_tick_function($closure = function () {
    echo "Tick!\n";
});
unregister_tick_function($closure);
echo "done";
Exemplo n.º 11
0
 /**
  * Stop profiling
  * @access public
  * @return void
  */
 public static function stop_profile()
 {
     unregister_tick_function(array(__CLASS__, 'do_profile'));
 }
Exemplo n.º 12
0
function bypass_suhosin($function, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $output_needed = True)
{
    //I found no other way to deal with arguments... poor me.
    if ($arg5 != null) {
        if (disabled_php("call_user_func") == False) {
            $return_value = call_user_func($function, $arg1, $arg2, $arg3, $arg4, $arg5);
        } else {
            if (disabled_php("call_user_func_array") == False) {
                $return_value = call_user_func_array($function, array($arg1, $arg2, $arg3, $arg4, $arg5));
            } else {
                if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                    $ref_function = new ReflectionFunction($function);
                    $handle = $ref_function->invoke($arg1, $arg2, $arg3, $arg4, $arg5);
                    if (is_string($handle)) {
                        $return_value = $handle;
                    } else {
                        $return_value = fread($handle, 4096);
                        pclose($handle);
                    }
                } else {
                    if ($output_needed == False) {
                        if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                            $it = new ArrayIterator(array(""));
                            iterator_apply($it, $function, array($arg1, $arg2, $arg3, $arg4, $arg5));
                        } else {
                            if (disabled_php("register_tick_function") == False) {
                                declare (ticks=1);
                                register_tick_function($function, $arg1, $arg2, $arg3, $arg4, $arg5);
                                unregister_tick_function($function);
                            } else {
                                if (disabled_php("array_map") == False) {
                                    array_map($function, array($arg1, $arg2, $arg3, $arg4, $arg5));
                                } else {
                                    if (disabled_php("array_walk") == False) {
                                        $x = array($arg1, $arg2, $arg3, $arg4, $arg5);
                                        array_walk($x, $function);
                                    } else {
                                        if (disabled_php("array_filter") == False) {
                                            array_filter(array($arg1, $arg2, $arg3, $arg4, $arg5), $function);
                                        } else {
                                            if (disabled_php("register_shutdown_function")) {
                                                register_shutdown_function($function, $arg1, $arg2, $arg3, $arg4, $arg5);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if ($arg4 != null) {
            if (disabled_php("call_user_func") == False) {
                $return_value = call_user_func($function, $arg1, $arg2, $arg3, $arg4);
            } else {
                if (disabled_php("call_user_func_array") == False) {
                    $return_value = call_user_func_array($function, array($arg1, $arg2, $arg3, $arg4));
                } else {
                    if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                        $ref_function = new ReflectionFunction($function);
                        $handle = $ref_function->invoke($arg1, $arg2, $arg3, $arg4);
                        if (is_string($handle)) {
                            $return_value = $handle;
                        } else {
                            $return_value = fread($handle, 4096);
                            pclose($handle);
                        }
                    } else {
                        if ($output_needed == False) {
                            if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                                $it = new ArrayIterator(array(""));
                                iterator_apply($it, $function, array($arg1, $arg2, $arg3, $arg4));
                            } else {
                                if (disabled_php("register_tick_function") == False) {
                                    declare (ticks=1);
                                    register_tick_function($function, $arg1, $arg2, $arg3, $arg4);
                                    unregister_tick_function($function);
                                } else {
                                    if (disabled_php("array_map") == False) {
                                        array_map($function, array($arg1, $arg2, $arg3, $arg4));
                                    } else {
                                        if (disabled_php("array_walk") == False) {
                                            $x = array($arg1, $arg2, $arg3, $arg4);
                                            array_walk($x, $function);
                                        } else {
                                            if (disabled_php("array_filter") == False) {
                                                array_filter(array($arg1, $arg2, $arg3, $arg4), $function);
                                            } else {
                                                if (disabled_php("register_shutdown_function")) {
                                                    register_shutdown_function($function, $arg1, $arg2, $arg3, $arg4);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            if ($arg3 != null) {
                if (disabled_php("call_user_func") == False) {
                    $return_value = call_user_func($function, $arg1, $arg2, $arg3);
                } else {
                    if (disabled_php("call_user_func_array") == False) {
                        $return_value = call_user_func_array($function, array($arg1, $arg2, $arg3));
                    } else {
                        if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                            $ref_function = new ReflectionFunction($function);
                            $handle = $ref_function->invoke($arg1, $arg2, $arg3);
                            if (is_string($handle)) {
                                $return_value = $handle;
                            } else {
                                $return_value = fread($handle, 4096);
                                pclose($handle);
                            }
                        } else {
                            if ($output_needed == False) {
                                if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                                    $it = new ArrayIterator(array(""));
                                    iterator_apply($it, $function, array($arg1, $arg2, $arg3));
                                } else {
                                    if (disabled_php("register_tick_function") == False) {
                                        declare (ticks=1);
                                        register_tick_function($function, $arg1, $arg2, $arg3);
                                        unregister_tick_function($function);
                                    } else {
                                        if (disabled_php("array_map") == False) {
                                            array_map($function, array($arg1, $arg2, $arg3));
                                        } else {
                                            if (disabled_php("array_walk") == False) {
                                                $x = array($arg1, $arg2, $arg3);
                                                array_walk($x, $function);
                                            } else {
                                                if (disabled_php("array_filter") == False) {
                                                    array_filter(array($arg1, $arg2, $arg3), $function);
                                                } else {
                                                    if (disabled_php("register_shutdown_function")) {
                                                        register_shutdown_function($function, $arg1, $arg2, $arg3);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($arg2 != null) {
                    if (disabled_php("call_user_func") == False) {
                        $return_value = call_user_func($function, $arg1, $arg2);
                    } else {
                        if (disabled_php("call_user_func_array") == False) {
                            $return_value = call_user_func_array($function, array($arg1, $arg2));
                        } else {
                            if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                                $ref_function = new ReflectionFunction($function);
                                $handle = $ref_function->invoke($arg1, $arg2);
                                if (is_string($handle)) {
                                    $return_value = $handle;
                                } else {
                                    $return_value = fread($handle, 4096);
                                    pclose($handle);
                                }
                            } else {
                                if ($output_needed == False) {
                                    if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                                        $it = new ArrayIterator(array(""));
                                        iterator_apply($it, $function, array($arg1, $arg2));
                                    } else {
                                        if (disabled_php("register_tick_function") == False) {
                                            declare (ticks=1);
                                            register_tick_function($function, $arg1, $arg2);
                                            unregister_tick_function($function);
                                        } else {
                                            if (disabled_php("array_map") == False) {
                                                array_map($function, array($arg1, $arg2));
                                            } else {
                                                if (disabled_php("array_walk") == False) {
                                                    $x = array($arg1, $arg2);
                                                    array_walk($x, $function);
                                                } else {
                                                    if (disabled_php("array_filter") == False) {
                                                        array_filter(array($arg1, $arg2), $function);
                                                    } else {
                                                        if (disabled_php("register_shutdown_function")) {
                                                            register_shutdown_function($function, $arg1, $arg2);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if ($arg1 != null) {
                        if (disabled_php("call_user_func") == False) {
                            $return_value = call_user_func($function, $arg1);
                        } else {
                            if (disabled_php("call_user_func_array") == False) {
                                $return_value = call_user_func_array($function, array($arg1));
                            } else {
                                if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                                    $ref_function = new ReflectionFunction($function);
                                    $handle = $ref_function->invoke($arg1);
                                    if (is_string($handle)) {
                                        $return_value = $handle;
                                    } else {
                                        $return_value = fread($handle, 4096);
                                        pclose($handle);
                                    }
                                } else {
                                    if ($output_needed == False) {
                                        if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                                            $it = new ArrayIterator(array(""));
                                            iterator_apply($it, $function, array($arg1));
                                        } else {
                                            if (disabled_php("register_tick_function") == False) {
                                                declare (ticks=1);
                                                register_tick_function($function, $arg1);
                                                unregister_tick_function($function);
                                            } else {
                                                if (disabled_php("array_map") == False) {
                                                    array_map($function, array($arg1));
                                                } else {
                                                    if (disabled_php("array_walk") == False) {
                                                        $x = array($arg1, $arg2, $arg3);
                                                        array_walk($x, $function);
                                                    } else {
                                                        if (disabled_php("array_filter") == False) {
                                                            array_filter(array($arg1), $function);
                                                        } else {
                                                            if (disabled_php("register_shutdown_function")) {
                                                                register_shutdown_function($function, $arg1);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        if (disabled_php("call_user_func") == False) {
                            $return_value = call_user_func($function);
                        } else {
                            if (disabled_php("call_user_func_array") == False) {
                                $return_value = call_user_func_array($function, array());
                            } else {
                                if (version_compare(PHP_VERSION, '5.0.0') >= 0 && disabled_php(null, "ReflectionFunction") == False) {
                                    $ref_function = new ReflectionFunction($function);
                                    $handle = $ref_function->invoke();
                                    if (is_string($handle)) {
                                        $return_value = $handle;
                                    } else {
                                        $return_value = fread($handle, 4096);
                                        pclose($handle);
                                    }
                                } else {
                                    if ($output_needed == False) {
                                        if (version_compare(PHP_VERSION, '5.1.0') >= 0 && disabled_php(null, "ArrayIterator") == False) {
                                            $it = new ArrayIterator(array(""));
                                            iterator_apply($it, $function, array());
                                        } else {
                                            if (disabled_php("register_tick_function") == False) {
                                                declare (ticks=1);
                                                register_tick_function($function);
                                                unregister_tick_function($function);
                                            } else {
                                                if (disabled_php("array_map") == False) {
                                                    array_map($function, array());
                                                } else {
                                                    if (disabled_php("array_walk") == False) {
                                                        $x = array();
                                                        array_walk($x, $function);
                                                    } else {
                                                        if (disabled_php("array_filter") == False) {
                                                            array_filter(array(), $function);
                                                        } else {
                                                            if (disabled_php("register_shutdown_function")) {
                                                                register_shutdown_function($function);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $return_value;
}
Exemplo n.º 13
0
 /**
  *  Appologies for the commented code.
  *  I would like to restore this functionality eventually.
  *  this is supposed to verify that ticks is a small enough number, as required
  *  by pnctl to fork and manage signals but that static var manipulation doesn't
  *  work from PHP7 so we'll disable for now
  */
 private function setup_ticks()
 {
     $tick_f = function () {
         ForkManager::confirmTicks();
     };
     register_tick_function($tick_f);
     // This is a short NOP+microsleep, just to
     // give verify_declare_ticks() a change to verify.
     $i = 0;
     $i++;
     $i++;
     $i++;
     time_nanosleep(0, 5000);
     if (self::$have_ticks) {
         unregister_tick_function($tick_f);
     } else {
         die("FM requires a 'declare(ticks=1);' in the calling code.\n");
     }
 }
Exemplo n.º 14
0
 /**
  * Starts the thread.
  * @return bool On successful execution returns true otherwise returns false.
  */
 public final function start()
 {
     // {{{
     if (!$this->amIParent()) {
         return false;
     }
     if ($this->amIStarted) {
         return false;
     }
     $this->childPid = pcntl_fork();
     if ($this->childPid == -1) {
         return false;
     }
     $this->_childPid = getmypid();
     $this->amIStarted = true;
     $csInitializationResult = null;
     if ($this->criticalSection !== null) {
         $csInitializationResult = $this->criticalSection->initialize($this->childPid, $this->uniqueId);
     }
     if (!$this->amIParent()) {
         // child
         // no dispatchers needed in the children; this means that no threads withing threads creation is possible
         unregister_tick_function('GPhpThreadCriticalSection::dispatch');
         // flag any subscribed variables indicating that the current
         // instance is located in a GPhpThread
         foreach (self::$originDynamicDataArr as &$o) {
             if ($o instanceof \GPhpThreadNotCloneableContainer) {
                 $o->import(true);
             }
         }
         if ($csInitializationResult === false) {
             $this->stop();
         }
         // don't execute the thread body if critical section is required, but missing
         pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD));
         $this->run();
         if ($this->criticalSection !== null) {
             $this->notifyParentThatChildIsTerminated();
         }
         $this->stop();
     } else {
         // parent
         if ($this->childPid != -1 && $this->criticalSection !== null) {
             if ($csInitializationResult === false) {
                 // don't add the thread to the dispatch queue if missing but required critical section is the case (actually this is done in the initialize method above)
                 $this->childPid = -1;
                 $this->_childPid = null;
                 $this->amIStarted = false;
                 return false;
             }
             if (!GPhpThread::$isCriticalSectionDispatcherRegistered) {
                 GPhpThread::$isCriticalSectionDispatcherRegistered = register_tick_function('GPhpThreadCriticalSection::dispatch');
             }
             pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD));
             // SIGCHLD will wait in the queue until it's processed
         }
         return true;
     }
     return true;
 }
Exemplo n.º 15
0
function jse_run($flags = JSE_ACCEL)
{
    // interrupt every 1000 low-level statements
    if ($flags & JSE_TICKS) {
        register_tick_function(array("jsrt", "tick_safe"));
        declare (ticks=1000);
    }
    #-- check for accelerator/assembler presence
    if ($flags & JSE_ACCEL && class_exists("jsa") && class_exists("jsrt")) {
        eval(jsa::assemble(NULL, $flags & JSE_TICKS));
    } else {
        jsi::run();
    }
    #-- clean up
    if ($flags & JSE_TICKS) {
        unregister_tick_function(array("jsrt", "tick_safe"));
        declare (ticks=0);
    }
}
Exemplo n.º 16
0
 /**
  * Unregister the ticker as tick function
  * @return \atick\Ticker
  */
 function unregister()
 {
     unregister_tick_function(array($this, "__invoke"));
     return $this;
 }
Exemplo n.º 17
0
 /**
  * @test
  * @expectedException \Ding\Helpers\Tcp\Exception\TcpException
  */
 public function cannot_socket_select_on_server_peers()
 {
     global $mockSocketCreate;
     global $mockSocketSelect;
     global $mockSocketListen;
     $mockSocketCreate = false;
     $mockSocketSelect = false;
     $mockSocketListen = false;
     $container = ContainerImpl::getInstance($this->_properties);
     $server = $container->getBean('Server');
     $server->open();
     $client = $container->getBean('Client6');
     $client->open();
     while (MyClientHandler::$time < 1) {
         usleep(1000);
     }
     unregister_tick_function(array($server, 'process'));
     unregister_tick_function(array($client, 'process'));
     $mockSocketListen = true;
     $server->processPeers();
     $mockSocketCreate = false;
     $mockSocketSelect = false;
     $mockSocketListen = false;
 }
Exemplo n.º 18
0
 public function stop()
 {
     $this->tick();
     $this->end_time = microtime(true);
     unregister_tick_function(array($this, "tick"));
 }
Exemplo n.º 19
0
 /**
  * Method used to stop execution time checker.
  *
  * @access public
  */
 public static function stopTimer()
 {
     unregister_tick_function('tick_timer');
 }
Exemplo n.º 20
0
 public static function stop()
 {
     unregister_tick_function('Profiler::count');
     trigger_error('Ticks needed to complete the requested operation: ' . self::$i, E_USER_NOTICE);
 }
Exemplo n.º 21
0
 public function init()
 {
     if (!self::$serverRequest instanceof PocketMinecraftServer) {
         self::$serverRequest = $this->server;
     }
     if ($this->getProperty("send-usage") !== false) {
         $this->server->schedule(6000, array($this, "sendUsage"), array(), true);
         //Send the info after 5 minutes have passed
         $this->sendUsage();
     }
     if ($this->getProperty("auto-save") === true) {
         $this->server->schedule(18000, array($this, "autoSave"), array(), true);
     }
     if (!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true) {
         $this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
     }
     if ($this->getProperty("enable-query") === true) {
         $this->query = new QueryHandler();
     }
     CraftingRecipes::init();
     $this->server->init();
     unregister_tick_function(array($this->server, "tick"));
     $this->console->__destruct();
     if ($this->rcon instanceof RCON) {
         $this->rcon->stop();
     }
     $this->__destruct();
     if ($this->getProperty("upnp-forwarding") === true) {
         console("[INFO] [UPnP] Removing port forward...");
         UPnP_RemovePortForward($this->getProperty("server-port"));
     }
     return $this->restart;
 }
Exemplo n.º 22
0
 private function unregisterSignalHandler()
 {
     if (!extension_loaded('pcntl')) {
         return;
     }
     pcntl_signal(SIGINT, SIG_DFL);
     unregister_tick_function([$this, 'signalDispatch']);
 }
Exemplo n.º 23
0
 /**
  * This method will find private methods started with test_ in
  * the current class and will execute each method in succession
  * by passing $t argument to it. Before each test execution
  * takes place, $t->prepareForTest($test) will be called. It must
  * return non-false for test to be carried out.
  *
  * $test will be an array containing keys for 'name', 'object' and
  * 'class'
  */
 function runTests(Tester $tester = null)
 {
     $test = array('object' => $this->name, 'class' => get_class($this));
     foreach (get_class_methods($this) as $method) {
         if (strpos($method, 'test_') === 0) {
             $test['name'] = substr($method, 5);
         } else {
             continue;
         }
         if ($tester && $tester->prepareForTest($test) === false) {
             continue;
         }
         if ($tester) {
             $r = $tester->results;
             $r->unload();
             $r->set($test);
         }
         // Proceed with test
         $me = memory_get_peak_usage();
         $ms = microtime(true);
         $this->_ticks = 0;
         declare (ticks=1);
         register_tick_function(array($this, '_ticker'));
         // Execute here
         try {
             $result = $this->{$method}($tester);
         } catch (Exception $e) {
             unregister_tick_function(array($this, '_ticker'));
             $time = microtime(true) - $ms;
             $memory = memory_get_peak_usage() - $me;
             $ticks = $this->_ticks;
             if ($e instanceof Exception_SkipTests) {
                 if ($tester) {
                     $r['exception'] = 'SKIPPED';
                     $r->saveAndUnload();
                 }
                 return array('skipped' => $e->getMessage());
             }
             if ($tester) {
                 $r['time'] = $time;
                 $r['memory'] = $memory;
                 $r['ticks'] = $ticks;
                 $r['exception'] = $e;
                 $r->saveAndUnload();
             }
             continue;
         }
         // Unregister
         unregister_tick_function(array($this, '_ticker'));
         $time = microtime(true) - $ms;
         $memory = memory_get_peak_usage() - $me;
         $ticks = $this->_ticks - 3;
         // there are always minimum of 3 ticks
         if ($tester) {
             $r['time'] = $time;
             $r['memory'] = $memory;
             $r['ticks'] = $ticks;
             $r['is_success'] = true;
             $r['result'] = $result;
             $r->saveAndUnload();
         }
     }
 }
Exemplo n.º 24
0
 /**
  * Disables the fatal handler and the tick callback.
  *
  * We disable the tick callback and the error handler during
  * a analysis, to generate faster output.
  */
 public function noFatalForKrexx()
 {
     if ($this->fatalShouldActive) {
         $this->krexxFatal->setIsActive(false);
         unregister_tick_function(array($this->krexxFatal, 'tickCallback'));
     }
 }
Exemplo n.º 25
0
 public function untick(...$args)
 {
     return unregister_tick_function(...$args);
 }
Exemplo n.º 26
0
 /**
  * "Unregister" the fatal error handler.
  *
  * Actually we can not unregister it. We simply tell it to not activate
  * and we unregister the tick function which provides us with the
  * backtrace.
  */
 public function unregisterFatalAction()
 {
     if (!is_null($this->krexxFatal)) {
         // Now we need to tell the shutdown function, that is must
         // not do anything on shutdown.
         $this->krexxFatal->setIsActive(false);
         unregister_tick_function(array($this->krexxFatal, 'tickCallback'));
     }
     $this->fatalShouldActive = false;
 }
Exemplo n.º 27
0
function a()
{
    echo "hello";
    unregister_tick_function('a');
}
Exemplo n.º 28
0
 /**
  */
 public function __destruct()
 {
     unregister_tick_function([$this, 'onTick']);
 }
Exemplo n.º 29
0
 function runTests($test_obj = null)
 {
     if (!$test_obj) {
         $test_obj = $this;
     }
     $tested = array();
     $data = array();
     foreach (get_class_methods($test_obj) as $method) {
         $m = '';
         if (strpos($method, 'test_') === 0) {
             $m = substr($method, 5);
         } elseif (strpos($method, 'prepare_') === 0) {
             $m = substr($method, 8);
         } else {
             continue;
         }
         if (isset($_GET['testonly']) && 'test_' . $_GET['testonly'] != $method) {
             continue;
         }
         // Do not retest same function even if it has both prepare and test
         if ($tested[$m]) {
             continue;
         }
         $tested[$m] = true;
         // Row contains test result data
         $row = array('name' => $m, 'id' => $m);
         foreach ($this->variances as $key => $vari) {
             if (is_numeric($key)) {
                 $key = $vari;
             }
             try {
                 // Input is a result of preparation function
                 if (method_exists($test_obj, 'prepare_' . $m)) {
                     $input = $test_obj->{'prepare_' . $m}($vari, $method);
                 } else {
                     if ($test_obj->hasMethod('prepare')) {
                         $input = $test_obj->prepare($vari, $method);
                     } else {
                         $input = null;
                     }
                 }
             } catch (Exception $e) {
                 if ($e instanceof Exception_SkipTests) {
                     $this->grid->destroy();
                     $this->add('View_Error')->set('Skipping all tests: ' . $e->getMessage());
                     return;
                 }
             }
             $this->input = $input;
             $test_func = method_exists($test_obj, 'test_' . $m) ? 'test_' . $m : 'test';
             // Test speed
             $me = memory_get_peak_usage();
             $ms = microtime(true);
             $this->cnt = 0;
             declare (ticks=1);
             register_tick_function(array($this, 'ticker'));
             try {
                 //$result=$test_obj->$test_func($input[0],$input[1],$input[2]);
                 $result = $this->executeTest($test_obj, $test_func, $input);
             } catch (Exception $e) {
                 if ($e instanceof Exception_SkipTests) {
                     $this->grid->destroy();
                     $this->add('View_Error')->set('Skipping all tests: ' . $e->getMessage());
                 }
                 if ($_GET['tester_details'] == $row['name'] && $_GET['vari'] == $vari) {
                     throw $e;
                 }
                 $result = 'Exception: ' . (method_exists($e, 'getText') ? $e->getText() : $e->getMessage());
                 $ll = $this->add('P', $row['name']);
                 $v = $ll->add('View')->setElement('a')->setAttr('href', '#')->set('More details')->js('click')->univ()->frameURL('Exception Details for test ' . $row['name'], $this->api->url(null, array('tester_details' => $row['name'], 'vari' => $vari)));
                 $result .= $ll->getHTML();
             }
             $ms = microtime(true) - $ms;
             $me = ($mend = memory_get_peak_usage()) - $me;
             unregister_tick_function(array($this, 'ticker'));
             $row[$key . '_inf'] = 'Ticks: ' . $this->cnt * 1 . '<br/>Memory: ' . $me;
             $result = $this->formatResult($row, $key, $result);
             $k = $key . '_' . $row['name'];
             if ($this->proper_responses[$k] == $result && isset($this->proper_responses[$k])) {
                 $row[$key . '_res'] = '<font color="green">PASS</font><br/>' . htmlspecialchars($result);
             } elseif ($this->proper_responses[$k]) {
                 $row[$key . '_res'] = '<font color="red">' . htmlspecialchars($result) . '</font><br/>' . var_export($this->proper_responses[$k], true);
             }
             $this->responses[] = '"' . $k . '"' . '=>' . var_export($result, true);
         }
         $data[] = $row;
     }
     $this->grid->setSource($data);
 }
Exemplo n.º 30
0
 /**
  * Processes the buffer to show the interface and/or the console messages
  */
 public static function processBuffer()
 {
     @unregister_tick_function('tickHandler');
     static::$_countTime = false;
     if (static::$_codeCoverage) {
         $trace_o = static::$_options['code_coverage'];
         static::$_options['code_coverage'] = true;
         static::stopCoverage();
         static::$_options['code_coverage'] = $trace_o;
     }
     if (static::$_functionTrace) {
         $trace_o = static::$_options['trace_functions'];
         static::$_options['trace_functions'] = true;
         static::stopTrace();
         static::$_options['trace_functions'] = $trace_o;
     }
     static::$_endTime = microtime(true);
     if (static::$_consoleStarted) {
         static::_debugConsole();
     }
     if (static::$_options['show_interface']) {
         static::_lastError();
         // get last php fatal error
         $interface = static::_buildInterface();
         // build the interface
         print $interface;
     }
 }