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 #include "memory_counter.h"
9 #include "mozilla/UniquePtr.h"
10 #include "mozmemory.h"
12 #include "GeckoProfiler.h"
14 namespace mozilla::profiler
{
15 class MemoryCounter
: public BaseProfilerCount
{
18 : BaseProfilerCount("malloc", "Memory", "Amount of allocated memory") {};
20 virtual ~MemoryCounter() {
21 // The counter is removed by ActivePS::Destroy()
24 CountSample
Sample() override
{
25 jemalloc_stats_lite_t stats
;
27 jemalloc_stats_lite(&stats
);
29 CountSample sample
= {
30 .count
= int64_t(stats
.allocated_bytes
),
31 .number
= stats
.num_operations
,
39 UniquePtr
<BaseProfilerCount
> create_memory_counter() {
40 return MakeUnique
<MemoryCounter
>();
43 } // namespace mozilla::profiler