PerformanceMark.h (2455B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_performancemark_h___ 8 #define mozilla_dom_performancemark_h___ 9 10 #include "mozilla/ProfilerMarkers.h" 11 #include "mozilla/dom/PerformanceEntry.h" 12 13 namespace mozilla::dom { 14 15 struct PerformanceMarkOptions; 16 17 // http://www.w3.org/TR/user-timing/#performancemark 18 class PerformanceMark final : public PerformanceEntry { 19 public: 20 NS_DECL_ISUPPORTS_INHERITED 21 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMark, 22 PerformanceEntry); 23 24 private: 25 PerformanceMark(nsISupports* aParent, const nsAString& aName, 26 DOMHighResTimeStamp aStartTime, 27 const JS::Handle<JS::Value>& aDetail, 28 DOMHighResTimeStamp aUnclampedStartTime); 29 30 public: 31 static already_AddRefed<PerformanceMark> Constructor( 32 const GlobalObject& aGlobal, const nsAString& aMarkName, 33 const PerformanceMarkOptions& aMarkOptions, ErrorResult& aRv); 34 35 static already_AddRefed<PerformanceMark> Constructor( 36 JSContext* aCx, nsIGlobalObject* aGlobal, const nsAString& aMarkName, 37 const PerformanceMarkOptions& aMarkOptions, ErrorResult& aRv); 38 39 virtual JSObject* WrapObject(JSContext* aCx, 40 JS::Handle<JSObject*> aGivenProto) override; 41 42 virtual DOMHighResTimeStamp StartTime() const override { return mStartTime; } 43 44 virtual DOMHighResTimeStamp UnclampedStartTime() const override { 45 MOZ_ASSERT(profiler_thread_is_being_profiled_for_markers(), 46 "This should only be called when the Gecko Profiler is active."); 47 return mUnclampedStartTime; 48 } 49 50 void GetDetail(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval); 51 52 size_t SizeOfIncludingThis( 53 mozilla::MallocSizeOf aMallocSizeOf) const override; 54 55 protected: 56 virtual ~PerformanceMark(); 57 DOMHighResTimeStamp mStartTime; 58 59 private: 60 JS::Heap<JS::Value> mDetail; 61 // This is used by the Gecko Profiler only to be able to add precise markers. 62 // It's not exposed to JS 63 DOMHighResTimeStamp mUnclampedStartTime; 64 }; 65 66 } // namespace mozilla::dom 67 68 #endif /* mozilla_dom_performancemark_h___ */