Use milliseconds for time profiling

Instead of seconds, and round the average condition at 1dp instead of 0.
Split from child patch by Dragons flight.

Depends-On: I2d8c8f8278073a9420e3eb373fb89a655925618a
Change-Id: I339aed5f8c1d49714e7927ce49286f9ce6c839f5
This commit is contained in:
Daimona Eaytoy 2019-02-10 13:08:06 +01:00
parent 0b7902fe6e
commit c3db63714e
3 changed files with 12 additions and 17 deletions

View file

@ -594,15 +594,11 @@ class AbuseFilter {
return [ 0, 0, 0, 0 ];
}
// 1000 ms in a sec
$timeProfile = ( $curTotalTime / $curCount ) * 1000;
// Return in ms, rounded to 2dp
$timeProfile = round( $timeProfile, 2 );
// Return in milliseconds, rounded to 2dp
$avgTime = round( $curTotalTime / $curCount, 2 );
$avgCond = round( $curTotalConds / $curCount, 1 );
$condProfile = ( $curTotalConds / $curCount );
$condProfile = round( $condProfile, 0 );
return [ $curCount, $profile['matches'], $timeProfile, $condProfile ];
return [ $curCount, $profile['matches'], $avgTime, $avgCond ];
}
/**
@ -1014,7 +1010,7 @@ class AbuseFilter {
*/
public static function filterProfileKey( $filter ) {
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->makeKey( 'abusefilter-profile', 'v2', $filter );
return $cache->makeKey( 'abusefilter-profile', 'v3', $filter );
}
/**

View file

@ -375,7 +375,7 @@ class AbuseFilterRunner {
$pattern = trim( $row->af_pattern );
$result = AbuseFilter::checkConditions( $pattern, $this->parser, true, $filterName );
$timeTaken = microtime( true ) - $startTime;
$timeTaken = 1000 * ( microtime( true ) - $startTime );
$condsUsed = $this->parser->getCondCount() - $startConds;
$this->profilingData[$filterName] = [
@ -403,9 +403,8 @@ class AbuseFilterRunner {
$this->recordProfilingResult( $filterID, $params['time'], $params['conds'], $params['result'] );
}
$runtime = $params['time'] * 1000;
if ( $runtime > $wgAbuseFilterSlowFilterRuntimeLimit ) {
$this->recordSlowFilter( $filterName, $runtime, $params['conds'], $params['result'] );
if ( $params['time'] > $wgAbuseFilterSlowFilterRuntimeLimit ) {
$this->recordSlowFilter( $filterName, $params['time'], $params['conds'], $params['result'] );
}
}
}
@ -414,7 +413,7 @@ class AbuseFilterRunner {
* Record per-filter profiling data
*
* @param int $filter
* @param float $time
* @param float $time Time taken, in milliseconds
* @param int $conds
* @param bool $matched
*/

View file

@ -1832,7 +1832,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase {
17 => [
'matches' => 1,
'actions' => 6,
'averageConditions' => 4.0
'averageConditions' => 4.3
],
19 => [
'matches' => 1,
@ -1872,7 +1872,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase {
17 => [
'matches' => 1,
'actions' => 6,
'averageConditions' => 4.0
'averageConditions' => 4.3
],
19 => [
'matches' => 1,
@ -1912,7 +1912,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase {
17 => [
'matches' => 1,
'actions' => 6,
'averageConditions' => 4.0
'averageConditions' => 4.3
],
19 => [
'matches' => 1,