mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibWeb: Report performance based timestamps relative to ESO time origin
This commit is contained in:
parent
8963e62a5e
commit
7488136a51
Notes:
github-actions[bot]
2025-01-27 13:54:36 +00:00
Author: https://github.com/tcl3
Commit: 7488136a51
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3341
12 changed files with 248 additions and 28 deletions
|
@ -24,9 +24,7 @@ GC_DEFINE_ALLOCATOR(Performance);
|
|||
|
||||
Performance::Performance(JS::Realm& realm)
|
||||
: DOM::EventTarget(realm)
|
||||
, m_timer(Core::TimerType::Precise)
|
||||
{
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
Performance::~Performance() = default;
|
||||
|
@ -68,8 +66,8 @@ GC::Ptr<NavigationTiming::PerformanceNavigation> Performance::navigation()
|
|||
// https://w3c.github.io/hr-time/#timeorigin-attribute
|
||||
double Performance::time_origin() const
|
||||
{
|
||||
// FIXME: The timeOrigin attribute MUST return the number of milliseconds in the duration returned by get time origin timestamp for the relevant global object of this.
|
||||
return static_cast<double>(m_timer.origin_time().nanoseconds()) / 1e6;
|
||||
// The timeOrigin attribute MUST return the number of milliseconds in the duration returned by get time origin timestamp for the relevant global object of this.
|
||||
return get_time_origin_timestamp(HTML::relevant_principal_global_object(*this));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#now-method
|
||||
|
|
|
@ -51,8 +51,6 @@ private:
|
|||
|
||||
GC::Ptr<NavigationTiming::PerformanceNavigation> m_navigation;
|
||||
GC::Ptr<NavigationTiming::PerformanceTiming> m_timing;
|
||||
|
||||
Core::ElapsedTimer m_timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -11,23 +11,15 @@
|
|||
|
||||
namespace Web::HighResolutionTime {
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
|
||||
DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
||||
// https://w3c.github.io/hr-time/#dfn-estimated-monotonic-time-of-the-unix-epoch
|
||||
DOMHighResTimeStamp estimated_monotonic_time_of_the_unix_epoch()
|
||||
{
|
||||
(void)global;
|
||||
|
||||
// To get time origin timestamp, given a global object global, run the following steps, which return a duration:
|
||||
// FIXME: 1. Let timeOrigin be global's relevant settings object's time origin.
|
||||
auto time_origin = 0;
|
||||
|
||||
// Each group of environment settings objects that could possibly communicate in any way
|
||||
// has an estimated monotonic time of the Unix epoch, a moment on the monotonic clock,
|
||||
// whose value is initialized by the following steps:
|
||||
|
||||
// !. Let wall time be the wall clock's unsafe current time.
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
auto wall_time = tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
|
||||
// 1. Let wall time be the wall clock's unsafe current time.
|
||||
auto wall_time = wall_clock_unsafe_current_time();
|
||||
|
||||
// 2. Let monotonic time be the monotonic clock's unsafe current time.
|
||||
auto monotonic_time = unsafe_shared_current_time();
|
||||
|
@ -37,9 +29,18 @@ DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
|||
|
||||
// 4. Initialize the estimated monotonic time of the Unix epoch to the result of calling coarsen time with epoch time
|
||||
auto estimated_monotonic_time = coarsen_time(epoch_time);
|
||||
return estimated_monotonic_time;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
|
||||
DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global)
|
||||
{
|
||||
// To get time origin timestamp, given a global object global, run the following steps, which return a duration:
|
||||
// 1. Let timeOrigin be global's relevant settings object's time origin.
|
||||
auto time_origin = HTML::relevant_principal_settings_object(global).time_origin();
|
||||
|
||||
// 2. Return the duration from the estimated monotonic time of the Unix epoch to timeOrigin.
|
||||
return estimated_monotonic_time - time_origin;
|
||||
return time_origin - estimated_monotonic_time_of_the_unix_epoch();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-coarsen-time
|
||||
|
@ -75,8 +76,9 @@ DOMHighResTimeStamp relative_high_resolution_time(DOMHighResTimeStamp time, JS::
|
|||
// https://w3c.github.io/hr-time/#dfn-relative-high-resolution-coarse-time
|
||||
DOMHighResTimeStamp relative_high_resolution_coarsen_time(DOMHighResTimeStamp coarsen_time, JS::Object const& global)
|
||||
{
|
||||
// The relative high resolution coarse time given a DOMHighResTimeStamp coarseTime and a global object global, is the difference between coarseTime and the result of calling get time origin timestamp with global.
|
||||
return coarsen_time - get_time_origin_timestamp(global);
|
||||
// The relative high resolution coarse time given a moment from the monotonic clock coarseTime and a global object global, is the duration from global's relevant settings object's time origin to coarseTime.
|
||||
auto time_origin = HTML::relevant_principal_settings_object(global).time_origin();
|
||||
return coarsen_time - time_origin;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
|
||||
|
@ -86,6 +88,12 @@ DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_cap
|
|||
return coarsen_time(unsafe_shared_current_time(), cross_origin_isolated_capability);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#wall-clock-unsafe-current-time
|
||||
DOMHighResTimeStamp wall_clock_unsafe_current_time()
|
||||
{
|
||||
return UnixDateTime::now().nanoseconds_since_epoch() / 1.0e6;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
|
||||
DOMHighResTimeStamp unsafe_shared_current_time()
|
||||
{
|
||||
|
|
|
@ -12,12 +12,14 @@
|
|||
|
||||
namespace Web::HighResolutionTime {
|
||||
|
||||
DOMHighResTimeStamp estimated_monotonic_time_of_the_unix_epoch();
|
||||
DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const&);
|
||||
DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability = false);
|
||||
DOMHighResTimeStamp current_high_resolution_time(JS::Object const&);
|
||||
DOMHighResTimeStamp relative_high_resolution_time(DOMHighResTimeStamp, JS::Object const&);
|
||||
DOMHighResTimeStamp relative_high_resolution_coarsen_time(DOMHighResTimeStamp, JS::Object const&);
|
||||
DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability = false);
|
||||
DOMHighResTimeStamp wall_clock_unsafe_current_time();
|
||||
DOMHighResTimeStamp unsafe_shared_current_time();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue