Revert "Removed filter profiling using $wgMemc"

This reverts commit afb78deb84.

I'll guard this behind a global and fix up the localisation messages
in a separate commit. This is a straight revert.

Bug: T132189
Change-Id: Iff4aa6d7d543db8f47c5f81f3c206dafcd5373dc
This commit is contained in:
Bartosz Dziewoński 2016-04-08 15:51:54 +02:00
parent 3d9c10d314
commit b60829a60c
4 changed files with 74 additions and 4 deletions

View file

@ -554,12 +554,79 @@ class AbuseFilter {
$timeTaken = $endTime - $startTime;
$condsUsed = $endConds - $startConds;
// @TODO: log slow/complex filters
self::recordProfilingResult( $row->af_id, $timeTaken, $condsUsed );
}
return $result;
}
/**
* @param $filter
*/
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 );
}
/**
* @param $filter
* @param $time
* @param $conds
*/
public static function recordProfilingResult( $filter, $time, $conds ) {
global $wgMemc;
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
$totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
$totalCondKey = wfMemcKey( 'abusefilter', 'profile-conds', 'total' );
$curCount = $wgMemc->get( $countKey );
$curTotal = $wgMemc->get( $totalKey );
$curTotalConds = $wgMemc->get( $totalCondKey );
if ( $curCount ) {
$wgMemc->set( $totalCondKey, $curTotalConds + $conds, 3600 );
$wgMemc->set( $totalKey, $curTotal + $time, 3600 );
$wgMemc->incr( $countKey );
} else {
$wgMemc->set( $countKey, 1, 3600 );
$wgMemc->set( $totalKey, $time, 3600 );
$wgMemc->set( $totalCondKey, $conds, 3600 );
}
}
/**
* @param $filter
* @return array
*/
public static function getFilterProfile( $filter ) {
global $wgMemc;
$countKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'count' );
$totalKey = wfMemcKey( 'abusefilter', 'profile', $filter, 'total' );
$totalCondKey = wfMemcKey( 'abusefilter', 'profile-conds', 'total' );
$curCount = $wgMemc->get( $countKey );
$curTotal = $wgMemc->get( $totalKey );
$curTotalConds = $wgMemc->get( $totalCondKey );
if ( !$curCount ) {
return array( 0, 0 );
}
$timeProfile = ( $curTotal / $curCount ) * 1000; // 1000 ms in a sec
$timeProfile = round( $timeProfile, 2 ); // Return in ms, rounded to 2dp
$condProfile = ( $curTotalConds / $curCount );
$condProfile = round( $condProfile, 0 );
return array( $timeProfile, $condProfile );
}
/**
* Utility function to decode global-$index to $index. Returns false if not global
*

View file

@ -257,6 +257,8 @@ class AbuseFilterViewEdit extends AbuseFilterView {
ChangeTags::purgeTagCacheAll();
}
AbuseFilter::resetFilterProfile( $new_id );
$out->redirect(
$this->getTitle()->getLocalURL(
array(
@ -391,9 +393,10 @@ class AbuseFilterViewEdit extends AbuseFilterView {
if ( $total > 0 ) {
$matches_percent = sprintf( '%.2f', 100 * $matches_count / $total );
list( $timeProfile, $condProfile ) = AbuseFilter::getFilterProfile( $filter );
$fields['abusefilter-edit-status-label'] = $this->msg( 'abusefilter-edit-status' )
->numParams( $total, $matches_count, $matches_percent )
->numParams( $total, $matches_count, $matches_percent, $timeProfile, $condProfile )
->escaped();
}
}

2
i18n/en.json Executable file → Normal file
View file

@ -127,7 +127,7 @@
"abusefilter-edit-subtitle-new": "Creating filter",
"abusefilter-edit-oldwarning": "<strong>You are editing an old version of this filter.\nThe statistics quoted are for the most recent version of the filter.\nIf you save your changes, you will overwrite all changes since the revision you are editing.</strong> &bull;\n[[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%).\nOn average, its run time is $4 ms, and it consumes $5 {{PLURAL:$5|condition|conditions}} of the condition limit.",
"abusefilter-edit-throttled": "'''Warning:''' This filter was automatically disabled as a safety measure.\nIt reached the limit of matching more than $1% of actions.",
"abusefilter-edit-new": "New filter",
"abusefilter-edit-save": "Save filter",

View file

@ -157,7 +157,7 @@
"abusefilter-edit-subtitle-new": "Page subtitle when creating an abuse filter. Parameters:\n* $1 - (Unused) filter ID\n* $2 - (Unused) history ID\nSee also:\n* {{msg-mw|Abusefilter-edit-subtitle}} - if editing the existing filter",
"abusefilter-edit-oldwarning": "Warning displayed when editing an older version of a filter. Parameters:\n* $1 - (Unused) history ID\n* $2 - filter ID",
"abusefilter-edit-status-label": "Field label for abuse filter statistics.\n{{Identical|Statistics}}",
"abusefilter-edit-status": "Parameters:\n* $1 - number of actions\n* $2 - matched count\n* $3 - matched percentage",
"abusefilter-edit-status": "Parameters:\n* $1 - number of actions\n* $2 - matched count\n* $3 - matched percentage\n* $4 - time (in milliseconds)\n* $5 - number of conditions",
"abusefilter-edit-throttled": "Used as warning message. Parameters:\n* $1 - threshold percentage",
"abusefilter-edit-new": "Field value in case an edited filter is new.",
"abusefilter-edit-save": "Submit button text to save a filter.",