Several improvements for performance measuring

This commit is contained in:
Michael Vogel 2013-01-26 18:35:39 +01:00
parent 2c93067682
commit fdee002f73
9 changed files with 87 additions and 36 deletions

View File

@ -417,6 +417,7 @@ if(! class_exists('App')) {
$this->performance["database"] = 0; $this->performance["database"] = 0;
$this->performance["network"] = 0; $this->performance["network"] = 0;
$this->performance["rendering"] = 0; $this->performance["rendering"] = 0;
$this->performance["parser"] = 0;
$this->config = array(); $this->config = array();
$this->page = array(); $this->page = array();
@ -725,6 +726,12 @@ if(! class_exists('App')) {
return $this->rdelim[$engine]; return $this->rdelim[$engine];
} }
function save_timestamp($stamp1, $value) {
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$this->performance[$value] += (float)$duration;
}
} }
} }

View File

@ -283,6 +283,8 @@ function bb_ShareAttributes($match) {
function bbcode($Text,$preserve_nl = false, $tryoembed = true) { function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$stamp1 = microtime(true);
$a = get_app(); $a = get_app();
// Hide all [noparse] contained bbtags by spacefying them // Hide all [noparse] contained bbtags by spacefying them
@ -637,6 +639,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
call_hooks('bbcode',$Text); call_hooks('bbcode',$Text);
$a->save_timestamp($stamp1, "parser");
return $Text; return $Text;
} }

View File

@ -23,6 +23,9 @@ class dba {
public $error = false; public $error = false;
function __construct($server,$user,$pass,$db,$install = false) { function __construct($server,$user,$pass,$db,$install = false) {
global $a;
$stamp1 = microtime(true);
$server = trim($server); $server = trim($server);
$user = trim($user); $user = trim($user);
@ -64,6 +67,8 @@ class dba {
if(! $install) if(! $install)
system_unavailable(); system_unavailable();
} }
$a->save_timestamp($stamp1, "network");
} }
public function getdb() { public function getdb() {
@ -87,7 +92,6 @@ class dba {
$stamp2 = microtime(true); $stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1); $duration = (float)($stamp2-$stamp1);
$a->performance["database"] += (float)$duration;
if(x($a->config,'system') && x($a->config['system'],'db_log')) { if(x($a->config,'system') && x($a->config['system'],'db_log')) {
if (($duration > $a->config["system"]["db_loglimit"])) { if (($duration > $a->config["system"]["db_loglimit"])) {
@ -164,6 +168,7 @@ class dba {
} }
} }
$a->save_timestamp($stamp1, "database");
if($this->debug) if($this->debug)
logger('dba: ' . printable(print_r($r, true))); logger('dba: ' . printable(print_r($r, true)));

View File

@ -1159,7 +1159,9 @@ function item_store($arr,$force_parent = false) {
if (($cachefile != '') AND !file_exists($cachefile)) { if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($arr['body']); $s = prepare_text($arr['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s); file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('item_store: put item '.$current_post.' into cachefile '.$cachefile); logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
} }

View File

@ -104,9 +104,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$a->set_curl_headers($header); $a->set_curl_headers($header);
@curl_close($ch); @curl_close($ch);
$stamp2 = microtime(true); $a->save_timestamp($stamp1, "network");
$duration = (float)($stamp2-$stamp1);
$a->performance["network"] += (float)$duration;
return($body); return($body);
}} }}
@ -201,9 +199,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
curl_close($ch); curl_close($ch);
$stamp2 = microtime(true); $a->save_timestamp($stamp1, "network");
$duration = (float)($stamp2-$stamp1);
$a->performance["network"] += (float)$duration;
return($body); return($body);
}} }}
@ -851,8 +847,11 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
$i = fetch_url($scaled); $i = fetch_url($scaled);
$cachefile = get_cachefile(hash("md5", $scaled)); $cachefile = get_cachefile(hash("md5", $scaled));
if ($cachefile != '') if ($cachefile != '') {
$stamp1 = microtime(true);
file_put_contents($cachefile, $i); file_put_contents($cachefile, $i);
$a->save_timestamp($stamp1, "file");
}
// guess mimetype from headers or filename // guess mimetype from headers or filename
$type = guess_image_type($mtch[1],true); $type = guess_image_type($mtch[1],true);

View File

