Merge pull request #5313 from senky/ticket/12628

[ticket/12628] Introduce debug.memory
This commit is contained in:
Marc Alexander 2018-10-09 14:05:42 +02:00 committed by GitHub
commit 466d331fec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 10 deletions

View file

@ -9,6 +9,7 @@ core:
exceptions: true exceptions: true
load_time: true load_time: true
sql_explain: true sql_explain: true
memory: true
twig: twig:
debug: true debug: true

View file

@ -4556,7 +4556,9 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
*/ */
function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db) function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db)
{ {
if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG')) global $phpbb_container;
if ($phpbb_container->getParameter('debug.sql_explain') && $request->variable('explain', false) && $auth->acl_get('a_'))
{ {
$db->sql_report('display'); $db->sql_report('display');
} }
@ -4586,9 +4588,10 @@ function phpbb_generate_debug_output(\phpbb\db\driver\driver_interface $db, \php
$totaltime = microtime(true) - $GLOBALS['starttime']; $totaltime = microtime(true) - $GLOBALS['starttime'];
$debug_info[] = sprintf('<span title="SQL time: %.3fs / PHP time: %.3fs">Time: %.3fs</span>', $db->get_sql_time(), ($totaltime - $db->get_sql_time()), $totaltime); $debug_info[] = sprintf('<span title="SQL time: %.3fs / PHP time: %.3fs">Time: %.3fs</span>', $db->get_sql_time(), ($totaltime - $db->get_sql_time()), $totaltime);
} }
}
$debug_info[] = sprintf('<span title="Cached: %d">Queries: %d</span>', $db->sql_num_queries(true), $db->sql_num_queries()); if ($phpbb_container->getParameter('debug.memory'))
{
$memory_usage = memory_get_peak_usage(); $memory_usage = memory_get_peak_usage();
if ($memory_usage) if ($memory_usage)
{ {
@ -4596,18 +4599,20 @@ function phpbb_generate_debug_output(\phpbb\db\driver\driver_interface $db, \php
$debug_info[] = 'Peak Memory Usage: ' . $memory_usage; $debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
} }
}
if (defined('DEBUG'))
{
$debug_info[] = 'GZIP: ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off'); $debug_info[] = 'GZIP: ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off');
if ($user->load) if ($user->load)
{ {
$debug_info[] = 'Load: ' . $user->load; $debug_info[] = 'Load: ' . $user->load;
} }
}
if ($auth->acl_get('a_') && $phpbb_container->getParameter('debug.sql_explain')) if ($phpbb_container->getParameter('debug.sql_explain'))
{
$debug_info[] = sprintf('<span title="Cached: %d">Queries: %d</span>', $db->sql_num_queries(true), $db->sql_num_queries());
if ($auth->acl_get('a_'))
{ {
$debug_info[] = '<a href="' . build_url() . '&amp;explain=1">SQL Explain</a>'; $debug_info[] = '<a href="' . build_url() . '&amp;explain=1">SQL Explain</a>';
} }

View file

@ -63,7 +63,7 @@ class convertor
{ {
global $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth; global $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth;
global $convert, $convert_row, $message_parser, $skip_rows, $language; global $convert, $convert_row, $message_parser, $skip_rows, $language;
global $request, $phpbb_dispatcher; global $request, $phpbb_dispatcher, $phpbb_container;
$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx); $phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
extract($phpbb_config_php_file->get_all()); extract($phpbb_config_php_file->get_all());
@ -687,7 +687,7 @@ class convertor
$this->template->assign_block_vars('checks', array( $this->template->assign_block_vars('checks', array(
'TITLE' => "skip_rows = $skip_rows", 'TITLE' => "skip_rows = $skip_rows",
'RESULT' => $rows . ((defined('DEBUG') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''), 'RESULT' => $rows . (($phpbb_container->getParameter('debug.memory') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''),
)); ));
$mtime = explode(' ', microtime()); $mtime = explode(' ', microtime());
@ -920,6 +920,7 @@ class convertor
{ {
global $user, $db, $phpbb_root_path, $phpEx, $config, $cache; global $user, $db, $phpbb_root_path, $phpEx, $config, $cache;
global $convert; global $convert;
global $phpbb_container;
include_once ($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include_once ($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
@ -959,7 +960,7 @@ class convertor
sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true); sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true);
$this->template->assign_block_vars('checks', array( $this->template->assign_block_vars('checks', array(
'TITLE' => sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . ((defined('DEBUG') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''), 'TITLE' => sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . (($phpbb_container->getParameter('debug.memory') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''),
'RESULT' => $user->lang['DONE'], 'RESULT' => $user->lang['DONE'],
)); ));

View file

@ -38,6 +38,7 @@ class container_configuration implements ConfigurationInterface
->booleanNode('exceptions')->defaultValue(false)->end() ->booleanNode('exceptions')->defaultValue(false)->end()
->booleanNode('load_time')->defaultValue(false)->end() ->booleanNode('load_time')->defaultValue(false)->end()
->booleanNode('sql_explain')->defaultValue(false)->end() ->booleanNode('sql_explain')->defaultValue(false)->end()
->booleanNode('memory')->defaultValue(false)->end()
->end() ->end()
->end() ->end()
->arrayNode('twig') ->arrayNode('twig')