Performance.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibCore/ElapsedTimer.h>
  9. #include <LibWeb/DOM/EventTarget.h>
  10. #include <LibWeb/UserTiming/PerformanceMark.h>
  11. namespace Web::HighResolutionTime {
  12. class Performance final : public DOM::EventTarget {
  13. WEB_PLATFORM_OBJECT(Performance, DOM::EventTarget);
  14. public:
  15. virtual ~Performance() override;
  16. double now() const { return static_cast<double>(m_timer.elapsed()); }
  17. double time_origin() const;
  18. JS::GCPtr<NavigationTiming::PerformanceTiming> timing();
  19. WebIDL::ExceptionOr<JS::NonnullGCPtr<UserTiming::PerformanceMark>> mark(String const& mark_name, UserTiming::PerformanceMarkOptions const& mark_options = {});
  20. void clear_marks(Optional<String> mark_name);
  21. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries() const;
  22. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_type(String const& type) const;
  23. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
  24. private:
  25. explicit Performance(HTML::Window&);
  26. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  27. virtual void visit_edges(Cell::Visitor&) override;
  28. JS::NonnullGCPtr<HTML::Window> m_window;
  29. JS::GCPtr<NavigationTiming::PerformanceTiming> m_timing;
  30. Core::ElapsedTimer m_timer;
  31. };
  32. }