summaryrefslogtreecommitdiffstats
path: root/xpcom/threads/HangAnnotations.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /xpcom/threads/HangAnnotations.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'xpcom/threads/HangAnnotations.h')
-rw-r--r--xpcom/threads/HangAnnotations.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/xpcom/threads/HangAnnotations.h b/xpcom/threads/HangAnnotations.h
new file mode 100644
index 000000000..6dddbf4bb
--- /dev/null
+++ b/xpcom/threads/HangAnnotations.h
@@ -0,0 +1,104 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_HangAnnotations_h
+#define mozilla_HangAnnotations_h
+
+#include <set>
+
+#include "mozilla/MemoryReporting.h"
+#include "mozilla/Mutex.h"
+#include "mozilla/UniquePtr.h"
+#include "mozilla/Vector.h"
+#include "nsString.h"
+
+namespace mozilla {
+namespace HangMonitor {
+
+/**
+ * This class declares an abstraction for a data type that encapsulates all
+ * of the annotations being reported by a registered hang Annotator.
+ */
+class HangAnnotations
+{
+public:
+ virtual ~HangAnnotations() {}
+
+ virtual void AddAnnotation(const nsAString& aName, const int32_t aData) = 0;
+ virtual void AddAnnotation(const nsAString& aName, const double aData) = 0;
+ virtual void AddAnnotation(const nsAString& aName, const nsAString& aData) = 0;
+ virtual void AddAnnotation(const nsAString& aName, const nsACString& aData) = 0;
+ virtual void AddAnnotation(const nsAString& aName, const bool aData) = 0;
+
+ class Enumerator
+ {
+ public:
+ virtual ~Enumerator() {}
+ virtual bool Next(nsAString& aOutName, nsAString& aOutValue) = 0;
+ };
+
+ virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
+ virtual bool IsEmpty() const = 0;
+ virtual UniquePtr<Enumerator> GetEnumerator() = 0;
+};
+
+typedef UniquePtr<HangAnnotations> HangAnnotationsPtr;
+typedef Vector<HangAnnotationsPtr> HangAnnotationsVector;
+
+class Annotator
+{
+public:
+ /**
+ * NB: This function is always called by the HangMonitor thread.
+ * Plan accordingly.
+ */
+ virtual void AnnotateHang(HangAnnotations& aAnnotations) = 0;
+};
+
+/**
+ * Registers an Annotator to be called when a hang is detected.
+ * @param aAnnotator Reference to an object that implements the
+ * HangMonitor::Annotator interface.
+ */
+void RegisterAnnotator(Annotator& aAnnotator);
+
+/**
+ * Registers an Annotator that was previously registered via RegisterAnnotator.
+ * @param aAnnotator Reference to an object that implements the
+ * HangMonitor::Annotator interface.
+ */
+void UnregisterAnnotator(Annotator& aAnnotator);
+
+/**
+ * Gathers annotations. This function should be called by ChromeHangs.
+ * @return UniquePtr to HangAnnotations object or nullptr if none.
+ */
+HangAnnotationsPtr ChromeHangAnnotatorCallout();
+
+namespace Observer {
+
+class Annotators
+{
+public:
+ Annotators();
+ ~Annotators();
+
+ bool Register(Annotator& aAnnotator);
+ bool Unregister(Annotator& aAnnotator);
+
+ HangAnnotationsPtr GatherAnnotations();
+
+private:
+ Mutex mMutex;
+ std::set<Annotator*> mAnnotators;
+};
+
+} // namespace Observer
+
+} // namespace HangMonitor
+} // namespace mozilla
+
+#endif // mozilla_HangAnnotations_h