| 
									
										
										
										
											2020-09-29 18:19:18 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2020, Andreas Kling <andreas@ladybird.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>
 | 
					
						
							| 
									
										
										
										
											2024-03-30 10:04:31 +00:00
										 |  |  | #include <LibWeb/HTML/WindowOrWorkerGlobalScope.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); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(Performance); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 17:52:03 +00:00
										 |  |  |     double now() const { return static_cast<double>(m_timer.elapsed_time().to_nanoseconds()) / 1e6; } | 
					
						
							| 
									
										
										
										
											2020-09-29 18:31:07 +02:00
										 |  |  |     double time_origin() const; | 
					
						
							| 
									
										
										
										
											2020-09-29 18:19:18 +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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-01 19:50:52 -06:00
										 |  |  |     JS::GCPtr<NavigationTiming::PerformanceTiming> timing(); | 
					
						
							|  |  |  |     JS::GCPtr<NavigationTiming::PerformanceNavigation> navigation(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-04-05 18:04:01 -07:00
										 |  |  |     explicit Performance(JS::Realm&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     HTML::WindowOrWorkerGlobalScopeMixin& window_or_worker(); | 
					
						
							|  |  |  |     HTML::WindowOrWorkerGlobalScopeMixin const& window_or_worker() const; | 
					
						
							| 
									
										
										
										
											2021-01-18 15:06:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     virtual 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-01 19:50:52 -06:00
										 |  |  |     JS::GCPtr<NavigationTiming::PerformanceNavigation> m_navigation; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |