add async include and et2 render times to page-generation-times shown

This commit is contained in:
Ralf Becker 2014-01-09 12:20:13 +00:00
parent 5179794f15
commit 90edb55ec5
6 changed files with 56 additions and 15 deletions

View File

@ -195,8 +195,14 @@ class etemplate_new extends etemplate_widget_template
// check if we are in an ajax-exec call from jdots template (or future other tabbed templates) // check if we are in an ajax-exec call from jdots template (or future other tabbed templates)
if (isset($GLOBALS['egw']->framework->response)) if (isset($GLOBALS['egw']->framework->response))
{ {
//error_log("Ajax " . __LINE__); $content = '<div id="'.$dom_id.'" class="et2_container"></div>';
$GLOBALS['egw']->framework->response->generic("data", array('<div id="'.$dom_id.'" class="et2_container"></div>')); // add server-side page-generation times
if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time'])
{
$vars = $GLOBALS['egw']->framework->_get_footer();
$content .= "\n".$vars['page_generation_time'];
}
$GLOBALS['egw']->framework->response->generic("data", array($content));
$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+egw_framework::get_extra()); $GLOBALS['egw']->framework->response->generic('et2_load',$load_array+egw_framework::get_extra());
self::$request = null; self::$request = null;
return; return;

View File

@ -207,6 +207,8 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
if (!$j.isArray(_data.langRequire)) _data.langRequire = []; if (!$j.isArray(_data.langRequire)) _data.langRequire = [];
egw(currentapp, window).langRequire(window, _data.langRequire, function() egw(currentapp, window).langRequire(window, _data.langRequire, function()
{ {
var start_time = (new Date).getTime();
// Appname should be first part of the template name // Appname should be first part of the template name
var split = _name.split('.'); var split = _name.split('.');
var appname = split[0]; var appname = split[0];
@ -311,6 +313,12 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
} }
$j(this.DOMContainer).trigger('load', this); $j(this.DOMContainer).trigger('load', this);
var end_time = (new Date).getTime();
var gen_time_div = $j('#divGenTime_'+appname);
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
gen_time_div.find('.et2RenderTime').remove();
gen_time_div.append('<span class="et2RenderTime">'+egw.lang('eT2 rendering took %1s', (end_time-start_time)/1000)+'</span>');
},this)); },this));
}; };

View File

@ -547,7 +547,7 @@ abstract class egw_framework
* *
* @return array * @return array
*/ */
protected function _get_footer() public function _get_footer()
{ {
$var = Array( $var = Array(
'img_root' => $GLOBALS['egw_info']['server']['webserver_url'] . $this->template_dir.'/images', 'img_root' => $GLOBALS['egw_info']['server']['webserver_url'] . $this->template_dir.'/images',
@ -558,7 +558,7 @@ abstract class egw_framework
{ {
$totaltime = sprintf('%4.2lf',microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']); $totaltime = sprintf('%4.2lf',microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']);
$var['page_generation_time'] = '<div id="divGenTime"><br/><span>'.lang('Page was generated in %1 seconds',$totaltime); $var['page_generation_time'] = '<div class="pageGenTime" id="divGenTime_'.$GLOBALS['egw_info']['flags']['currentapp'].'"><span>'.lang('Page was generated in %1 seconds',$totaltime);
if ($GLOBALS['egw_info']['flags']['session_restore_time']) if ($GLOBALS['egw_info']['flags']['session_restore_time'])
{ {
$var['page_generation_time'] .= ' '.lang('(session restored in %1 seconds)', $var['page_generation_time'] .= ' '.lang('(session restored in %1 seconds)',

View File

@ -39,6 +39,7 @@
(function(){ (function(){
var debug = false; var debug = false;
var egw_script = document.getElementById('egw_script_id'); var egw_script = document.getElementById('egw_script_id');
var start_time = (new Date).getTime();
// Flag for if this is opened in a popup // Flag for if this is opened in a popup
var popup = (window.opener != null); var popup = (window.opener != null);
@ -151,8 +152,14 @@
break; break;
} }
} }
window.egw_LAB.script(include).wait(function() window.egw_LAB.script(include).wait(function()
{ {
var end_time = (new Date).getTime();
var gen_time_div = $j('#divGenTime_'+window.egw_appName);
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
gen_time_div.append('<span class="asyncIncludeTime">'+egw.lang('async includes took %1s', (end_time-start_time)/1000)+'</span>');
// Make sure opener knows when we close - start a heartbeat // Make sure opener knows when we close - start a heartbeat
if((popup || window.opener) && window.name != '') if((popup || window.opener) && window.name != '')
{ {

View File

@ -120,7 +120,14 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
} }
if(js_files.length > 0) if(js_files.length > 0)
{ {
this.egw.includeJS(js_files, function() {this.handleResponse(data);}, this); var start_time = (new Date).getTime();
this.egw.includeJS(js_files, function() {
var end_time = (new Date).getTime();
this.handleResponse(data);
var gen_time_div = $j('#divGenTime_'+this.egw.appname);
if (!gen_time_div.length) gen_time_div = $j('.pageGenTime');
gen_time_div.append('<span class="asyncIncludeTime">'+egw.lang('async includes took %1s', (end_time-start_time)/1000)+'</span>');
}, this);
return; return;
} }
for (var i = 0; i < data.response.length; i++) for (var i = 0; i < data.response.length; i++)

View File

@ -59,10 +59,23 @@ a:hover,a:active
color:#666666; color:#666666;
} }
#divGenTime,#divPoweredBy .pageGenTime,#divPoweredBy
{ {
font-size: 80%; font-size: 80%;
color: #ff0000; color: #ff0000;
text-align: center;
}
.pageGenTime {
margin-top: 1em;
}
.pageGenTime > span:after {
content: ", ";
}
.pageGenTime > span:last-child:after {
content: "";
} }
#divPoweredBy #divPoweredBy