2020-09-29 18:19:18 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2023-03-22 19:12:57 +00:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2020-09-29 18:19:18 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-29 18:19:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibCore/ElapsedTimer.h>
|
|
|
|
|
#include <LibWeb/DOM/EventTarget.h>
|
2023-03-23 17:07:52 +00:00
|
|
|
#include <LibWeb/UserTiming/PerformanceMark.h>
|
2023-05-13 13:34:28 +01:00
|
|
|
#include <LibWeb/UserTiming/PerformanceMeasure.h>
|
2020-09-29 18:19:18 +02:00
|
|
|
|
|
|
|
|
namespace Web::HighResolutionTime {
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
class Performance final : public DOM::EventTarget {
|
|
|
|
|
WEB_PLATFORM_OBJECT(Performance, DOM::EventTarget);
|
2020-09-29 18:19:18 +02:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
|
|
|
|
virtual ~Performance() override;
|
2020-09-29 18:19:18 +02:00
|
|
|
|
2023-01-01 22:50:49 -07:00
|
|
|
double now() const { return static_cast<double>(m_timer.elapsed()); }
|
2020-09-29 18:31:07 +02:00
|
|
|
double time_origin() const;
|
2020-09-29 18:19:18 +02:00
|
|
|
|
2022-08-31 19:12:11 +02:00
|
|
|
JS::GCPtr<NavigationTiming::PerformanceTiming> timing();
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2023-03-23 17:07:52 +00:00
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<UserTiming::PerformanceMark>> mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options = {});
|
|
|
|
|
void clear_marks(Optional<String> mark_name);
|
2023-05-13 13:34:28 +01:00
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<UserTiming::PerformanceMeasure>> measure(String const& measure_name, Variant<String, UserTiming::PerformanceMeasureOptions> const& start_or_measure_options, Optional<String> end_mark);
|
|
|
|
|
void clear_measures(Optional<String> measure_name);
|
2023-03-23 17:07:52 +00:00
|
|
|
|
2023-03-22 19:12:57 +00:00
|
|
|
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries() const;
|
|
|
|
|
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_type(String const& type) const;
|
|
|
|
|
WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
private:
|
|
|
|
|
explicit Performance(HTML::Window&);
|
2021-01-18 15:06:13 +01:00
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2020-09-29 18:19:18 +02:00
|
|
|
|
2023-05-13 13:34:28 +01:00
|
|
|
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_name_to_timestamp(JS::Realm& realm, String const& name);
|
|
|
|
|
WebIDL::ExceptionOr<HighResolutionTime::DOMHighResTimeStamp> convert_mark_to_timestamp(JS::Realm& realm, Variant<String, HighResolutionTime::DOMHighResTimeStamp> mark);
|
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
JS::NonnullGCPtr<HTML::Window> m_window;
|
2022-08-31 19:12:11 +02:00
|
|
|
JS::GCPtr<NavigationTiming::PerformanceTiming> m_timing;
|
2020-09-29 18:19:18 +02:00
|
|
|
|
|
|
|
|
Core::ElapsedTimer m_timer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|