Skip to content

Commit

Permalink
(migration) log cumulative mysql timing info everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
grandsbor committed Sep 30, 2014
1 parent 60669bd commit 04b60ca
Show file tree
Hide file tree
Showing 59 changed files with 97 additions and 10 deletions.
1 change: 1 addition & 0 deletions add.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
} else {
show_error($config['msg']['notadmin']);
}
log_timing();
1 change: 1 addition & 0 deletions ajax/add_book_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
}

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><result ok="'.$result.'"/>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/anaphora.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
$res['error'] = 1;
}

log_timing(true);
die(json_encode($res));
1 change: 1 addition & 0 deletions ajax/annot.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
catch (Exception $e) {
$result = 0;
}
log_timing(true);
echo '<result ok="'.$result.'"/>';
?>
1 change: 1 addition & 0 deletions ajax/bind_book.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
catch (Exception $e) {
echo '<result ok="0"/>';
}
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/clck_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
}

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><result ok="'.$result.'"/>';
log_timing(true);
1 change: 1 addition & 0 deletions ajax/dict_pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
}

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><result ok="'.(int)$res.'"/>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/dict_reload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
echo '</tfr>';
}
echo '</response>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/dict_substring_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
foreach ($res as $line) {
echo $line['lemma_text'] . '|' . $line['gr'] . '|' . $line['lemma_id'] ."\n";
}
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/download_url.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
catch (Exception $e) {
echo '<response ok="0"/>';
}
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/game_mark_shown.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
}

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><result ok="'.(int)$res.'"/>';
log_timing(true);
1 change: 1 addition & 0 deletions ajax/get_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
recursive_print(0);

echo '</comments>';
log_timing(true);

function recursive_print($id) {
global $comm;
Expand Down
1 change: 1 addition & 0 deletions ajax/get_context.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
}
}
echo '</context>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/lastpar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
$txt .= $r['end'];

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><response num="'.$num.'">'.htmlspecialchars($txt).'</response>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/lemma_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
echo '<lemma id="'.$r['lemma_id'].'"/>';
}
echo '</lemmata>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/merge_tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
catch (Exception $e) {
echo '<result ok="0"/>';
}
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/ner.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@
$res['error'] = 1;
}

log_timing(true);
die(json_encode($res));
1 change: 1 addition & 0 deletions ajax/own_book.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
catch (Exception $e) {
echo '<result ok="0"/>';
}
log_timing(true);
1 change: 1 addition & 0 deletions ajax/paradigm_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
}
}
echo '</response>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/post_comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
}
catch (Exception $e) {
echo '<response ok="0"/>';
log_timing(true);
}
?>
1 change: 1 addition & 0 deletions ajax/publish_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
echo '<success>' . ($published['success'] ? 'ok' : 'failed') . '</success>';
echo '<output>' . htmlspecialchars($published['output']) . '</output>';
echo '</response>';
log_timing(true);

?>
1 change: 1 addition & 0 deletions ajax/run_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
echo '<success>' . ($result['success'] ? 'ok' : 'failed') . '</success>';
echo '<output>' . htmlspecialchars($result['output']) . '</output>';
echo '</response>';
log_timing(true);

?>
1 change: 1 addition & 0 deletions ajax/run_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
echo '<success>' . ($result['success'] ? 'ok' : 'failed') . '</success>';
echo '<output>' . htmlspecialchars($result['output']) . '</output>';
echo '</response>';
log_timing(true);

?>
1 change: 1 addition & 0 deletions ajax/save_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
$result = 0;
}
echo '<result ok="'.$result.'"/></response>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/select_book.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
}

echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?><response>'.$out.'</response>';
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/set_option.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
$res['error'] = 1;
}

log_timing(true);
die(json_encode($res));
1 change: 1 addition & 0 deletions ajax/syntax_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@
$res['error'] = 1;
}

log_timing(true);
die(json_encode($res));
1 change: 1 addition & 0 deletions ajax/tag_autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
foreach ($res as $line) {
echo $line['tag_name']."\n";
}
log_timing(true);
?>
1 change: 1 addition & 0 deletions ajax/tokenizer_monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
header('Content-Type: application/x-json; charset=utf-8');

echo json_encode(get_monitor_data($_GET['from'], $_GET['until']));
log_timing(true);

?>
1 change: 1 addition & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ function json_encode_readable($arr)
$answer['error'] = 'Unknown action';
}

