Backed out 3 changesets (bug 1205985) for causing xpcshell failures in test_TelemetrySession.js

CLOSED TREE

Backed out changeset f82f5070bee5 (bug 1205985)
Backed out changeset 89b03879ce7d (bug 1205985)
Backed out changeset 9ba60febbcf8 (bug 1205985)
This commit is contained in:
Mihai Alexandru Michis 2021-01-11 13:44:23 +02:00
parent b845a849f8
commit f12a97c159
15 changed files with 31 additions and 349 deletions

View File

@ -10,7 +10,6 @@
#include "mozilla/Atomics.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Uptime.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -37,9 +36,6 @@ struct TimeStampInitialization {
TimeStampInitialization() {
TimeStamp::Startup();
mFirstTimeStamp = TimeStamp::Now();
// On Windows < 10, initializing the uptime requires `mFirstTimeStamp` to be
// valid.
mozilla::InitializeUptime();
};
~TimeStampInitialization() { TimeStamp::Shutdown(); };

View File

@ -24,7 +24,6 @@
#include <unistd.h>
#include "mozilla/TimeStamp.h"
#include "mozilla/Uptime.h"
// Estimate of the smallest duration of time we can measure.
static uint64_t sResolution;

View File

@ -49,7 +49,6 @@
#include "mozilla/Sprintf.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Uptime.h"
#include <pthread.h>
// Estimate of the smallest duration of time we can measure.

View File

@ -10,7 +10,6 @@
#include "mozilla/DynamicallyLinkedFunctionPtr.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/Uptime.h"
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,150 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "Uptime.h"
#ifdef XP_WIN
# include "mozilla/DynamicallyLinkedFunctionPtr.h"
#endif // XP_WIN
#include <stdint.h>
#include <inttypes.h>
#include "mozilla/TimeStamp.h"
#include "mozilla/Maybe.h"
#include "mozilla/Assertions.h"
using namespace mozilla;
namespace {
Maybe<uint64_t> NowIncludingSuspendMs();
Maybe<uint64_t> NowExcludingSuspendMs();
static Maybe<uint64_t> mStartExcludingSuspendMs;
static Maybe<uint64_t> mStartIncludingSuspendMs;
// Apple things
#if defined(__APPLE__) && defined(__MACH__)
# include <time.h>
# include <sys/time.h>
# include <sys/types.h>
# include <mach/mach_time.h>
const uint64_t kNSperMS = 1000000;
Maybe<uint64_t> NowExcludingSuspendMs() {
return Some(clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / kNSperMS);
}
Maybe<uint64_t> NowIncludingSuspendMs() {
return Some(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) / kNSperMS);
}
#endif // macOS
#if defined(XP_WIN)
// Number of hundreds of nanoseconds in a millisecond
static constexpr uint64_t kHNSperMS = 10000;
Maybe<uint64_t> NowExcludingSuspendMs() {
ULONGLONG interrupt_time;
if (!QueryUnbiasedInterruptTime(&interrupt_time)) {
return Nothing();
}
return Some(interrupt_time / kHNSperMS);
}
Maybe<uint64_t> NowIncludingSuspendMs() {
static const mozilla::StaticDynamicallyLinkedFunctionPtr<void(WINAPI*)(
PULONGLONG)>
pQueryInterruptTime(L"KernelBase.dll", "QueryInterruptTime");
if (!pQueryInterruptTime) {
// On Windows, this does include the time the computer was suspended so it's
// an adequate fallback.
TimeStamp processCreation = TimeStamp::ProcessCreation();
TimeStamp now = TimeStamp::Now();
if (!processCreation.IsNull() && !now.IsNull()) {
return Some(uint64_t((now - processCreation).ToMilliseconds()));
} else {
return Nothing();
}
}
ULONGLONG interrupt_time;
pQueryInterruptTime(&interrupt_time);
return Some(interrupt_time / kHNSperMS);
}
#endif // XP_WIN
#if defined(XP_LINUX) // including Android
# include <time.h>
// Number of nanoseconds in a millisecond.
static constexpr uint64_t kNSperMS = 1000000;
uint64_t TimespecToMilliseconds(struct timespec aTs) {
return aTs.tv_sec * 1000 + aTs.tv_nsec / kNSperMS;
}
Maybe<uint64_t> NowExcludingSuspendMs() {
struct timespec ts = {0};
if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
return Nothing();
}
return Some(TimespecToMilliseconds(ts));
}
Maybe<uint64_t> NowIncludingSuspendMs() {
# ifndef CLOCK_BOOTTIME
return Nothing();
# else
struct timespec ts = {0};
if (clock_gettime(CLOCK_BOOTTIME, &ts)) {
return Nothing();
}
return Some(TimespecToMilliseconds(ts));
# endif
}
#endif // XP_LINUX
}; // anonymous namespace
namespace mozilla {
void InitializeUptime() {
MOZ_RELEASE_ASSERT(mStartIncludingSuspendMs.isNothing() &&
mStartExcludingSuspendMs.isNothing(),
"Must not be called more than once");
mStartIncludingSuspendMs = NowIncludingSuspendMs();
mStartExcludingSuspendMs = NowExcludingSuspendMs();
}
Maybe<uint64_t> ProcessUptimeMs() {
if (!mStartIncludingSuspendMs) {
return Nothing();
}
Maybe<uint64_t> maybeNow = NowIncludingSuspendMs();
if (!maybeNow) {
return Nothing();
}
return Some(maybeNow.value() - mStartIncludingSuspendMs.value());
}
Maybe<uint64_t> ProcessUptimeExcludingSuspendMs() {
if (!mStartExcludingSuspendMs) {
return Nothing();
}
Maybe<uint64_t> maybeNow = NowExcludingSuspendMs();
if (!maybeNow) {
return Nothing();
}
return Some(maybeNow.value() - mStartExcludingSuspendMs.value());
}
}; // namespace mozilla

