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/. */
7 #ifndef mozilla_MemoryTelemetry_h
8 #define mozilla_MemoryTelemetry_h
10 #include "mozilla/TimeStamp.h"
11 #include "mozilla/Result.h"
12 #include "nsIObserver.h"
15 #include "nsWeakReference.h"
24 enum class ResponseRejectReason
;
28 * Periodically gathers memory usage metrics after cycle collection, and
29 * populates telemetry histograms with their values.
31 class MemoryTelemetry final
: public nsIObserver
,
32 public nsSupportsWeakReference
{
37 static MemoryTelemetry
& Get();
39 nsresult
GatherReports(
40 const std::function
<void()>& aCompletionCallback
= nullptr);
43 * Does expensive initialization, which should happen only after startup has
44 * completed, and the event loop is idle.
46 nsresult
DelayedInit();
53 ~MemoryTelemetry() = default;
57 static Result
<uint32_t, nsresult
> GetOpenTabsCount();
59 void GatherTotalMemory();
60 nsresult
FinishGatheringTotalMemory(int64_t aTotalMemory
,
61 const nsTArray
<int64_t>& aChildSizes
);
63 nsCOMPtr
<nsIEventTarget
> mThreadPool
;
65 bool mGatheringTotalMemory
= false;
67 TimeStamp mLastPoll
{};
70 } // namespace mozilla
72 #endif // defined mozilla_MemoryTelemetry_h