mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1313420 - Implement Performance.timeOrigin - part 1, r=bz
This commit is contained in:
parent
0b046c7ab4
commit
b0435b9411
@ -13,6 +13,7 @@
|
||||
#include "PerformanceMeasure.h"
|
||||
#include "PerformanceObserver.h"
|
||||
#include "PerformanceResourceTiming.h"
|
||||
#include "PerformanceService.h"
|
||||
#include "PerformanceWorker.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/PerformanceBinding.h"
|
||||
@ -141,6 +142,17 @@ Performance::Performance(nsPIDOMWindowInner* aWindow)
|
||||
Performance::~Performance()
|
||||
{}
|
||||
|
||||
DOMHighResTimeStamp
|
||||
Performance::TimeOrigin()
|
||||
{
|
||||
if (!mPerformanceService) {
|
||||
mPerformanceService = PerformanceService::GetOrCreate();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mPerformanceService);
|
||||
return mPerformanceService->TimeOrigin(CreationTimeStamp());
|
||||
}
|
||||
|
||||
JSObject*
|
||||
Performance::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
@ -266,7 +278,7 @@ Performance::ClearMarks(const Optional<nsAString>& aName)
|
||||
|
||||
DOMHighResTimeStamp
|
||||
Performance::ResolveTimestampFromName(const nsAString& aName,
|
||||
ErrorResult& aRv)
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AutoTArray<RefPtr<PerformanceEntry>, 1> arr;
|
||||
DOMHighResTimeStamp ts;
|
||||
|
@ -24,6 +24,7 @@ namespace dom {
|
||||
class PerformanceEntry;
|
||||
class PerformanceNavigation;
|
||||
class PerformanceObserver;
|
||||
class PerformanceService;
|
||||
class PerformanceTiming;
|
||||
|
||||
namespace workers {
|
||||
@ -70,6 +71,8 @@ public:
|
||||
|
||||
virtual DOMHighResTimeStamp Now() const = 0;
|
||||
|
||||
DOMHighResTimeStamp TimeOrigin();
|
||||
|
||||
void Mark(const nsAString& aName, ErrorResult& aRv);
|
||||
|
||||
void ClearMarks(const Optional<nsAString>& aName);
|
||||
@ -154,6 +157,8 @@ private:
|
||||
uint64_t mResourceTimingBufferSize;
|
||||
static const uint64_t kDefaultResourceTimingBufferSize = 150;
|
||||
bool mPendingNotificationObserversTask;
|
||||
|
||||
RefPtr<PerformanceService> mPerformanceService;
|
||||
};
|
||||
|
||||
} // 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',
|
||||
'PerformanceObserverEntryList.h',
|
||||
'PerformanceResourceTiming.h',
|
||||
'PerformanceService.h',
|
||||
'PerformanceTiming.h',
|
||||
]
|
||||
|
||||
@ -26,6 +27,7 @@ UNIFIED_SOURCES += [
|
||||
'PerformanceObserver.cpp',
|
||||
'PerformanceObserverEntryList.cpp',
|
||||
'PerformanceResourceTiming.cpp',
|
||||
'PerformanceService.cpp',
|
||||
'PerformanceTiming.cpp',
|
||||
'PerformanceWorker.cpp',
|
||||
]
|
||||
|
@ -17,6 +17,9 @@ typedef sequence <PerformanceEntry> PerformanceEntryList;
|
||||
interface Performance {
|
||||
[DependsOn=DeviceState, Affects=Nothing]
|
||||
DOMHighResTimeStamp now();
|
||||
|
||||
[Constant]
|
||||
readonly attribute DOMHighResTimeStamp timeOrigin;
|
||||
};
|
||||
|
||||
[Exposed=Window]
|
||||
|
Loading…
Reference in New Issue
Block a user