View File

@ -1,26 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_Uptime_h
#define mozilla_Uptime_h
#include <stdint.h>
#include "mozilla/Maybe.h"
namespace mozilla {
// Called at the beginning of the process from TimeStamp::Startup.
MFBT_API void InitializeUptime();
// Returns the number of milliseconds the calling process has lived for.
MFBT_API Maybe<uint64_t> ProcessUptimeMs();
// Returns the number of milliseconds the calling process has lived for,
// excluding the time period the system was suspended.
MFBT_API Maybe<uint64_t> ProcessUptimeExcludingSuspendMs();
}; // namespace mozilla
#endif // mozilla_Uptime_h

View File

@ -16,7 +16,6 @@ EXPORTS.mozilla += [
"Printf.h",
"StackWalk.h",
"TimeStamp.h",
"Uptime.h",
]
EXPORTS.mozilla.glue += [
@ -38,7 +37,6 @@ SOURCES += [
"Printf.cpp",
"StackWalk.cpp",
"TimeStamp.cpp",
"Uptime.cpp",
]
OS_LIBS += CONFIG["REALTIME_LIBS"]

View File

@ -653,9 +653,6 @@ class SandboxPolicyCommon : public SandboxPolicyBase {
// Allow clock_gettime on a thread.
// 4 -> CPUCLOCK_PERTHREAD_MASK. 2 -> CPUCLOCK_SCHED.
.ElseIf((clk_id & 7u) == (4u | 2u), Allow())
#endif
#ifdef CLOCK_BOOTTIME
.ElseIf(clk_id == CLOCK_BOOTTIME, Allow())
#endif
.Else(InvalidSyscall());
}

View File

@ -401,39 +401,6 @@ browser.engagement:
record_in_processes:
- 'main'
session_time_including_suspend:
bug_numbers:
- 1205985
description: >
The duration of the session in milliseconds, including the time the device
was suspended.
expires: never
kind: uint
notification_emails:
- padenot@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
session_time_excluding_suspend:
bug_numbers:
- 1205985
description: >
The duration of the session in milliseconds, excluding the time the device
was suspended.
expires: never
kind: uint
notification_emails:
- padenot@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
# The following section contains the browser engagement scalars.
browser.engagement.navigation:
urlbar:
@ -3281,6 +3248,23 @@ telemetry:
record_in_processes:
- 'main'
process_creation_timestamp_inconsistent:
bug_numbers:
- 1514392
description: >
The number of times ProcessCreation saw an inconsistent value.
expires: "72"
kind: uint
notification_emails:
- jrediger@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
- 'fennec'
record_in_processes:
- 'main'
- 'content'
environment_didnt_change:
bug_numbers:
- 1483477

View File

@ -1506,16 +1506,6 @@ TelemetryImpl::MsSinceProcessStart(double* aResult) {
return Telemetry::Common::MsSinceProcessStart(aResult);
}
NS_IMETHODIMP
TelemetryImpl::MsSinceProcessStartIncludingSuspend(double* aResult) {
return Telemetry::Common::MsSinceProcessStartIncludingSuspend(aResult);
}
NS_IMETHODIMP
TelemetryImpl::MsSinceProcessStartExcludingSuspend(double* aResult) {
return Telemetry::Common::MsSinceProcessStartExcludingSuspend(aResult);
}
NS_IMETHODIMP
TelemetryImpl::MsSystemNow(double* aResult) {
#if defined(XP_UNIX) && !defined(XP_DARWIN)

View File

@ -17,7 +17,6 @@
#include "nsVersionComparator.h"
#include "TelemetryProcessData.h"
#include "Telemetry.h"
#include "mozilla/Uptime.h"
namespace mozilla::Telemetry::Common {
@ -85,29 +84,19 @@ bool CanRecordProduct(SupportedProduct aProducts) {
}
nsresult MsSinceProcessStart(double* aResult) {
bool isInconsistent = false;
*aResult =
(TimeStamp::NowLoRes() - TimeStamp::ProcessCreation()).ToMilliseconds();
(TimeStamp::NowLoRes() - TimeStamp::ProcessCreation(&isInconsistent))
.ToMilliseconds();
if (isInconsistent) {
Telemetry::ScalarAdd(
Telemetry::ScalarID::TELEMETRY_PROCESS_CREATION_TIMESTAMP_INCONSISTENT,
1);
}
return NS_OK;
}
nsresult MsSinceProcessStartIncludingSuspend(double* aResult) {
auto rv = mozilla::ProcessUptimeMs();
if (rv) {
*aResult = rv.value();
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
}
nsresult MsSinceProcessStartExcludingSuspend(double* aResult) {
auto rv = mozilla::ProcessUptimeExcludingSuspendMs();
if (rv) {
*aResult = rv.value();
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
}
void LogToBrowserConsole(uint32_t aLogLevel, const nsAString& aMsg) {
if (!NS_IsMainThread()) {
nsString msg(aMsg);

View File

@ -87,34 +87,13 @@ bool CanRecordProduct(SupportedProduct aProducts);
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes). Depending on the platform,
* this can include the time the device was suspended (Windows) or not (Linux,
* macOS).
* timestamps (unaffected by system clock changes).
*
* @return NS_OK on success.
* @return NS_OK on success, NS_ERROR_NOT_AVAILABLE if TimeStamp doesn't have
* the data.
*/
nsresult MsSinceProcessStart(double* aResult);
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes), including the time the
* system was suspended.
*
* @return NS_OK on success, NS_ERROR_NOT_AVAILABLE if the data is unavailable
* (this can happen on old operating systems).
*/
nsresult MsSinceProcessStartIncludingSuspend(double* aResult);
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes), excluding the time the
* system was suspended.
*
* @return NS_OK on success, NS_ERROR_NOT_AVAILABLE if the data is unavailable
* (this can happen on old operating systems).
*/
nsresult MsSinceProcessStartExcludingSuspend(double* aResult);
/**
* Dumps a log message to the Browser Console using the provided level.
*

View File

@ -409,28 +409,11 @@ interface nsITelemetry : nsISupports
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes). On Windows, this includes
* the period of time the device was suspended. On Linux and macOS, this does
* not include the period of time the device was suspneded.
* timestamps (unaffected by system clock changes).
* @throws NS_ERROR_NOT_AVAILABLE if TimeStamp doesn't have the data.
*/
double msSinceProcessStart();
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes), including the periods of
* time the device was suspended.
* @throws NS_ERROR_NOT_AVAILABLE if unavailable.
*/
double msSinceProcessStartIncludingSuspend();
/**
* Return the number of milliseconds since process start using monotonic
* timestamps (unaffected by system clock changes), excluding the periods of
* time the device was suspended.
* @throws NS_ERROR_NOT_AVAILABLE if unavailable.
*/
double msSinceProcessStartExcludingSuspend();
/**
* Time since the system wide epoch. This is not a monotonic timer but
* can be used across process boundaries.

View File

@ -762,15 +762,6 @@ var Impl = {
const isMobile = AppConstants.platform == "android";
const isSubsession = isMobile ? false : !this._isClassicReason(reason);
Telemetry.scalarSet(
"browser.engagement.session_time_including_suspend",
Telemetry.msSinceProcessStartIncludingSuspend()
);
Telemetry.scalarSet(
"browser.engagement.session_time_excluding_suspend",
Telemetry.msSinceProcessStartExcludingSuspend()
);
if (isMobile) {
clearSubsession = false;
}

View File

@ -597,52 +597,6 @@ add_task(async function test_expiredHistogram() {
);
});
add_task(async function sessionTimeExcludingAndIncludingSuspend() {
Preferences.set("toolkit.telemetry.testing.overrideProductsCheck", true);
await TelemetryController.testReset();
let subsession = TelemetrySession.getPayload("environment-change", true);
let parentScalars = subsession.processes.parent.scalars;
let withSuspend =
parentScalars["browser.engagement.session_time_including_suspend"];
let withoutSuspend =
parentScalars["browser.engagement.session_time_excluding_suspend"];
Assert.ok(
withSuspend > 0,
"The session time including suspend should be positive"
);
Assert.ok(
withoutSuspend > 0,
"The session time excluding suspend should be positive"
);
// Two things about the next assertion:
// 1. The two calls to get the two different uptime values are made
// separately, so we can't guarantee equality, even if we know the machine
// has not been suspended (for example because it's running in infra and
// was just booted). In this case the value should be close to each other.
// 2. This test will fail if the device running this has been suspended in
// between booting the Firefox process running this test, and doing the
// following assertion test, but that's unlikely in practice.
const max_delta_ms = 100;
Assert.ok(
withSuspend - withoutSuspend <= max_delta_ms,
"In test condition, the two uptimes should be close to each other"
);
// This however should always hold.
Assert.ok(
withSuspend >= withoutSuspend,
`The uptime without suspend must always been greater or equal to the uptime
without suspend`
);
Preferences.set("toolkit.telemetry.testing.overrideProductsCheck", false);
});
// Sends a ping to a non existing server. If we remove this test, we won't get
// all the histograms we need in the main ping.
add_task(async function test_noServerPing() {