mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
Bug 1313420 - Implement Performance.timeOrigin - part 1
https://hg.mozilla.org/mozilla-central/rev/cf0f72f0b0be
This commit is contained in:
parent
fdcf9f71e5
commit
ad947fb20a
6 changed files with 117 additions and 1 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include "PerformanceMeasure.h"
|
#include "PerformanceMeasure.h"
|
||||||
#include "PerformanceObserver.h"
|
#include "PerformanceObserver.h"
|
||||||
#include "PerformanceResourceTiming.h"
|
#include "PerformanceResourceTiming.h"
|
||||||
|
#include "PerformanceService.h"
|
||||||
#include "PerformanceWorker.h"
|
#include "PerformanceWorker.h"
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
#include "mozilla/dom/PerformanceBinding.h"
|
#include "mozilla/dom/PerformanceBinding.h"
|
||||||
|
|
@ -119,6 +120,17 @@ Performance::Performance(nsPIDOMWindowInner* aWindow)
|
||||||
Performance::~Performance()
|
Performance::~Performance()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
DOMHighResTimeStamp
|
||||||
|
Performance::TimeOrigin()
|
||||||
|
{
|
||||||
|
if (!mPerformanceService) {
|
||||||
|
mPerformanceService = PerformanceService::GetOrCreate();
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_ASSERT(mPerformanceService);
|
||||||
|
return mPerformanceService->TimeOrigin(CreationTimeStamp());
|
||||||
|
}
|
||||||
|
|
||||||
JSObject*
|
JSObject*
|
||||||
Performance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
Performance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||||
{
|
{
|
||||||
|
|
@ -243,7 +255,7 @@ Performance::ClearMarks(const Optional<nsAString>& aName)
|
||||||
|
|
||||||
DOMHighResTimeStamp
|
DOMHighResTimeStamp
|
||||||
Performance::ResolveTimestampFromName(const nsAString& aName,
|
Performance::ResolveTimestampFromName(const nsAString& aName,
|
||||||
ErrorResult& aRv)
|
ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
|
AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
|
||||||
DOMHighResTimeStamp ts;
|
DOMHighResTimeStamp ts;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ namespace dom {
|
||||||
class PerformanceEntry;
|
class PerformanceEntry;
|
||||||
class PerformanceNavigation;
|
class PerformanceNavigation;
|
||||||
class PerformanceObserver;
|
class PerformanceObserver;
|
||||||
|
class PerformanceService;
|
||||||
class PerformanceTiming;
|
class PerformanceTiming;
|
||||||
|
|
||||||
namespace workers {
|
namespace workers {
|
||||||
|
|
@ -69,6 +70,8 @@ public:
|
||||||
|
|
||||||
virtual DOMHighResTimeStamp Now() const = 0;
|
virtual DOMHighResTimeStamp Now() const = 0;
|
||||||
|
|
||||||
|
DOMHighResTimeStamp TimeOrigin();
|
||||||
|
|
||||||
void Mark(const nsAString& aName, ErrorResult& aRv);
|
void Mark(const nsAString& aName, ErrorResult& aRv);
|
||||||
|
|
||||||
void ClearMarks(const Optional<nsAString>& aName);
|
void ClearMarks(const Optional<nsAString>& aName);
|
||||||
|
|
@ -157,6 +160,8 @@ private:
|
||||||
uint64_t mResourceTimingBufferSize;
|
uint64_t mResourceTimingBufferSize;
|
||||||
static const uint64_t kDefaultResourceTimingBufferSize = 150;
|
static const uint64_t kDefaultResourceTimingBufferSize = 150;
|
||||||
bool mPendingNotificationObserversTask;
|
bool mPendingNotificationObserversTask;
|
||||||
|
|
||||||
|
RefPtr<PerformanceService> mPerformanceService;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
|
|
||||||
46
dom/performance/PerformanceService.cpp
Normal file
46
dom/performance/PerformanceService.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* -*- 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 "PerformanceService.h"
|
||||||
|
|
||||||
|
#include "mozilla/ClearOnShutdown.h"
|
||||||
|
#include "mozilla/StaticMutex.h"
|
||||||
|
#include "mozilla/StaticPtr.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
static StaticRefPtr<PerformanceService> gPerformanceService;
|
||||||
|
static StaticMutex gPerformanceServiceMutex;
|
||||||
|
|
||||||
|
/* static */ PerformanceService*
|
||||||
|
PerformanceService::GetOrCreate()
|
||||||
|
{
|
||||||
|
StaticMutexAutoLock al(gPerformanceServiceMutex);
|
||||||
|
|
||||||
|
if (!gPerformanceService) {
|
||||||
|
gPerformanceService = new PerformanceService();
|
||||||
|
ClearOnShutdown(&gPerformanceService);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gPerformanceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
DOMHighResTimeStamp
|
||||||
|
PerformanceService::TimeOrigin(const TimeStamp& aCreationTimeStamp) const
|
||||||
|
{
|
||||||
|
return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() +
|
||||||
|
(mCreationEpochTime / PR_USEC_PER_MSEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
PerformanceService::PerformanceService()
|
||||||
|
{
|
||||||
|
mCreationTimeStamp = TimeStamp::Now();
|
||||||
|
mCreationEpochTime = PR_Now();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // dom namespace
|
||||||
|
} // mozilla namespace
|
||||||
48
dom/performance/PerformanceService.h
Normal file
48
dom/performance/PerformanceService.h
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
/* -*- 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 dom_performance_PerformanceService_h
|
||||||
|
#define dom_performance_PerformanceService_h
|
||||||
|
|
||||||
|
#include "mozilla/TimeStamp.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsDOMNavigationTiming.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
// This class is thread-safe.
|
||||||
|
|
||||||
|
// We use this singleton for having the correct value of performance.timeOrigin.
|
||||||
|
// This value must be calculated on top of the pair:
|
||||||
|
// - mCreationTimeStamp (monotonic clock)
|
||||||
|
// - mCreationEpochTime (unix epoch time)
|
||||||
|
// These 2 values must be taken "at the same time" in order to be used
|
||||||
|
// correctly.
|
||||||
|
|
||||||
|
class PerformanceService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PerformanceService)
|
||||||
|
|
||||||
|
static PerformanceService*
|
||||||
|
GetOrCreate();
|
||||||
|
|
||||||
|
DOMHighResTimeStamp
|
||||||
|
TimeOrigin(const TimeStamp& aCreationTimeStamp) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
PerformanceService();
|
||||||
|
~PerformanceService() = default;
|
||||||
|
|
||||||
|
TimeStamp mCreationTimeStamp;
|
||||||
|
PRTime mCreationEpochTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // dom namespace
|
||||||
|
} // mozilla namespace
|
||||||
|
|
||||||
|
#endif // dom_performance_PerformanceService_h
|
||||||
|
|
@ -13,6 +13,7 @@ EXPORTS.mozilla.dom += [
|
||||||
'PerformanceObserver.h',
|
'PerformanceObserver.h',
|
||||||
'PerformanceObserverEntryList.h',
|
'PerformanceObserverEntryList.h',
|
||||||
'PerformanceResourceTiming.h',
|
'PerformanceResourceTiming.h',
|
||||||
|
'PerformanceService.h',
|
||||||
'PerformanceTiming.h',
|
'PerformanceTiming.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -26,6 +27,7 @@ UNIFIED_SOURCES += [
|
||||||
'PerformanceObserver.cpp',
|
'PerformanceObserver.cpp',
|
||||||
'PerformanceObserverEntryList.cpp',
|
'PerformanceObserverEntryList.cpp',
|
||||||
'PerformanceResourceTiming.cpp',
|
'PerformanceResourceTiming.cpp',
|
||||||
|
'PerformanceService.cpp',
|
||||||
'PerformanceTiming.cpp',
|
'PerformanceTiming.cpp',
|
||||||
'PerformanceWorker.cpp',
|
'PerformanceWorker.cpp',
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ typedef sequence <PerformanceEntry> PerformanceEntryList;
|
||||||
interface Performance {
|
interface Performance {
|
||||||
[DependsOn=DeviceState, Affects=Nothing]
|
[DependsOn=DeviceState, Affects=Nothing]
|
||||||
DOMHighResTimeStamp now();
|
DOMHighResTimeStamp now();
|
||||||
|
|
||||||
|
[Constant]
|
||||||
|
readonly attribute DOMHighResTimeStamp timeOrigin;
|
||||||
};
|
};
|
||||||
|
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue