Revision: 48564
Author: werdna
Date: 2009-03-19 02:40:48 +0000 (Thu, 19 Mar 2009)
Log Message:
-----------
Add basic filter profiling to AbuseFilter -- display on the edit filter page
the average time taken to run the filter. Currently sampling at 1/50
Modified Paths:
--------------
trunk/extensions/AbuseFilter/AbuseFilter.class.php
trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
Modified: trunk/extensions/AbuseFilter/AbuseFilter.class.php
===================================================================
--- trunk/extensions/AbuseFilter/AbuseFilter.class.php 2009-03-19 02:05:58 UTC
(rev 48563)
+++ trunk/extensions/AbuseFilter/AbuseFilter.class.php 2009-03-19 02:40:48 UTC
(rev 48564)
@@ -361,10 +361,16 @@
wfProfileIn( __METHOD__ );
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'abuse_filter', '*', array( 'af_enabled'
=> 1, 'af_deleted' => 0 ) );
+
+ // Sampling profiler
+ $profile = rand(0,50);
+ $profile = ($profile == 1) ? true : false;
$filter_matched = array();
while ( $row = $dbr->fetchObject( $res ) ) {
+ if ($profile)
+ $startTime = microtime(true);
// Store the row somewhere convenient
self::$filters[$row->af_id] = $row;
@@ -377,6 +383,14 @@
// Record non-match.
$filter_matched[$row->af_id] = false;
}
+
+ if ($profile) {
+ $endTime = microtime(true);
+
+ $timeTaken = $endTime - $startTime;
+
+ self::recordProfilingResult( $row->af_id,
$timeTaken );
+ }
}
// Update statistics, and disable filters which are
over-blocking.
@@ -386,6 +400,48 @@
return $filter_matched;
}
+
+ public static function resetFilterProfile( $filter ) {
+ global $wgMemc;
+ $countKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'count' );
+ $totalKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'total' );
+
+ $wgMemc->delete( $countKey );
+ $wgMemc->delete( $totalKey );
+ }
+
+ public static function recordProfilingResult( $filter, $time ) {
+ global $wgMemc;
+
+ $countKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'count' );
+ $totalKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'total' );
+
+ $curCount = $wgMemc->get( $countKey );
+ $curTotal = $wgMemc->get( $totalKey );
+
+ $wgMemc->set( $totalKey, $curTotal + $time, 3600 );
+
+ if ($curCount)
+ $wgMemc->incr( $countKey );
+ else
+ $wgMemc->set( $countKey, 1, 3600 );
+ }
+
+ public static function getFilterProfile( $filter ) {
+ global $wgMemc;
+
+ $countKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'count' );
+ $totalKey = wfMemcKey( 'abusefilter', 'profile', $filter,
'total' );
+
+ $curCount = $wgMemc->get( $countKey );
+ $curTotal = $wgMemc->get( $totalKey );
+
+ if (!$curCount)
+ return 0;
+
+ $profile = ($curTotal / $curCount) * 1000;
+ return round( $profile, 2); // Return in ms, rounded to 2dp
+ }
/** Returns an array [ list of actions taken by filter, error message
to display, if any ] */
public static function executeFilterActions( $filters, $title, $vars ) {
Modified: trunk/extensions/AbuseFilter/AbuseFilter.i18n.php
===================================================================
--- trunk/extensions/AbuseFilter/AbuseFilter.i18n.php 2009-03-19 02:05:58 UTC
(rev 48563)
+++ trunk/extensions/AbuseFilter/AbuseFilter.i18n.php 2009-03-19 02:40:48 UTC
(rev 48564)
@@ -151,7 +151,8 @@
If you save your changes, you will overwrite all changes since the revision
you are editing.</strong> •
[[Special:AbuseFilter/history/$2|Return to this filter's history]].",
'abusefilter-edit-status-label' => 'Statistics:',
- 'abusefilter-edit-status' => 'Of the last $1
{{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).',
+ 'abusefilter-edit-status' => 'Of the last $1
{{PLURAL:$1|action|actions}}, this filter has matched $2 ($3%).
+On average, its run time is $4ms',
'abusefilter-edit-throttled' => "'''Warning''': This filter was
automatically disabled as a safety measure.
It reached the limit of matching more than $1% of actions.",
'abusefilter-edit-new' => 'New filter',
Modified: trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php
===================================================================
--- trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php 2009-03-19
02:05:58 UTC (rev 48563)
+++ trunk/extensions/AbuseFilter/Views/AbuseFilterViewEdit.php 2009-03-19
02:40:48 UTC (rev 48564)
@@ -174,6 +174,8 @@
global $wgMemc;
$wgMemc->delete( wfMemcKey( 'valid-tags' ) );
}
+
+ AbuseFilter::resetFilterProfile( $new_id );
global $wgOut;
@@ -257,11 +259,13 @@
if ($total > 0) {
$matches_percent = sprintf( '%.2f', 100 *
$matches_count / $total );
+ $profile = AbuseFilter::getFilterProfile(
$filter );
$fields['abusefilter-edit-status-label'] =
wfMsgExt( 'abusefilter-edit-status',
array( 'parsemag', 'escape' ),
$wgLang->formatNum($total),
$wgLang->formatNum($matches_count),
-
$wgLang->formatNum($matches_percent)
+
$wgLang->formatNum($matches_percent),
+ $wgLang->formatNum($profile)
);
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs