Performance.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace Web::HighResolutionTime {
  11. class Performance final : public DOM::EventTarget {
  12. WEB_PLATFORM_OBJECT(Performance, DOM::EventTarget);
  13. public:
  14. virtual ~Performance() override;
  15. double now() const { return static_cast<double>(m_timer.elapsed()); }
  16. double time_origin() const;
  17. JS::GCPtr<NavigationTiming::PerformanceTiming> timing();
  18. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries() const;
  19. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_type(String const& type) const;
  20. WebIDL::ExceptionOr<Vector<JS::Handle<PerformanceTimeline::PerformanceEntry>>> get_entries_by_name(String const& name, Optional<String> type) const;
  21. private:
  22. explicit Performance(HTML::Window&);
  23. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  24. virtual void visit_edges(Cell::Visitor&) override;
  25. JS::NonnullGCPtr<HTML::Window> m_window;
  26. JS::GCPtr<NavigationTiming::PerformanceTiming> m_timing;
  27. Core::ElapsedTimer m_timer;
  28. };
  29. }