Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
d63ef701
Commit
d63ef701
authored
Sep 04, 2014
by
Scott Vivian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Point old qa_usage_* functions to new class
parent
02245a28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
180 deletions
+47
-180
qa-base.php
qa-include/qa-base.php
+3
-3
qa-util-debug.php
qa-include/qa-util-debug.php
+44
-177
No files found.
qa-include/qa-base.php
View file @
d63ef701
...
@@ -1484,10 +1484,10 @@
...
@@ -1484,10 +1484,10 @@
return
$options
[
$name
];
return
$options
[
$name
];
}
}
/**
* Simple method to output a preformatted variable
*/
function
qa_debug
(
$var
)
function
qa_debug
(
$var
)
/*
Simple method to output a preformatted variable
*/
{
{
echo
"
\n
"
.
'<pre style="padding: 10px; background-color: #eee; color: #444; font-size: 11px; text-align: left">'
;
echo
"
\n
"
.
'<pre style="padding: 10px; background-color: #eee; color: #444; font-size: 11px; text-align: left">'
;
echo
$var
===
null
?
'NULL'
:
print_r
(
$var
,
true
);
echo
$var
===
null
?
'NULL'
:
print_r
(
$var
,
true
);
...
...
qa-include/qa-util-debug.php
View file @
d63ef701
<?php
<?php
/**
/*
* @deprecated This file is deprecated from Q2A 1.7; use Q2A_Util_Usage class (Q2A/Util/Usage.php) instead.
Question2Answer (c) Gideon Greenspan
*
* The functions in this file are maintained for backwards compatibility, but simply call through to the
http://www.question2answer.org/
* new class where applicable.
*/
File: qa-include/qa-util-debug.php
function
qa_usage_init
()
Version: See define()s at top of qa-include/qa-base.php
{
Description: Debugging stuff, currently used for tracking resource usage
// should already be initialised in qa-base.php
global
$qa_usage
;
if
(
empty
(
$qa_usage
))
This program is free software; you can redistribute it and/or
$qa_usage
=
new
Q2A_Util_Usage
;
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.
function
qa_usage_get
()
{
This program is distributed in the hope that it will be useful,
global
$qa_usage
;
but WITHOUT ANY WARRANTY; without even the implied warranty of
return
$qa_usage
->
getCurrent
();
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
}
GNU General Public License for more details.
function
qa_usage_delta
(
$oldusage
,
$newusage
)
More about this license: http://www.question2answer.org/license.php
{
*/
// equivalent function is now private
return
null
;
function
qa_debug
(
$var
)
}
/*
Simple method to output a preformatted variable
function
qa_usage_mark
(
$stage
)
*/
{
{
global
$qa_usage
;
if
(
$var
===
null
)
return
$qa_usage
->
mark
(
$stage
);
echo
"
\n
NULL
\n
"
;
}
else
{
$css
=
'padding: 10px; background-color: #eee; color: #444; font-size: 11px; text-align: left'
;
function
qa_usage_line
(
$stage
,
$usage
,
$totalusage
)
echo
"
\n
<pre style='
$css
'>"
,
print_r
(
$var
,
true
),
"</pre>
\n
"
;
{
}
// equivalent function is now private
}
return
null
;
}
function
qa_usage_init
()
function
qa_usage_output
()
/*
{
Initialize the counts of resource usage
global
$qa_usage
;
*/
return
$qa_usage
->
output
();
{
}
global
$qa_database_usage
,
$qa_database_queries
,
$qa_usage_start
,
$qa_usage_last
;
$qa_database_usage
=
array
(
'queries'
=>
0
,
'clock'
=>
0
);
$qa_database_queries
=
''
;
$qa_usage_last
=
$qa_usage_start
=
qa_usage_get
();
}
function
qa_usage_get
()
/*
Return an array representing the resource usage as of now
*/
{
global
$qa_database_usage
;
$usage
=
array
(
'files'
=>
count
(
get_included_files
()),
'queries'
=>
$qa_database_usage
[
'queries'
],
'ram'
=>
function_exists
(
'memory_get_usage'
)
?
memory_get_usage
()
:
0
,
'clock'
=>
array_sum
(
explode
(
' '
,
microtime
())),
'mysql'
=>
$qa_database_usage
[
'clock'
],
);
if
(
function_exists
(
'getrusage'
))
{
$rusage
=
getrusage
();
$usage
[
'cpu'
]
=
$rusage
[
"ru_utime.tv_sec"
]
+
$rusage
[
"ru_stime.tv_sec"
]
+
(
$rusage
[
"ru_utime.tv_usec"
]
+
$rusage
[
"ru_stime.tv_usec"
])
/
1000000
;
}
else
$usage
[
'cpu'
]
=
0
;
$usage
[
'other'
]
=
$usage
[
'clock'
]
-
$usage
[
'cpu'
]
-
$usage
[
'mysql'
];
return
$usage
;
}
function
qa_usage_delta
(
$oldusage
,
$newusage
)
/*
Return the difference between two resource usage arrays, as an array
*/
{
$delta
=
array
();
foreach
(
$newusage
as
$key
=>
$value
)
$delta
[
$key
]
=
max
(
0
,
$value
-@
$oldusage
[
$key
]);
return
$delta
;
}
function
qa_usage_mark
(
$stage
)
/*
Mark the beginning of a new stage of script execution and store usages accordingly
*/
{
global
$qa_usage_last
,
$qa_usage_stages
;
$usage
=
qa_usage_get
();
$qa_usage_stages
[
$stage
]
=
qa_usage_delta
(
$qa_usage_last
,
$usage
);
$qa_usage_last
=
$usage
;
}
function
qa_usage_line
(
$stage
,
$usage
,
$totalusage
)
/*
Return HTML to represent the resource $usage, showing appropriate proportions of $totalusage
*/
{
return
sprintf
(
"%s – <b>%.1fms</b> (%d%%) – PHP %.1fms (%d%%), MySQL %.1fms (%d%%), Other %.1fms (%d%%) – %d PHP %s, %d DB %s, %dk RAM (%d%%)"
,
$stage
,
$usage
[
'clock'
]
*
1000
,
$usage
[
'clock'
]
*
100
/
$totalusage
[
'clock'
],
$usage
[
'cpu'
]
*
1000
,
$usage
[
'cpu'
]
*
100
/
$totalusage
[
'clock'
],
$usage
[
'mysql'
]
*
1000
,
$usage
[
'mysql'
]
*
100
/
$totalusage
[
'clock'
],
$usage
[
'other'
]
*
1000
,
$usage
[
'other'
]
*
100
/
$totalusage
[
'clock'
],
$usage
[
'files'
],
(
$usage
[
'files'
]
==
1
)
?
'file'
:
'files'
,
$usage
[
'queries'
],
(
$usage
[
'queries'
]
==
1
)
?
'query'
:
'queries'
,
$usage
[
'ram'
]
/
1024
,
$usage
[
'ram'
]
?
(
$usage
[
'ram'
]
*
100
/
$totalusage
[
'ram'
])
:
0
);
}
function
qa_usage_output
()
/*
Output an (ugly) block of HTML detailing all resource usage and database queries
*/
{
global
$qa_usage_start
,
$qa_usage_stages
,
$qa_database_queries
;
$totaldelta
=
qa_usage_delta
(
$qa_usage_start
,
qa_usage_get
());
?>
<style>
.debug-table
{
border-collapse
:
collapse
;
box-sizing
:
border-box
;
width
:
100%
;
margin
:
20px
auto
;
}
.debug-table
tr
{
background-color
:
#ccc
;
}
.debug-table
td
{
padding
:
10px
;
}
td
.debug-cell-files
{
width
:
30%
;
padding-right
:
5px
;
}
td
.debug-cell-queries
{
width
:
70%
;
padding-left
:
5px
;
}
textarea
.debug-output
{
box-sizing
:
border-box
;
width
:
100%
;
font
:
12px
monospace
;
color
:
#000
;
}
</style>
<table
class=
"debug-table"
>
<tbody>
<tr>
<td
colspan=
"2"
>
<?php
echo
qa_usage_line
(
'Total'
,
$totaldelta
,
$totaldelta
)
.
"<br>
\n
"
;
foreach
(
$qa_usage_stages
as
$stage
=>
$stagedelta
)
echo
'<br>'
.
qa_usage_line
(
ucfirst
(
$stage
),
$stagedelta
,
$totaldelta
)
.
"
\n
"
;
?>
</td>
</tr>
<tr>
<td
class=
"debug-cell-files"
>
<textarea
class=
"debug-output"
cols=
"40"
rows=
"20"
>
<?php
foreach
(
get_included_files
()
as
$file
)
echo
qa_html
(
implode
(
'/'
,
array_slice
(
explode
(
'/'
,
$file
),
-
3
)))
.
"
\n
"
;
?>
</textarea>
</td>
<td
class=
"debug-cell-queries"
>
<textarea
class=
"debug-output"
cols=
"40"
rows=
"20"
>
<?=
qa_html
(
$qa_database_queries
)
?>
</textarea>
</td>
</tr>
</tbody>
</table>
<?php
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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