log_timing();
die(json_encode_readable($answer));
?>
1 change: 1 addition & 0 deletions books.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@
} else {
show_error($config['msg']['notadmin']);
}
log_timing();
?>
1 change: 1 addition & 0 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
$smarty->assign('comments', get_latest_comments($skip));
$smarty->assign('skip', $skip);
$smarty->display('comments.tpl');
log_timing();
?>
1 change: 1 addition & 0 deletions config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ morph_annot_moder_context_size = 4
morph_annot_moder_page_size = 15
morph_annot_timeout = 600
morph_annot_user_context_size = 4
timing_log_threshold = 2
1 change: 1 addition & 0 deletions dict.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@
}
$smarty->display('dict/main.tpl', (int)user_has_permission('perm_dict'));
}
log_timing();
?>
1 change: 1 addition & 0 deletions dict_diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
$set_id = (int)$_GET['set_id'];
$smarty->assign('diff', dict_diff($lemma_id, $set_id));
$smarty->display('dict/diff.tpl');
log_timing();
?>
1 change: 1 addition & 0 deletions dict_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
$smarty->assign('history', dict_history($lemma_id, $skip));
$smarty->assign('skip', $skip);
$smarty->display('dict/history.tpl');
log_timing();
?>
1 change: 1 addition & 0 deletions diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
$rev_id = isset($_GET['rev_id']) ? (int)$_GET['rev_id'] : 0;
$smarty->assign('diff', main_diff($sent_id, $set_id, $rev_id));
$smarty->display('diff.tpl');
log_timing();
?>
1 change: 1 addition & 0 deletions game_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
$smarty->assign('badges', get_badges_info());
$smarty->display('game_admin.tpl');
}
log_timing();
?>
1 change: 1 addition & 0 deletions generator_cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
else {
show_error($config['msg']['notadmin']);
}
log_timing();
?>
1 change: 1 addition & 0 deletions history.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
$smarty->assign('maa', $maa);
}
$smarty->display('history.tpl', $cache_id);
log_timing();
?>
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@
}
$smarty->display('index.tpl');
}
log_timing();
?>
24 changes: 14 additions & 10 deletions lib/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ function sql_query($q, $debug=1, $override_readonly=0) {
if (file_exists('/var/lock/oc_readonly.lock') && stripos(trim($q), 'select') > 1 && !$override_readonly)
throw new Exception("Database in readonly mode");
$debug = isset($_SESSION['debug_mode']) && $debug;
$time_start = microtime(true);
if ($debug) {
$time_start = microtime(true);
$q = str_ireplace('select ', 'SELECT SQL_NO_CACHE ', $q);
}

try {
if ($debug)
printf("<table class='debug' width='100%%'><tr><td valign='top' width='20'>%d<td>SQL: %s</td>", $total_queries, htmlspecialchars($q));
$res = $pdo_db->query($q);
$time = microtime(true)-$time_start;
$total_time += $time;
$total_queries++;
if ($debug) {
$time = microtime(true)-$time_start;
$total_time += $time;
$total_queries++;
printf("<td width='100'>%.4f сек.</td><td width='100'>%.4f сек.</td></tr></table>\n", $time, $total_time);
}
}
Expand All @@ -80,11 +80,16 @@ function sql_insert_id() {
}
function sql_prepare($q) {
global $pdo_db;
global $total_time;
$debug = isset($_SESSION['debug_mode']);
$time_start = microtime(true);
if ($debug)
printf("<table class='debug' width='100%%'><tr><td valign='top' width='20'>*</td><td colspan='3'>PREPARE: %s</td></tr></table>\n", htmlspecialchars($q));
try {
return $pdo_db->prepare($q);
$q = $pdo_db->prepare($q);
$time = microtime(true)-$time_start;
$total_time += $time;
return $q;
}
catch (PDOException $e) {
if ($debug)
Expand All @@ -97,15 +102,14 @@ function sql_execute($res, $params) {
global $total_time;
global $total_queries;
$debug = isset($_SESSION['debug_mode']);
if ($debug)
$time_start = microtime(true);
$time_start = microtime(true);

try {
$res->execute($params);
$time = microtime(true)-$time_start;
$total_time += $time;
$total_queries++;
if ($debug) {
$time = microtime(true)-$time_start;
$total_time += $time;
$total_queries++;
printf("<table class='debug' width='100%%'><tr><td valign='top' width='20'>%d<td>SQL: %s</td><td width='100'>%.4f сек.</td><td width='100'>%.4f сек.</td></tr></table>\n", $total_queries, "(prepared statement)", $time, $total_time);
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_once('vendor/autoload.php'); // Smarty, something else which was installed via Composer
require_once('common.php');
require_once('lib_awards.php');
require_once('timer.php');

$smarty = new Smarty(); // no need to require the Smarty.php, it was autoloaded
$smarty->template_dir = $config['smarty']['template_dir'];
Expand Down
1 change: 1 addition & 0 deletions lib/header_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$config = parse_ini_file(__DIR__ . '/../config.ini', true);

require_once('common.php');
require_once('timer.php');

$transaction_counter = 0;
$nested_transaction_counter = 0;
Expand Down
5 changes: 5 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
} else {
header('Location:login.php?act=error');
}
log_timing();
exit();
case 'login_openid':
$r = user_login_openid($_POST['token']);
Expand All @@ -36,9 +37,11 @@
default:
header('Location:login.php?act=error');
}
log_timing();
exit();
case 'login_openid2':
user_login_openid_agree(isset($_POST['agree']));
log_timing();
header('Location:index.php');
exit();
case 'logout':
Expand All @@ -48,6 +51,7 @@
} else {
header('Location:index.php');
}
log_timing();
exit();
case 'reg_done':
$reg_status = user_register($_POST);
Expand All @@ -71,6 +75,7 @@
$smarty->assign('change_status', user_change_shown_name($_POST['shown_name']));
break;
}
log_timing();

if (
isset($_SERVER['HTTP_REFERER']) &&
Expand Down
1 change: 1 addition & 0 deletions manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
$smarty->assign('content', get_wiki_page("Инструкция по интерфейсу для снятия омонимии"));

$smarty->display('static/doc/annotation.tpl');
log_timing();
?>
22 changes: 22 additions & 0 deletions migrations/20140930101915_add_timer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddTimer extends AbstractMigration
{
public function up()
{
$this->execute("CREATE TABLE timing (
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
`page` VARCHAR(255) NOT NULL,
`total_time` FLOAT NOT NULL,
`is_ajax` TINYINT UNSIGNED NOT NULL
) ENGINE=INNODB");
}

public function down()
{
$this->dropTable("timing");
}
}
1 change: 1 addition & 0 deletions ner.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
$smarty->assign('page', get_books_with_NE());
$smarty->display('ner/main.tpl');
}
log_timing();
Loading

0 comments on commit 04b60ca

Please sign in to comment.