Count API module instantiations and Hook runs
authorOri Livneh <ori@wikimedia.org>
Thu, 2 Jul 2015 00:25:24 +0000 (17:25 -0700)
committerOri Livneh <ori@wikimedia.org>
Thu, 2 Jul 2015 23:45:02 +0000 (16:45 -0700)
We previously had counts for hooks and modules as a side-effect of having them
profiled. We removed the profiling for performance reasons, which left us
without counts also. But the performance of counters is not a concern, and
their signal value not insubstantial. So introduce them here.

Fix getModulePath() to not crash while we're at it.

Change-Id: Ic04daf475b936b942833362c7a979dde671b3ef4

includes/Hooks.php
includes/api/ApiMain.php

index 036d65c..28c54d2 100644 (file)
@@ -135,6 +135,7 @@ class Hooks {
         *   returning null) is equivalent to returning true.
         */
        public static function run( $event, array $args = array(), $deprecatedVersion = null ) {
+               RequestContext::getMain()->getStats()->increment( 'hooks.' . $event );
                foreach ( self::getHandlers( $event ) as $hook ) {
                        // Turn non-array values into an array. (Can't use casting because of objects.)
                        if ( !is_array( $hook ) ) {
index f2059d7..fec750f 100644 (file)
@@ -404,6 +404,8 @@ class ApiMain extends ApiBase {
                } else {
                        $this->executeActionWithErrorHandling();
                }
+               $this->getContext()->getStats()->increment(
+                       'api.modules.' . strtr( $this->getModule()->getModulePath(), '+', '.' ) );
        }
 
        /**