@ -204,7 +204,10 @@ function get_plugin_info($plugin){
if (!is_file("addon/$plugin/$plugin.php")) return $info; if (!is_file("addon/$plugin/$plugin.php")) return $info;
$stamp1 = microtime(true);
$f = file_get_contents("addon/$plugin/$plugin.php"); $f = file_get_contents("addon/$plugin/$plugin.php");
$a->save_timestamp($stamp1, "file");
$r = preg_match("|/\*.*\*/|msU", $f, $m); $r = preg_match("|/\*.*\*/|msU", $f, $m);
if ($r){ if ($r){
@ -267,9 +270,11 @@ function get_theme_info($theme){
if (!is_file("view/theme/$theme/theme.php")) return $info; if (!is_file("view/theme/$theme/theme.php")) return $info;
$stamp1 = microtime(true);
$f = file_get_contents("view/theme/$theme/theme.php"); $f = file_get_contents("view/theme/$theme/theme.php");
$r = preg_match("|/\*.*\*/|msU", $f, $m); $a->save_timestamp($stamp1, "file");
$r = preg_match("|/\*.*\*/|msU", $f, $m);
if ($r){ if ($r){
$ll = explode("\n", $m[0]); $ll = explode("\n", $m[0]);

View File

@ -46,7 +46,9 @@ function create_tags_from_item($itemid) {
if (($cachefile != '') AND !file_exists($cachefile)) { if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($message['body']); $s = prepare_text($message['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s); file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile); logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile);
} }

View File

@ -428,15 +428,26 @@ function load_view_file($s) {
$lang = 'en'; $lang = 'en';
$b = basename($s); $b = basename($s);
$d = dirname($s); $d = dirname($s);
if(file_exists("$d/$lang/$b")) if(file_exists("$d/$lang/$b")) {
return file_get_contents("$d/$lang/$b"); $stamp1 = microtime(true);
$content = file_get_contents("$d/$lang/$b");
$a->save_timestamp($stamp1, "file");
return $content;
}
$theme = current_theme(); $theme = current_theme();
if(file_exists("$d/theme/$theme/$b")) if(file_exists("$d/theme/$theme/$b")) {
return file_get_contents("$d/theme/$theme/$b"); $stamp1 = microtime(true);
$content = file_get_contents("$d/theme/$theme/$b");
$a->save_timestamp($stamp1, "file");
return $content;
}
return file_get_contents($s); $stamp1 = microtime(true);
$content = file_get_contents($s);
$a->save_timestamp($stamp1, "file");
return $content;
}} }}
if(! function_exists('get_intltext_template')) { if(! function_exists('get_intltext_template')) {
@ -451,12 +462,22 @@ function get_intltext_template($s) {
if(! isset($lang)) if(! isset($lang))
$lang = 'en'; $lang = 'en';
if(file_exists("view/$lang$engine/$s")) if(file_exists("view/$lang$engine/$s")) {
return file_get_contents("view/$lang$engine/$s"); $stamp1 = microtime(true);
elseif(file_exists("view/en$engine/$s")) $content = file_get_contents("view/$lang$engine/$s");
return file_get_contents("view/en$engine/$s"); $a->save_timestamp($stamp1, "file");
else return $content;
return file_get_contents("view$engine/$s"); } elseif(file_exists("view/en$engine/$s")) {
$stamp1 = microtime(true);
$content = file_get_contents("view/en$engine/$s");
$a->save_timestamp($stamp1, "file");
return $content;
} else {
$stamp1 = microtime(true);
$content = file_get_contents("view$engine/$s");
$a->save_timestamp($stamp1, "file");
return $content;
}
}} }}
if(! function_exists('get_markup_template')) { if(! function_exists('get_markup_template')) {
@ -470,21 +491,19 @@ function get_markup_template($s, $root = '') {
$template = new FriendicaSmarty(); $template = new FriendicaSmarty();
$template->filename = $template_file; $template->filename = $template_file;
$a->save_timestamp($stamp1, "rendering");
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["rendering"] += (float)$duration;
return $template; return $template;
} }
else { else {
$template_file = get_template_file($a, $s, $root); $template_file = get_template_file($a, $s, $root);
$a->save_timestamp($stamp1, "rendering");
$stamp2 = microtime(true); $stamp1 = microtime(true);
$duration = (float)($stamp2-$stamp1); $content = file_get_contents($template_file);
$a->performance["rendering"] += (float)$duration; $a->save_timestamp($stamp1, "file");
return $content;
return file_get_contents($template_file);
} }
}} }}
@ -542,7 +561,9 @@ function logger($msg,$level = 0) {
if((! $debugging) || (! $logfile) || ($level > $loglevel)) if((! $debugging) || (! $logfile) || ($level > $loglevel))
return; return;
$stamp1 = microtime(true);
@file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND); @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
$a->save_timestamp($stamp1, "file");
return; return;
}} }}
@ -1029,11 +1050,15 @@ function prepare_body($item,$attach = false) {
$cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));
if (($cachefile != '')) { if (($cachefile != '')) {
if (file_exists($cachefile)) if (file_exists($cachefile)) {
$stamp1 = microtime(true);
$s = file_get_contents($cachefile); $s = file_get_contents($cachefile);
else { $a->save_timestamp($stamp1, "file");
} else {
$s = prepare_text($item['body']); $s = prepare_text($item['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s); file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile); logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
} }
} else } else

View File

@ -762,7 +762,9 @@ function item_post(&$a) {
if (($cachefile != '') AND !file_exists($cachefile)) { if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($datarray['body']); $s = prepare_text($datarray['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s); file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile); logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile);
} }