Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
91fac199
Commit
91fac199
authored
Apr 03, 2007
by
Penny Leach
Browse files
differentiate between db reads and db writes, fixed a few small bugs
in perf
parent
5bebdc73
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/lang/en.utf8/performance.php
View file @
91fac199
...
...
@@ -31,6 +31,8 @@ $string['timeused'] = 'Execution time';
$string
[
'seconds'
]
=
'seconds'
;
$string
[
'included'
]
=
'Included files'
;
$string
[
'dbqueries'
]
=
'DB queries'
;
$string
[
'reads'
]
=
'reads'
;
$string
[
'writes'
]
=
'writes'
;
$string
[
'ticks'
]
=
'ticks'
;
$string
[
'sys'
]
=
'sys'
;
$string
[
'user'
]
=
'user'
;
...
...
htdocs/lib/dml.php
View file @
91fac199
...
...
@@ -51,7 +51,13 @@ function execute_sql($command) {
try
{
$result
=
$db
->
Execute
(
$command
);
increment_perf_db
();
// searching for these rather than just select as subqueries may have select in them.
if
(
preg_match
(
'/(update|insert|delete|alter|create)/i'
,
$command
))
{
increment_perf_db_writes
();
}
else
{
increment_perf_db_reads
();
}
}
catch
(
ADODB_Exception
$e
)
{
log_debug
(
$e
->
getMessage
()
.
"Command was:
$command
"
);
...
...
@@ -366,10 +372,10 @@ function get_recordset_sql($sql, $values=null, $limitfrom=null, $limitnum=null)
if
(
!
empty
(
$values
)
&&
is_array
(
$values
)
&&
count
(
$values
)
>
0
)
{
$stmt
=
$db
->
Prepare
(
$sql
);
$rs
=
$db
->
Execute
(
$stmt
,
$values
);
increment_perf_db
();
increment_perf_db
_reads
();
}
else
{
$rs
=
$db
->
Execute
(
$sql
);
increment_perf_db
();
increment_perf_db
_reads
();
}
}
}
...
...
@@ -775,7 +781,7 @@ function set_field_select($table, $newfield, $newvalue, $select, $values) {
$sql
=
'UPDATE '
.
get_config
(
'dbprefix'
)
.
$table
.
' SET '
.
$newfield
.
' = ? '
.
$select
;
try
{
$stmt
=
$db
->
Prepare
(
$sql
);
increment_perf_db
();
increment_perf_db
_writes
();
return
$db
->
Execute
(
$stmt
,
$values
);
}
catch
(
ADODB_Exception
$e
)
{
...
...
@@ -811,7 +817,7 @@ function delete_records($table, $field1=null, $value1=null, $field2=null, $value
$sql
=
'DELETE FROM '
.
get_config
(
'dbprefix'
)
.
$table
.
' '
.
$select
;
try
{
$stmt
=
$db
->
Prepare
(
$sql
);
increment_perf_db
();
increment_perf_db
_writes
();
return
$db
->
Execute
(
$stmt
,
$values
);
}
catch
(
ADODB_Exception
$e
)
{
...
...
@@ -842,10 +848,10 @@ function delete_records_sql($sql, $values=null) {
$result
=
false
;
if
(
!
empty
(
$values
)
&&
is_array
(
$values
)
&&
count
(
$values
)
>
0
)
{
$stmt
=
$db
->
Prepare
(
$sql
);
increment_perf_db
();
increment_perf_db
_writes
();
$result
=
$db
->
Execute
(
$stmt
,
$values
);
}
else
{
increment_perf_db
();
increment_perf_db
_writes
();
$result
=
$db
->
Execute
(
$sql
);
}
}
...
...
@@ -925,7 +931,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
// Run the SQL statement
try
{
$stmt
=
$db
->
Prepare
(
$insertSQL
);
increment_perf_db
();
increment_perf_db
_writes
();
$rs
=
$db
->
Execute
(
$stmt
,
$ddd
);
}
catch
(
ADODB_Exception
$e
)
{
...
...
@@ -952,7 +958,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
// try to get the primary key based on id
try
{
$oidsql
=
'SELECT '
.
$primarykey
.
' FROM '
.
get_config
(
'dbprefix'
)
.
$table
.
' WHERE oid = '
.
$id
;
increment_perf_db
();
increment_perf_db
_reads
();
$rs
=
$db
->
Execute
(
$oidsql
);
if
(
$rs
->
RecordCount
()
==
1
)
{
return
(
integer
)
$rs
->
fields
[
0
];
...
...
@@ -1081,7 +1087,7 @@ function update_record($table, $dataobject, $where=null) {
$sql
=
'UPDATE '
.
get_config
(
'dbprefix'
)
.
$table
.
' SET '
.
$update
.
' WHERE '
.
$whereclause
;
try
{
$stmt
=
$db
->
Prepare
(
$sql
);
increment_perf_db
();
increment_perf_db
_writes
();
$rs
=
$db
->
Execute
(
$stmt
,
array_merge
(
$values
,
$wherevalues
));
return
true
;
}
...
...
@@ -1178,7 +1184,7 @@ function where_values_prepared($value1=null, $value2=null, $value3=null, $value4
function
column_type
(
$table
,
$column
)
{
global
$db
;
increment_perf_db
();
increment_perf_db
_reads
();
if
(
!
$rs
=
$db
->
Execute
(
'SELECT '
.
$column
.
' FROM '
.
get_config
(
'dbprefix'
)
.
$table
.
' WHERE 1=2'
))
{
return
false
;
}
...
...
@@ -1280,7 +1286,7 @@ function db_format_tsfield($field, $as = null) {
function
configure_dbconnection
()
{
global
$db
;
increment_perf_db
();
increment_perf_db
_writes
();
$db
->
Execute
(
"SET NAMES 'utf8'"
);
// more later..
...
...
@@ -1370,12 +1376,19 @@ function create_sql_exception_message($e, $sql, $values) {
return
$message
;
}
function
increment_perf_db
()
{
function
increment_perf_db
_reads
()
{
if
(
!
get_config
(
'perftolog'
)
&&
!
get_config
(
'perftofoot'
))
{
return
true
;
}
global
$PERF
;
$PERF
->
db
querie
s
++
;
$PERF
->
db
read
s
++
;
}
function
increment_perf_db_writes
()
{
if
(
!
get_config
(
'perftolog'
)
&&
!
get_config
(
'perftofoot'
))
{
return
true
;
}
global
$PERF
;
$PERF
->
dbwrites
++
;
}
?>
htdocs/lib/mahara.php
View file @
91fac199
...
...
@@ -1476,8 +1476,13 @@ function get_performance_info() {
$inc
=
get_included_files
();
$info
[
'includecount'
]
=
count
(
$inc
);
if
(
!
empty
(
$PERF
->
dbqueries
))
{
$info
[
'dbqueries'
]
=
$PERF
->
dbqueries
;
if
(
!
empty
(
$PERF
->
dbreads
))
{
$info
[
'dbreads'
]
=
$PERF
->
dbreads
;
}
if
(
!
empty
(
$PERF
->
dbwrites
))
{
$info
[
'dbwrites'
]
=
$PERF
->
dbwrites
;
}
if
(
function_exists
(
'posix_times'
))
{
...
...
htdocs/theme/default/templates/performancefooter.tpl
View file @
91fac199
...
...
@@ -8,12 +8,12 @@
{
if
$perf_includecount
}
<span
class=
"included"
>
{
str
tag
=
"included"
section
=
"performance"
}
:
{
$perf_includecount
}
</span><br
/>
{/
if
}
{
if
$perf_db
que
ries
}
<span
class=
"dbqueries"
>
{
str
tag
=
"dbqueries"
section
=
"performance"
}
:
{
$perf_db
queries
}
</span><br
/>
{
if
$perf_db
reads
||
$perf_dbw
ri
t
es
}
<span
class=
"dbqueries"
>
{
str
tag
=
"dbqueries"
section
=
"performance"
}
:
{
$perf_db
reads
}
{
str
tag
=
'reads'
section
=
'performance'
}
,
{
$perf_dbwrites
}
{
str
tag
=
'writes'
section
=
'performance'
}
</span><br
/>
{/
if
}
{
if
$perf_ticks
}
<span
class=
"posixtimes"
>
{
str
tag
=
"ticks"
section
=
"performance"
}
:
{
$perf_ticks
}
{
str
tag
=
"user"
section
=
"performance"
}
:
{
$perf_u
ser
}
{
str
tag
=
"sys"
section
=
"performance"
}
:
{
$perf_s
ys
}
{
str
tag
=
"cuser"
section
=
"performance"
}
:
{
$perf_cutime
}
<span
class=
"posixtimes"
>
{
str
tag
=
"ticks"
section
=
"performance"
}
:
{
$perf_ticks
}
{
str
tag
=
"user"
section
=
"performance"
}
:
{
$perf_u
time
}
{
str
tag
=
"sys"
section
=
"performance"
}
:
{
$perf_s
time
}
{
str
tag
=
"cuser"
section
=
"performance"
}
:
{
$perf_cutime
}
{
str
tag
=
"csys"
section
=
"performance"
}
:
{
$perf_cstime
}
</span><br
/>
{/
if
}
{
if
$perf_serverload
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment