gradlew
author Tom Ritter <tom@mozilla.com>
Fri, 12 Jan 2018 13:36:04 -0600
changeset 399590 17bf5819b42fa3b656f2d3c565bc4fb0ca050066
parent 268966 3fa48c9d205bc6628b74caf93716338935b48689
permissions -rwxr-xr-x
Bug 1429764 Do not call ReduceTimerPrecision twice for DOM Navigation timers r=bkelly,timhuang Bug 1429764 details a test failure that was asserting that the performance navigation timers were strictly increasing (or equal). fetchStart should have a timestamp before domainLookupStart. But it didn't. The problem is two-fold. This corrects the test and the issue by addressing one part of the problem, the second part of the problem needs to be written up in a new bug and addressed there. (That bug is not yet filed at writing, but see dependencies of 1429764 in the future to find it.) The second, and underlying, problem is that calling ReduceTimerPrecision with the same value multiple times may continually reduce it. Meaning that the first you call it with, say, .75, (and a precision of .20), it will be reduced to .6. The second time you call it (with .6), instead of staying at .6 it will be reduced to .4. This is because floats are fuzzy. Inside ReduceTimerPrecision we are multiplying a decimal by a decimal, so while floor(.6 / .20) should equal 3, sometimes it's actually 2.999... which gets floors to 2, gets multiplied again by .2, and which results in .4 If that's the underlying problem, the first, and surface, problem is - why are we calling ReduceTimerPrecision multiple times? We shouldn't be. That's what this patch fixes. TimeStampToDOMHighResOrFetchStart will return either TimeStampToDOMHighRes() or FetchStartHighRes(). FetchStartHighRes() internally calls TimeStampToDOMHighRes and then ReduceTimerPrecision - this is where (some of) the two reduction calls happen - because TimeStampToDOMHighRes itself calls ReduceTimerPrecision also. I remove the ReduceTimerPrecision from TimeStampToDOMHighRes. FetchStartHighRes will now only call ReduceTimerPrecision once, at the end of the return. But we have to fix places we call TimeStampToDOMHighResOrFetchStart, because the callers of that function also call ReduceTimerPrecision. So if TimeStampToDOMHighResOrFetchStart returned FetchStartHighRes, we'd be calling ReduceTimerPrecision twice for those callers. So inside first off, we remove the outer call to ReduceTimerPrecision. that surrounds the 5 or so callsites of TimeStampToDOMHighResOrFetchStart. Then inside of TimeStampToDOMHighResOrFetchStart we return either FetchStartHighRes (which is has already called ReduceTimerPrecision) or we call ReduceTimerPrecision with the value. Now. TimeStampToDOMHighRes was used in more places than just FetchStartHighRes - there were several other places where we were doing double rounding, and this fixed those as well. AsyncOpenHighRes, WorkerStartHighRes, DomainLookupEndHighRes, ConnectStartHighRes, SecureConnectionStartHighRes, ConnectEndHighRes, and ResponseEndHighRes. MozReview-Commit-ID: K5nHql135rb

#!/usr/bin/env bash

##############################################################################
##
##  Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
    echo "$*"
}

die ( ) {
    echo
    echo "$*"
    echo
    exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
  CYGWIN* )
    cygwin=true
    ;;
  Darwin* )
    darwin=true
    ;;
  MINGW* )
    msys=true
    ;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`"/$link"
    fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
    MAX_FD_LIMIT=`ulimit -H -n`
    if [ $? -eq 0 ] ; then
        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
            MAX_FD="$MAX_FD_LIMIT"
        fi
        ulimit -n $MAX_FD
        if [ $? -ne 0 ] ; then
            warn "Could not set maximum file descriptor limit: $MAX_FD"
        fi
    else
        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
    fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
    JAVACMD=`cygpath --unix "$JAVACMD"`

    # We build the pattern for arguments to be converted via cygpath
    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
    SEP=""
    for dir in $ROOTDIRSRAW ; do
        ROOTDIRS="$ROOTDIRS$SEP$dir"
        SEP="|"
    done
    OURCYGPATTERN="(^($ROOTDIRS))"
    # Add a user-defined pattern to the cygpath arguments
    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
    fi
    # Now convert the arguments - kludge to limit ourselves to /bin/sh
    i=0
    for arg in "$@" ; do
        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option

        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
        else
            eval `echo args$i`="\"$arg\""
        fi
        i=$((i+1))
    done
    case $i in
        (0) set -- ;;
        (1) set -- "$args0" ;;
        (2) set -- "$args0" "$args1" ;;
        (3) set -- "$args0" "$args1" "$args2" ;;
        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
    esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
    JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"