Time POST requests to API write modules
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 25 Mar 2016 19:13:34 +0000 (12:13 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 31 Mar 2016 10:05:07 +0000 (10:05 +0000)
This lets us capture some basic endpoint timing data that is
lacking now, such as upload API call time.

Change-Id: If0627e2d78d82b22ed6bdaaa0fa7fe5f20ef50b1

includes/api/ApiMain.php

index 1f1a1e8..e372511 100644 (file)
@@ -397,7 +397,13 @@ class ApiMain extends ApiBase {
                if ( $this->mInternalMode ) {
                        $this->executeAction();
                } else {
+                       $start = microtime( true );
                        $this->executeActionWithErrorHandling();
+                       if ( $this->isWriteMode() && $this->getRequest()->wasPosted() ) {
+                               $timeMs = 1000 * max( 0, microtime( true ) - $start );
+                               $this->getStats()->timing(
+                                       'api.' . $this->getModuleName() . '.executeTiming', $timeMs );
+                       }
                }
        }