support for Context profiling
This commit is contained in:
parent
a1da59804e
commit
4b86497816
3 changed files with 82 additions and 0 deletions
|
@ -723,12 +723,14 @@ $_event_count = 0;
|
|||
*/
|
||||
function send_event(Event $event) {
|
||||
global $_event_listeners, $_event_count;
|
||||
ctx_log_start("Processing ".get_class($event));
|
||||
$my_event_listeners = $_event_listeners; // http://bugs.php.net/bug.php?id=35106
|
||||
ksort($my_event_listeners);
|
||||
foreach($my_event_listeners as $listener) {
|
||||
$listener->receive_event($event);
|
||||
}
|
||||
$_event_count++;
|
||||
ctx_log_endok("Processing ".get_class($event));
|
||||
}
|
||||
|
||||
|
||||
|
|
18
index.php
18
index.php
|
@ -53,6 +53,7 @@
|
|||
// set up and purify the environment
|
||||
define("DEBUG", true);
|
||||
define("COVERAGE", true);
|
||||
define("CONTEXT", false);
|
||||
define("CACHE_MEMCACHE", false);
|
||||
define("CACHE_DIR", false);
|
||||
define("VERSION", 'trunk');
|
||||
|
@ -66,6 +67,11 @@ if(empty($database_dsn) && !file_exists("config.php")) {
|
|||
|
||||
require_once "config.php";
|
||||
require_once "core/util.inc.php";
|
||||
require_once "lib/context.php";
|
||||
if(CONTEXT) {
|
||||
ctx_set_log(CONTEXT);
|
||||
}
|
||||
ctx_log_start($_SERVER["REQUEST_URI"], true, true);
|
||||
if(COVERAGE) {
|
||||
_start_coverage();
|
||||
register_shutdown_function("_end_coverage");
|
||||
|
@ -76,19 +82,25 @@ _start_cache();
|
|||
|
||||
try {
|
||||
// load base files
|
||||
ctx_log_start("Initialisation");
|
||||
ctx_log_start("Opening files");
|
||||
$files = array_merge(glob("core/*.php"), glob("ext/*/main.php"));
|
||||
foreach($files as $filename) {
|
||||
require_once $filename;
|
||||
}
|
||||
ctx_log_endok();
|
||||
|
||||
|
||||
ctx_log_start("Connecting to DB");
|
||||
// connect to the database
|
||||
$database = new Database();
|
||||
//$database->db->fnExecute = '_count_execs'; // FIXME: PDO equivalent
|
||||
$database->db->beginTransaction();
|
||||
$config = new DatabaseConfig($database);
|
||||
ctx_log_endok();
|
||||
|
||||
|
||||
ctx_log_start("Loading themelets");
|
||||
// load the theme parts
|
||||
$_theme = $config->get_string("theme", "default");
|
||||
if(!file_exists("themes/$_theme")) $_theme = "default";
|
||||
|
@ -111,6 +123,7 @@ try {
|
|||
}
|
||||
}
|
||||
}
|
||||
ctx_log_endok();
|
||||
|
||||
|
||||
// initialise the extensions
|
||||
|
@ -121,17 +134,21 @@ try {
|
|||
add_event_listener($c, $c->get_priority());
|
||||
}
|
||||
}
|
||||
ctx_log_endok("Initialisation");
|
||||
|
||||
|
||||
ctx_log_start("Page generation");
|
||||
// start the page generation waterfall
|
||||
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
|
||||
$user = _get_user($config, $database);
|
||||
send_event(new InitExtEvent());
|
||||
send_event(_get_page_request());
|
||||
$page->display();
|
||||
ctx_log_endok("Page generation");
|
||||
|
||||
$database->db->commit();
|
||||
_end_cache();
|
||||
ctx_log_endok();
|
||||
}
|
||||
catch(Exception $e) {
|
||||
$version = VERSION;
|
||||
|
@ -150,5 +167,6 @@ catch(Exception $e) {
|
|||
</html>
|
||||
EOD;
|
||||
$database->db->rollback();
|
||||
ctx_log_ender();
|
||||
}
|
||||
?>
|
||||
|
|
62
lib/context.php
Normal file
62
lib/context.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
$_context_log = null;
|
||||
|
||||
function ctx_set_log($name) {
|
||||
global $_context_log;
|
||||
if($name) {
|
||||
$_context_log = fopen($name, "a");
|
||||
}
|
||||
else {
|
||||
$_context_log = null;
|
||||
}
|
||||
}
|
||||
|
||||
function ctx_log_msg($func, $text, $type) {
|
||||
global $_context_log;
|
||||
if($_context_log) {
|
||||
fprintf(
|
||||
$_context_log,
|
||||
"%f %s %d %d %s %s %s\n",
|
||||
microtime(true), # returning a float is 5.0+
|
||||
php_uname('n'), # gethostname() is 5.3+
|
||||
posix_getpid(),
|
||||
posix_getpid(), //gettid(),
|
||||
$type, $func, $text
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function __get_func() {
|
||||
$stack = debug_backtrace();
|
||||
if(count($stack) < 3) {
|
||||
return "top-level";
|
||||
}
|
||||
$p = $stack[2];
|
||||
return $p['function'];
|
||||
}
|
||||
|
||||
function ctx_log_bmark($text=null) {ctx_log_msg(__get_func(), $text, "BMARK");}
|
||||
function ctx_log_clear($text=null) {ctx_log_msg(__get_func(), $text, "CLEAR");}
|
||||
|
||||
function ctx_log_start($text=null, $bookmark=false, $clear=false) {
|
||||
if($clear) {
|
||||
ctx_log_msg(__get_func(), $text, "CLEAR");
|
||||
}
|
||||
if($bookmark) {
|
||||
ctx_log_msg(__get_func(), $text, "BMARK");
|
||||
}
|
||||
ctx_log_msg(__get_func(), $text, "START");
|
||||
}
|
||||
function ctx_log_endok($text=null, $clear=false) {
|
||||
ctx_log_msg(__get_func(), $text, "ENDOK");
|
||||
if($clear) {
|
||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
||||
}
|
||||
}
|
||||
function ctx_log_ender($text=null, $clear=false) {
|
||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
||||
if($clear) {
|
||||
ctx_log_msg(__get_func(), $text, "ENDER");
|
||||
}
|
||||
}
|
||||
?>
|
Reference in a new issue