pluf2

pluf2 Commit Details


Date:2010-02-17 14:28:37 (14 years 10 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:dcc03b431a4bf060edafaf129c5ccdd6d3aee234
Parents: e24114fca6452b3cfb832a2bb0f43a15c082d63d
Message:Added a DB wrapper generating statistics.

Changes:

File differences

src/Pluf/DB/Stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2010 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Database statistics class.
*
* This class is just a wrapper which will pass the queries to the
* underlying database class but keeping timing information. This is
* very good to track your slow queries and improve your code.
*
*/
class Pluf_DB_Stats
{
/**
* The real database connection.
*/
protected $_rdb = null;
public function __construct($db)
{
$this->_rdb = $db;
}
public function __call($name, $args)
{
if (!in_array($name, array('execute', 'select'))) {
return call_user_func_array(array($this->_rdb, $name), $args);
}
Pluf_Log::stime('timer');
$res = call_user_func_array(array($this->_rdb, $name), $args);
Pluf_Log::perf(array('Pluf_DB_Stats', $this->_rdb->lastquery, Pluf_Log::etime('timer', 'total_sql')));
Pluf_Log::inc('sql_query');
return $res;
}
public function __get($name)
{
return $this->_rdb->$name;
}
public function __set($name, $value)
{
return $this->_rdb->$name = $value;
}
}
function Pluf_DB_Stats_getConnection($extra=null)
{
if (isset($GLOBALS['_PX_db']) &&
(is_resource($GLOBALS['_PX_db']->con_id) or is_object($GLOBALS['_PX_db']->con_id))) {
return $GLOBALS['_PX_db'];
}
$GLOBALS['_PX_db'] = new Pluf_DB_Stats(
Pluf_DB::get(Pluf::f('db_engine'),
Pluf::f('db_server'),
Pluf::f('db_database'),
Pluf::f('db_login'),
Pluf::f('db_password'),
Pluf::f('db_table_prefix'),
Pluf::f('debug'),
Pluf::f('db_version'))
);
return $GLOBALS['_PX_db'];
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05495s using 13 queries.