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/Maybe.h"
12 #include "mozilla/Result.h"
13 #include "nsIObserver.h"
16 #include "nsWeakReference.h"
25 enum class ResponseRejectReason
;
29 * Periodically gathers memory usage metrics after cycle collection, and
30 * populates telemetry histograms with their values.
32 class MemoryTelemetry final
: public nsIObserver
,
33 public nsSupportsWeakReference
{
38 static MemoryTelemetry
& Get();
40 nsresult
GatherReports(
41 const std::function
<void()>& aCompletionCallback
= nullptr);
44 * Called to signal that we can begin collecting telemetry.
49 * Notify that the browser is active and telemetry should be recorded soon.
58 ~MemoryTelemetry() = default;
62 static Result
<uint32_t, nsresult
> GetOpenTabsCount();
64 void GatherTotalMemory();
65 nsresult
FinishGatheringTotalMemory(Maybe
<int64_t> aTotalMemory
,
66 const nsTArray
<int64_t>& aChildSizes
);
68 nsCOMPtr
<nsIEventTarget
> mThreadPool
;
70 bool mGatheringTotalMemory
= false;
73 TimeStamp mLastPoke
{};
74 nsCOMPtr
<nsITimer
> mTimer
;
76 // True if startup is finished and it's okay to start gathering telemetry.
80 } // namespace mozilla
82 #endif // defined mozilla_MemoryTelemetry_h