Performance: Adding several variables for performance measuring.

This commit is contained in:
Michael - piratica.eu 2013-01-26 16:46:43 +01:00
parent cc9ce39e3f
commit 2c93067682
4 changed files with 61 additions and 31 deletions

View File

@ -355,6 +355,7 @@ if(! class_exists('App')) {
public $identities;
public $is_mobile;
public $is_tablet;
public $performance = array();
public $nav_sel;
@ -412,6 +413,11 @@ if(! class_exists('App')) {
date_default_timezone_set($this->timezone);
$this->performance["start"] = microtime(true);
$this->performance["database"] = 0;
$this->performance["network"] = 0;
$this->performance["rendering"] = 0;
$this->config = array();
$this->page = array();
$this->pager= array();

View File

@ -78,18 +78,20 @@ class dba {
$this->error = '';
if(x($a->config,'system') && x($a->config['system'],'db_log'))
$stamp1 = microtime(true);
$stamp1 = microtime(true);
if($this->mysqli)
$result = @$this->db->query($sql);
else
$result = @mysql_query($sql,$this->db);
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["database"] += (float)$duration;
if(x($a->config,'system') && x($a->config['system'],'db_log')) {
$stamp2 = microtime(true);
$duration = round($stamp2-$stamp1, 3);
if (($duration > $a->config["system"]["db_loglimit"])) {
$duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log"], $duration."\t".
basename($backtrace[1]["file"])."\t".

View File

@ -7,6 +7,8 @@
if(! function_exists('fetch_url')) {
function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
$stamp1 = microtime(true);
$a = get_app();
$ch = @curl_init($url);
@ -101,6 +103,11 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$body = substr($s,strlen($header));
$a->set_curl_headers($header);
@curl_close($ch);
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["network"] += (float)$duration;
return($body);
}}
@ -108,6 +115,9 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
if(! function_exists('post_url')) {
function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
$stamp1 = microtime(true);
$a = get_app();
$ch = curl_init($url);
if(($redirects > 8) || (! $ch))
@ -190,6 +200,11 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
$a->set_curl_headers($header);
curl_close($ch);
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["network"] += (float)$duration;
return($body);
}}

View File

@ -15,7 +15,8 @@ if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
global $t;
// $ts = microtime();
$stamp1 = microtime(true);
$a = get_app();
if($a->theme['template_engine'] === 'smarty3') {
@ -37,9 +38,11 @@ function replace_macros($s,$r) {
$output = template_unescape($r);
}
// $tt = microtime() - $ts;
// $a = get_app();
// $a->page['debug'] .= "$tt <br>\n";
$a = get_app();
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["rendering"] += (float)$duration;
return $output;
}}
@ -458,7 +461,8 @@ function get_intltext_template($s) {
if(! function_exists('get_markup_template')) {
function get_markup_template($s, $root = '') {
// $ts = microtime();
$stamp1 = microtime(true);
$a = get_app();
if($a->theme['template_engine'] === 'smarty3') {
@ -467,16 +471,19 @@ function get_markup_template($s, $root = '') {
$template = new FriendicaSmarty();
$template->filename = $template_file;
// $tt = microtime() - $ts;
// $a->page['debug'] .= "$tt <br>\n";
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["rendering"] += (float)$duration;
return $template;
}
else {
$template_file = get_template_file($a, $s, $root);
// $file_contents = file_get_contents($template_file);
// $tt = microtime() - $ts;
// $a->page['debug'] .= "$tt <br>\n";
// return $file_contents;
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$a->performance["rendering"] += (float)$duration;
return file_get_contents($template_file);
}
}}