Several improvements for performance measuring
This commit is contained in:
parent
2c93067682
commit
fdee002f73
7
boot.php
7
boot.php
|
@ -417,6 +417,7 @@ if(! class_exists('App')) {
|
|||
$this->performance["database"] = 0;
|
||||
$this->performance["network"] = 0;
|
||||
$this->performance["rendering"] = 0;
|
||||
$this->performance["parser"] = 0;
|
||||
|
||||
$this->config = array();
|
||||
$this->page = array();
|
||||
|
@ -725,6 +726,12 @@ if(! class_exists('App')) {
|
|||
return $this->rdelim[$engine];
|
||||
}
|
||||
|
||||
function save_timestamp($stamp1, $value) {
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$this->performance[$value] += (float)$duration;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,6 +283,8 @@ function bb_ShareAttributes($match) {
|
|||
|
||||
function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// Hide all [noparse] contained bbtags by spacefying them
|
||||
|
@ -637,6 +639,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
|
|||
|
||||
call_hooks('bbcode',$Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
return $Text;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ class dba {
|
|||
public $error = false;
|
||||
|
||||
function __construct($server,$user,$pass,$db,$install = false) {
|
||||
global $a;
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$server = trim($server);
|
||||
$user = trim($user);
|
||||
|
@ -64,6 +67,8 @@ class dba {
|
|||
if(! $install)
|
||||
system_unavailable();
|
||||
}
|
||||
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
}
|
||||
|
||||
public function getdb() {
|
||||
|
@ -87,7 +92,6 @@ class dba {
|
|||
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$a->performance["database"] += (float)$duration;
|
||||
|
||||
if(x($a->config,'system') && x($a->config['system'],'db_log')) {
|
||||
if (($duration > $a->config["system"]["db_loglimit"])) {
|
||||
|
@ -164,6 +168,7 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
$a->save_timestamp($stamp1, "database");
|
||||
|
||||
if($this->debug)
|
||||
logger('dba: ' . printable(print_r($r, true)));
|
||||
|
|
|
@ -1159,7 +1159,9 @@ function item_store($arr,$force_parent = false) {
|
|||
|
||||
if (($cachefile != '') AND !file_exists($cachefile)) {
|
||||
$s = prepare_text($arr['body']);
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($cachefile, $s);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
|
||||
}
|
||||
|
||||
|
|
|
@ -104,9 +104,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
|||
$a->set_curl_headers($header);
|
||||
@curl_close($ch);
|
||||
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$a->performance["network"] += (float)$duration;
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
return($body);
|
||||
}}
|
||||
|
@ -201,9 +199,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
|
||||
curl_close($ch);
|
||||
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$a->performance["network"] += (float)$duration;
|
||||
$a->save_timestamp($stamp1, "network");
|
||||
|
||||
return($body);
|
||||
}}
|
||||
|
@ -851,8 +847,11 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
|||
$i = fetch_url($scaled);
|
||||
|
||||
$cachefile = get_cachefile(hash("md5", $scaled));
|
||||
if ($cachefile != '')
|
||||
if ($cachefile != '') {
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($cachefile, $i);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = guess_image_type($mtch[1],true);
|
||||
|
|
|
@ -201,12 +201,15 @@ function get_plugin_info($plugin){
|
|||
'author' => array(),
|
||||
'version' => ""
|
||||
);
|
||||
|
||||
|
||||
if (!is_file("addon/$plugin/$plugin.php")) return $info;
|
||||
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
$f = file_get_contents("addon/$plugin/$plugin.php");
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
|
||||
$r = preg_match("|/\*.*\*/|msU", $f, $m);
|
||||
|
||||
|
||||
if ($r){
|
||||
$ll = explode("\n", $m[0]);
|
||||
foreach( $ll as $l ) {
|
||||
|
@ -266,11 +269,13 @@ function get_theme_info($theme){
|
|||
$info['unsupported'] = true;
|
||||
|
||||
if (!is_file("view/theme/$theme/theme.php")) return $info;
|
||||
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
$f = file_get_contents("view/theme/$theme/theme.php");
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
|
||||
$r = preg_match("|/\*.*\*/|msU", $f, $m);
|
||||
|
||||
|
||||
|
||||
if ($r){
|
||||
$ll = explode("\n", $m[0]);
|
||||
foreach( $ll as $l ) {
|
||||
|
|
|
@ -46,7 +46,9 @@ function create_tags_from_item($itemid) {
|
|||
|
||||
if (($cachefile != '') AND !file_exists($cachefile)) {
|
||||
$s = prepare_text($message['body']);
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($cachefile, $s);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile);
|
||||
}
|
||||
|
||||
|
|
|
@ -428,15 +428,26 @@ function load_view_file($s) {
|
|||
$lang = 'en';
|
||||
$b = basename($s);
|
||||
$d = dirname($s);
|
||||
if(file_exists("$d/$lang/$b"))
|
||||
return file_get_contents("$d/$lang/$b");
|
||||
if(file_exists("$d/$lang/$b")) {
|
||||
$stamp1 = microtime(true);
|
||||
$content = file_get_contents("$d/$lang/$b");
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
return $content;
|
||||
}
|
||||
|
||||
$theme = current_theme();
|
||||
|
||||
if(file_exists("$d/theme/$theme/$b"))
|
||||
return file_get_contents("$d/theme/$theme/$b");
|
||||
if(file_exists("$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')) {
|
||||
|
@ -451,12 +462,22 @@ function get_intltext_template($s) {
|
|||
if(! isset($lang))
|
||||
$lang = 'en';
|
||||
|
||||
if(file_exists("view/$lang$engine/$s"))
|
||||
return file_get_contents("view/$lang$engine/$s");
|
||||
elseif(file_exists("view/en$engine/$s"))
|
||||
return file_get_contents("view/en$engine/$s");
|
||||
else
|
||||
return file_get_contents("view$engine/$s");
|
||||
if(file_exists("view/$lang$engine/$s")) {
|
||||
$stamp1 = microtime(true);
|
||||
$content = file_get_contents("view/$lang$engine/$s");
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
return $content;
|
||||
} 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')) {
|
||||
|
@ -470,21 +491,19 @@ function get_markup_template($s, $root = '') {
|
|||
|
||||
$template = new FriendicaSmarty();
|
||||
$template->filename = $template_file;
|
||||
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$a->performance["rendering"] += (float)$duration;
|
||||
$a->save_timestamp($stamp1, "rendering");
|
||||
|
||||
return $template;
|
||||
}
|
||||
else {
|
||||
$template_file = get_template_file($a, $s, $root);
|
||||
$a->save_timestamp($stamp1, "rendering");
|
||||
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2-$stamp1);
|
||||
$a->performance["rendering"] += (float)$duration;
|
||||
$stamp1 = microtime(true);
|
||||
$content = file_get_contents($template_file);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
return $content;
|
||||
|
||||
return file_get_contents($template_file);
|
||||
}
|
||||
}}
|
||||
|
||||
|
@ -541,8 +560,10 @@ function logger($msg,$level = 0) {
|
|||
|
||||
if((! $debugging) || (! $logfile) || ($level > $loglevel))
|
||||
return;
|
||||
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
@file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
return;
|
||||
}}
|
||||
|
||||
|
@ -1029,11 +1050,15 @@ function prepare_body($item,$attach = false) {
|
|||
$cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));
|
||||
|
||||
if (($cachefile != '')) {
|
||||
if (file_exists($cachefile))
|
||||
if (file_exists($cachefile)) {
|
||||
$stamp1 = microtime(true);
|
||||
$s = file_get_contents($cachefile);
|
||||
else {
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
} else {
|
||||
$s = prepare_text($item['body']);
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($cachefile, $s);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
|
||||
}
|
||||
} else
|
||||
|
|
|
@ -762,7 +762,9 @@ function item_post(&$a) {
|
|||
|
||||
if (($cachefile != '') AND !file_exists($cachefile)) {
|
||||
$s = prepare_text($datarray['body']);
|
||||
$stamp1 = microtime(true);
|
||||
file_put_contents($cachefile, $s);
|
||||
$a->save_timestamp($stamp1, "file");
|
||||
logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue