Bug 1619362 - Parse MOZ_BASE_PROFILER_STARTUP_DURATION and _INTERVAL. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D64988

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2020-03-17 04:11:20 +00:00
Родитель 93518320ab
Коммит 345b2ee888
7 изменённых файлов: 126 добавлений и 33 удалений

Просмотреть файл

@ -47,8 +47,10 @@
# include "mozilla/Atomics.h"
# include "mozilla/AutoProfilerLabel.h"
# include "mozilla/BaseProfilerDetail.h"
# include "mozilla/DoubleConversion.h"
# include "mozilla/Printf.h"
# include "mozilla/Services.h"
# include "mozilla/Span.h"
# include "mozilla/StackWalk.h"
# include "mozilla/StaticPtr.h"
# include "mozilla/ThreadLocal.h"
@ -2422,35 +2424,36 @@ void profiler_init(void* aStackTop) {
const char* startupDuration = getenv("MOZ_BASE_PROFILER_STARTUP_DURATION");
if (startupDuration && startupDuration[0] != '\0') {
// TODO implement if needed
MOZ_CRASH("MOZ_BASE_PROFILER_STARTUP_DURATION unsupported");
// errno = 0;
// double durationVal = PR_strtod(startupDuration, nullptr);
// if (errno == 0 && durationVal >= 0.0) {
// if (durationVal > 0.0) {
// duration = Some(durationVal);
// }
// LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION = %f", durationVal);
// } else {
// LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION not a valid float: %s",
// startupDuration);
// PrintUsageThenExit(1);
// }
// The duration is a floating point number. Use StringToDouble rather than
// strtod, so that "." is used as the decimal separator regardless of OS
// locale.
auto durationVal = StringToDouble(std::string(startupDuration));
if (durationVal && *durationVal >= 0.0) {
if (*durationVal > 0.0) {
duration = Some(*durationVal);
}
LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION = %f", *durationVal);
} else {
LOG("- MOZ_BASE_PROFILER_STARTUP_DURATION not a valid float: %s",
startupDuration);
PrintUsageThenExit(1);
}
}
const char* startupInterval = getenv("MOZ_BASE_PROFILER_STARTUP_INTERVAL");
if (startupInterval && startupInterval[0] != '\0') {
// TODO implement if needed
MOZ_CRASH("MOZ_BASE_PROFILER_STARTUP_INTERVAL unsupported");
// errno = 0;
// interval = PR_strtod(startupInterval, nullptr);
// if (errno == 0 && interval > 0.0 && interval <= 1000.0) {
// LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL = %f", interval);
// } else {
// LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL not a valid float: %s",
// startupInterval);
// PrintUsageThenExit(1);
// }
// The interval is a floating point number. Use StringToDouble rather than
// strtod, so that "." is used as the decimal separator regardless of OS
// locale.
auto intervalValue = StringToDouble(MakeStringSpan(startupInterval));
if (intervalValue && *intervalValue > 0.0 && *intervalValue <= 1000.0) {
interval = *intervalValue;
LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL = %f", interval);
} else {
LOG("- MOZ_BASE_PROFILER_STARTUP_INTERVAL not a valid float: %s",
startupInterval);
PrintUsageThenExit(1);
}
}
features |= StartupExtraDefaultFeatures() & AvailableFeatures();

Просмотреть файл

@ -30,6 +30,7 @@
#include "Decimal.h"
#include "moz-decimal-utils.h"
#include "DoubleConversion.h"
using namespace moz_decimal_utils;
@ -1048,3 +1049,15 @@ Decimal Decimal::zero(Sign sign)
}
} // namespace blink
// Implementation of DoubleConversion.h:
namespace mozilla {
Maybe<double> StringToDouble(Span<const char> aStringSpan) {
bool valid = false;
double result = mozToDouble(aStringSpan, &valid);
return valid ? Some(result) : Nothing();
}
}

Просмотреть файл

@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* A utility function that converts a string to a double independent of OS locale. */
#ifndef MOZILLA_DOUBLECONVERSION_H
#define MOZILLA_DOUBLECONVERSION_H
#include "mozilla/Maybe.h"
#include "mozilla/Span.h"
#include <string>
namespace mozilla {
// Parses aStringSpan into a double floating point value. Always treats . as the
// decimal separator, regardless of OS locale. Consumes the entire string;
// trailing garbage is invalid. Returns Nothing() for invalid input.
// The implementation uses double_conversion::StringToDoubleConverter with
// NO_FLAGS, see double-conversion/string-to-double.h for more documentation.
Maybe<double> StringToDouble(Span<const char> aStringSpan);
}
#endif // MOZILLA_DOUBLECONVERSION_H

Просмотреть файл

@ -0,0 +1,42 @@
diff --git a/mozglue/misc/decimal/Decimal.cpp b/mozglue/misc/decimal/Decimal.cpp
--- a/mozglue/misc/decimal/Decimal.cpp
+++ b/mozglue/misc/decimal/Decimal.cpp
@@ -25,16 +25,17 @@
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Decimal.h"
#include "moz-decimal-utils.h"
+#include "DoubleConversion.h"
using namespace moz_decimal_utils;
#include <algorithm>
#include <float.h>
namespace blink {
@@ -1043,8 +1044,20 @@ bool Decimal::toString(char* strBuf, siz
}
Decimal Decimal::zero(Sign sign)
{
return Decimal(EncodedData(sign, EncodedData::ClassZero));
}
} // namespace blink
+
+// Implementation of DoubleConversion.h:
+
+namespace mozilla {
+
+Maybe<double> StringToDouble(Span<const char> aStringSpan) {
+ bool valid = false;
+ double result = mozToDouble(aStringSpan, &valid);
+ return valid ? Some(result) : Nothing();
+}
+
+}

Просмотреть файл

@ -14,6 +14,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/Casting.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/Span.h"
#include <cmath>
#include <cstring>
@ -42,18 +43,22 @@
typedef std::string String;
double mozToDouble(const String &aStr, bool *valid) {
double mozToDouble(mozilla::Span<const char> aStr, bool *valid) {
double_conversion::StringToDoubleConverter converter(
double_conversion::StringToDoubleConverter::NO_FLAGS,
mozilla::UnspecifiedNaN<double>(), mozilla::UnspecifiedNaN<double>(), nullptr, nullptr);
const char* str = aStr.c_str();
int length = mozilla::AssertedCast<int>(strlen(str));
const char* str = aStr.Elements();
int length = mozilla::AssertedCast<int>(aStr.Length());
int processed_char_count; // unused - NO_FLAGS requires the whole string to parse
double result = converter.StringToDouble(str, length, &processed_char_count);
*valid = mozilla::IsFinite(result);
return result;
}
double mozToDouble(const String &aStr, bool *valid) {
return mozToDouble(mozilla::MakeStringSpan(aStr.c_str()), valid);
}
String mozToString(double aNum) {
char buffer[64];
int buffer_length = mozilla::ArrayLength(buffer);

Просмотреть файл

@ -35,6 +35,7 @@ if [ $# -eq 1 ]; then
cp "$P" .
done
else
#LATEST_SHA=$(cat UPSTREAM-GIT-SHA)
LATEST_SHA=$(git ls-remote https://chromium.googlesource.com/chromium/src.git/ | awk "/refs\/heads\/master/ {print \$1}")
REPO_PATH="https://chromium.googlesource.com/chromium/src.git/+/$LATEST_SHA/third_party/WebKit/Source/platform"
#REPO_PATH="https://github.com/WebKit/webkit/tree/master/Source/WebCore/platform"
@ -49,10 +50,11 @@ fi
# Apply patches:
patch -p3 < zero-serialization.patch
patch -p3 < comparison-with-nan.patch
patch -p3 < mfbt-abi-markers.patch
patch -p3 < to-moz-dependencies.patch
patch -p4 < zero-serialization.patch
patch -p4 < comparison-with-nan.patch
patch -p4 < mfbt-abi-markers.patch
patch -p4 < to-moz-dependencies.patch
patch -p4 < add-doubleconversion-impl.patch
# The following is disabled. See
# https://bugzilla.mozilla.org/show_bug.cgi?id=1208357#c7
#patch -p3 < fix-wshadow-warnings.patch
#patch -p4 < fix-wshadow-warnings.patch

Просмотреть файл

@ -9,6 +9,7 @@ FINAL_LIBRARY = 'mozglue'
EXPORTS.mozilla += [
'AutoProfilerLabel.h',
'decimal/Decimal.h',
'decimal/DoubleConversion.h',
'PlatformConditionVariable.h',
'PlatformMutex.h',
'Printf.h',