/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2023, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::HighResolutionTime { class Performance final : public DOM::EventTarget { WEB_PLATFORM_OBJECT(Performance, DOM::EventTarget); JS_DECLARE_ALLOCATOR(Performance); public: virtual ~Performance() override; double now() const { return static_cast(m_timer.elapsed_time().to_nanoseconds()) / 1e6; } double time_origin() const; WebIDL::ExceptionOr> mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options = {}); void clear_marks(Optional mark_name); WebIDL::ExceptionOr> measure(String const& measure_name, Variant const& start_or_measure_options, Optional end_mark); void clear_measures(Optional measure_name); WebIDL::ExceptionOr>> get_entries() const; WebIDL::ExceptionOr>> get_entries_by_type(String const& type) const; WebIDL::ExceptionOr>> get_entries_by_name(String const& name, Optional type) const; JS::GCPtr timing(); JS::GCPtr navigation(); private: explicit Performance(JS::Realm&); HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker(); HTML::WindowOrWorkerGlobalScopeMixin const& window_or_worker() const; virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; WebIDL::ExceptionOr convert_name_to_timestamp(JS::Realm& realm, String const& name); WebIDL::ExceptionOr convert_mark_to_timestamp(JS::Realm& realm, Variant mark); JS::GCPtr m_navigation; JS::GCPtr m_timing; Core::ElapsedTimer m_timer; }; }