$dom = is_null($fqdn) ? $globals->mail->domain : $fqdn;
$url = "http://$uid:$pass@{$globals->lists->rpchost}:{$globals->lists->rpcport}/$dom";
parent::__construct($url);
+ if ($globals->debug & 1) {
+ $this->bt = new PlBacktrace('MMList');
+ }
}
function __call($method, $args)
}
if ($globals->debug & 1) {
- $this->assign('db_trace', XDB::trace_format($this, 'skin/common.database-debug.tpl'));
+ PlBacktrace::clean();
+ $this->assign_by_ref('backtraces', PlBacktrace::$bt);
}
$this->assign('validate', true);
error_reporting(0);
$result = $this->fetch($skin);
- $ttime = sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
+ $ttime = sprintf('Temps total: %.02fs<br />', microtime(true) - $TIME_BEGIN);
$replc = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
if ($globals->debug & 2) {
-
$fd = fopen($this->compile_dir."/valid.html","w");
fwrite($fd, $result);
fclose($fd);
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2007 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+/** Ligth debugging tool to generate execution backtrace
+ */
+class PlBacktrace
+{
+ static public $bt = array();
+
+ public $traces = array();
+ public $totaltime = 0.0;
+ public $error = false;
+
+ function __construct($name, array $init = array(), $sizef = 'rows', $timef = 'exectime', $errorf = 'error')
+ {
+ PlBacktrace::$bt[$name] = $this;
+ foreach ($init as &$entry) {
+ $this->add($entry, $sizef, $timef, $errorf);
+ }
+ }
+
+ private function add(array &$entry, $sizef = 'rows', $timef = 'exectime', $errorf = 'error')
+ {
+ $trace = array();
+ $trace['action'] = $entry['action'];
+ unset($entry['action']);
+ $trace['exectime'] = @$entry[$timef];
+ $this->totaltime += $trace['exectime'];
+ unset($entry[$timef]);
+ $trace['rows'] = @$entry[$sizef];
+ unset($entry[$sizef]);
+ $trace['error'] = @$entry[$errorf];
+ unset($entry[$errorf]);
+ if ($trace['error']) {
+ $this->error = true;
+ }
+ $trace['data'] = array($entry);
+ $this->traces[] =& $trace;
+ }
+
+ public function newEvent($action, $rows = 0, $error = null, array $userdata = array())
+ {
+ $trace = array('action' => $action, 'time' => 0);
+ $this->traces[] =& $trace;
+ $this->update($rows, $error, $userdata);
+ }
+
+ public function start($action)
+ {
+ $trace = array('action' => $action, 'starttime' => microtime(true));
+ $this->traces[] =& $trace;
+ }
+
+ public function stop($rows = 0, $error = null, array $userdata = array())
+ {
+ $time = microtime(true);
+ if (!$this->traces) {
+ return;
+ }
+ $trace =& $this->traces[count($this->traces) - 1];
+ $trace['time'] = $time - $trace['starttime'];
+ unset($trace['starttime']);
+ $this->totaltime += $trace['time'];
+ $this->update($rows, $error, $userdata);
+ }
+
+ public function update($rows = 0, $error = null, array $userdata = array())
+ {
+ $trace =& $this->traces[count($this->traces) - 1];
+ $trace['rows'] = $rows;
+ $trace['error'] = $error;
+ $trace['data'] = $userdata;
+ if ($trace['error']) {
+ $this->error = true;
+ }
+ }
+
+ public static function clean()
+ {
+ foreach (PlBacktrace::$bt as $name=>&$entry) {
+ if (!$entry->traces) {
+ unset(PlBacktrace::$bt[$name]);
+ }
+ }
+ }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
{
global $globals;
XDB::$mysqli = new mysqli($globals->dbhost, $globals->dbuser, $globals->dbpwd, $globals->dbdb);
- if (mysqli_connect_errno() && $globals->debug & 1) {
- $GLOBALS['XDB::trace_data'][] = array('query' => 'MySQLI connection', 'explain' => array(),
- 'error' => mysqli_connect_error(), 'exectime' => 0, 'rows' => 0);
- $GLOBALS['XDB::error'] = true;
- return false;
+ if ($globals->debug & 1) {
+ $bt = new PlBacktrace('MySQL');
+ if (mysqli_connect_errno()) {
+ $bt->newEvent("MySQLI connection", 0, mysqli_connect_error());
+ return false;
+ }
}
XDB::$mysqli->autocommit(true);
XDB::$mysqli->set_charset($globals->dbcharset);
$res->free();
}
}
- $trace_data = array('query' => XDB::_reformatQuery($query), 'explain' => $explain);
- $time_start = microtime();
+ PlBacktrace::$bt['MySQL']->start(XDB::_reformatQuery($query));
}
$res = XDB::$mysqli->query($query);
if ($globals->debug & 1) {
- list($ue, $se) = explode(" ", microtime());
- list($us, $ss) = explode(" ", $time_start);
- $time = intval((($ue - $us) + ($se - $ss)) * 1000);
- $trace_data['error'] = XDB::$mysqli->error;
- $trace_data['errno'] = XDB::$mysqli->errno;
- $trace_data['exectime'] = $time;
- $trace_data['rows'] = @$res->num_rows ? $res->num_rows : XDB::$mysqli->affected_rows;
- $GLOBALS['XDB::trace_data'][] = $trace_data;
- if (XDB::$mysqli->errno) {
- $GLOBALS['XDB::error'] = true;
- }
+ PlBacktrace::$bt['MySQL']->stop(@$res->num_rows ? $res->num_rows : XDB::$mysqli->affected_rows,
+ XDB::$mysqli->error,
+ $explain);
}
return $res;
}
public static function errno()
{
- global $globals;
- if ($globals->debug & 1) {
- $count = count($GLOBALS['XDB::trace_data']);
- if (!$count) {
- return 0;
- }
- return $GLOBALS['XDB::trace_data'][$count - 1]['errno'];
- }
return XDB::$mysqli->errno;
}
public static function error()
{
- global $globals;
- if ($globals->debug & 1) {
- $count = count($GLOBALS['XDB::trace_data']);
- if (!$count) {
- return null;
- }
- return $GLOBALS['XDB::trace_data'][$count - 1]['error'];
- }
return XDB::$mysqli->error;
}
die(var_export($var, true).' is not a valid for a database entry');
}
}
-
- public static function trace_format(&$page, $template = 'skin/common.database-debug.tpl') {
- $page->assign('trace_data', @$GLOBALS['XDB::trace_data']);
- $page->assign('db_error', @$GLOBALS['XDB::error']);
- return $page->fetch($template);
- }
}
class XOrgDBResult
{
private $url;
private $urlparts;
+ public $bt = null;
public function __construct($url)
{
public function __call($method, $args)
{
$query = xmlrpc_encode_request($method, $args);
+ if ($this->bt) {
+ $this->bt->start($method . "\n" . var_export($args, true));
+ }
$answer = $this->http_post($query, $this->urlparts);
+ if ($this->bt) {
+ $this->bt->stop();
+ }
$result = $this->find_and_decode_xml($answer);
+ if ($this->bt) {
+ if (isset($result['faultCode'])) {
+ $this->bt->update(0, $result['faultString']);
+ } else {
+ $this->bt->update(count($result));
+ }
+ }
if (is_array($result) && isset($result['faultCode'])) {
trigger_error("Error in xmlrpc call $function\n".
table_prefix = "banana_"
spool_root = "/var/spool/banana"
+mbox_helper = "/usr/bin/banana-mbox-helper"
[Geoloc]
webservice_url = ""
#dev a { text-decoration: none; }
-#db-trace div.hide { display: none; }
-#db-trace:hover div.hide { display: block }
+.backtrace div.hide { display: none; }
+.backtrace:hover div.hide { display: block }
#suid {
color: red;
if (S::has_perms()) {
Banana::$msgshow_mimeparts[] = 'source';
}
+ Banana::$debug_nntp = ($globals->debug & 1);
parent::__construct($params);
}
Banana::$spool_root = $globals->banana->spool_root;
Banana::$spool_boxlist = false;
Banana::$msgedit_canattach = true;
+ Banana::$debug_mbox = ($globals->debug & 1);
+ Banana::$mbox_helper = $globals->banana->mbox_helper;
if (S::has_perms()) {
Banana::$msgshow_mimeparts[] = 'source';
}
{
return ModerationBanana::$domain . '_' . ModerationBanana::$listname;
}
+
+ public function backtrace()
+ {
+ return null;
+ }
}
// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-function microtime_float()
-{
- list($usec, $sec) = explode(' ', microtime());
- return ((float)$usec + (float)$sec);
-}
-$TIME_BEGIN = microtime_float();
+$TIME_BEGIN = microtime(true);
date_default_timezone_set('Europe/Paris');
$page->assign('banana_res', $res);
$page->addCssInline($banana->css());
$page->addCssLink('banana.css');
+ new PlBacktrace('NNTP', $banana->backtrace(), 'response', 'time');
}
}
$page->assign('banana', $banana->run());
$page->addCssInline($banana->css());
$page->addCssLink('banana.css');
+ new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time');
} else {
$page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
}
{**************************************************************************}
-{foreach item=query from=$trace_data}
-{if $query.explain}
-{assign var=cols value=$query.explain[0]|@count}
+{foreach item=query from=$trace->traces}
+{if $query.data}
+{assign var=cols value=$query.data[0]|@count}
{else}
{assign var=cols value=1}
{/if}
<table class="bicol" style="width: 75%; font-size: smaller; margin-left:2px; margin-top: 3px;">
<tr class="impair">
<td colspan="{$cols}">
- <strong>QUERY:</strong>
- <pre style="padding: 0; margin: 0;">{$query.query}</pre>
+ <strong>ACTION:</strong>
+ <pre style="padding: 0; margin: 0;">{$query.action}</pre>
<br/>
</td>
</tr>
<tr>
<td colspan="{$cols}">
<strong>INFO:</strong><br />
- {$query.rows} enregistrement{if $query.rows > 1}s{/if} en {$query.exectime}ms
+ {$query.rows} ligne{if $query.rows > 1}s{/if} en {$query.exectime|string_format:"%.3f"}s
</td>
</tr>
{/if}
-{if $query.explain}
+{if $query.data}
<tr>
- {foreach key=key item=item from=$query.explain[0]}
+ {foreach key=key item=item from=$query.data[0]}
<th style="font-size: smaller">{$key}</th>
{/foreach}
</tr>
- {foreach item=explain_row from=$query.explain}
+ {foreach item=data_row from=$query.data}
<tr class="impair">
- {foreach item=item from=$explain_row}
+ {foreach item=item from=$data_row}
<td class="center" style="font-size: smaller">{$item}</td>
{/foreach}
</tr>
{**************************************************************************}
{if #globals.debug#}
-{if $db_trace && $db_trace neq "\n\n"}
- <div id="db-trace">
+{foreach from=$backtraces key=bt_name item=trace}
+ <div class="backtrace">
<h1>
- {if $db_error}<span style="color: #f00">{/if}
- Trace de l'exécution de cette page sur mysql (hover me)
- {if $db_error}</span>{/if}
+ {if $trace->error}<span style="color: #f00">{/if}
+ Exécution de {$bt_name} en {$trace->totaltime|string_format:"%.3f"}s (hover-me pour la trace)
+ {if $trace->error}</span>{/if}
</h1>
<div class="hide">
- {$db_trace|smarty:nodefaults}
+ {include file="skin/common.backtrace.tpl"}
</div>
</div>
-{/if}
+{/foreach}
{if $validate}
<div id="dev">