Profile wfShellExec() calls by caller
authorChad Horohoe <chadh@wikimedia.org>
Wed, 4 Mar 2015 06:23:00 +0000 (22:23 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Wed, 4 Mar 2015 23:04:45 +0000 (15:04 -0800)
Change-Id: Ide437ec586b9e123ca73b5abd17278a72375dfb0

includes/GlobalFunctions.php

index 3f10620..869b7e0 100644 (file)
@@ -2757,6 +2757,8 @@ function wfShellExecDisabled() {
  * @param array $options Array of options:
  *   - duplicateStderr: Set this to true to duplicate stderr to stdout,
  *     including errors from limit.sh
+ *   - profileMethod: By default this function will profile based on the calling
+ *     method. Set this to a string for an alternative method to profile from
  *
  * @return string Collected stdout as a string
  */
@@ -2775,6 +2777,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
        }
 
        $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
+       $profileMethod = isset( $options['profileMethod'] ) ? $options['profileMethod'] : wfGetCaller();
 
        wfInitShellLocale();
 
@@ -2848,6 +2851,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                $desc[3] = array( 'pipe', 'w' );
        }
        $pipes = null;
+       $scoped = Profiler::instance()->scopedProfileIn( __FUNCTION__ . '-' . $profileMethod );
        $proc = proc_open( $cmd, $desc, $pipes );
        if ( !$proc ) {
                wfDebugLog( 'exec', "proc_open() failed: $cmd" );
@@ -2999,7 +3003,8 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
  * @return string Collected stdout and stderr as a string
  */
 function wfShellExecWithStderr( $cmd, &$retval = null, $environ = array(), $limits = array() ) {
-       return wfShellExec( $cmd, $retval, $environ, $limits, array( 'duplicateStderr' => true ) );
+       return wfShellExec( $cmd, $retval, $environ, $limits,
+               array( 'duplicateStderr' => true, 'profileMethod' => wfGetCaller() ) );
 }
 
 /**