Bug 1928254 - pt 2. Add profiler callbacks for mozjemalloc r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D227441
This commit is contained in:
committed by
pbone@mozilla.com
parent
dd4278a7d5
commit
df279eb40e
@@ -6,6 +6,7 @@
|
||||
|
||||
EXPORTS += [
|
||||
"malloc_decls.h",
|
||||
"mozjemalloc_profiling.h",
|
||||
"mozjemalloc_types.h",
|
||||
"mozmemory.h",
|
||||
"mozmemory_utils.h",
|
||||
@@ -72,3 +73,4 @@ TEST_DIRS += ["test"]
|
||||
|
||||
if CONFIG["NIGHTLY_BUILD"]:
|
||||
DEFINES["NON_RANDOM_ARENA_IDS"] = True
|
||||
DEFINES["MOZJEMALLOC_PROFILING_CALLBACKS"] = True
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
#include "mozmemory_wrap.h"
|
||||
#include "mozjemalloc.h"
|
||||
#include "mozjemalloc_types.h"
|
||||
#include "mozjemalloc_profiling.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
@@ -642,6 +643,10 @@ static Atomic<size_t> gRecycledSize;
|
||||
|
||||
static size_t opt_dirty_max = DIRTY_MAX_DEFAULT;
|
||||
|
||||
#ifdef MOZJEMALLOC_PROFILING_CALLBACKS
|
||||
static MallocProfilerCallbacks* sCallbacks;
|
||||
#endif
|
||||
|
||||
// Return the smallest chunk multiple that is >= s.
|
||||
#define CHUNK_CEILING(s) (((s) + kChunkSizeMask) & ~kChunkSizeMask)
|
||||
|
||||
@@ -2177,6 +2182,16 @@ void* MozVirtualAlloc(void* lpAddress, size_t dwSize, uint32_t flAllocationType,
|
||||
|
||||
#endif // XP_WIN
|
||||
|
||||
#ifdef MOZJEMALLOC_PROFILING_CALLBACKS
|
||||
namespace mozilla {
|
||||
|
||||
void jemalloc_set_profiler_callbacks(MallocProfilerCallbacks* aCallbacks) {
|
||||
sCallbacks = aCallbacks;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
#endif
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
static inline void pages_decommit(void* aAddr, size_t aSize) {
|
||||
|
||||
43
memory/build/mozjemalloc_profiling.h
Normal file
43
memory/build/mozjemalloc_profiling.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*- 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 _MOZJEMALLOC_PROFILING_H
|
||||
#define _MOZJEMALLOC_PROFILING_H
|
||||
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozjemalloc_types.h"
|
||||
#include "mozmemory_wrap.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
struct PurgeStats {
|
||||
arena_id_t arena_id;
|
||||
const char* arena_label;
|
||||
const char* caller;
|
||||
size_t pages = 0;
|
||||
size_t system_calls = 0;
|
||||
|
||||
PurgeStats(arena_id_t aId, const char* aLabel, const char* aCaller)
|
||||
: arena_id(aId), arena_label(aLabel), caller(aCaller) {}
|
||||
};
|
||||
|
||||
#ifdef MOZJEMALLOC_PROFILING_CALLBACKS
|
||||
class MallocProfilerCallbacks {
|
||||
public:
|
||||
virtual ~MallocProfilerCallbacks() {}
|
||||
|
||||
using TS = mozilla::TimeStamp;
|
||||
|
||||
virtual void OnPurge(TS aStart, TS aEnd, const PurgeStats& aStats) = 0;
|
||||
};
|
||||
|
||||
MOZ_JEMALLOC_API void jemalloc_set_profiler_callbacks(
|
||||
MallocProfilerCallbacks* aCallbacks);
|
||||
#endif
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // ! _MOZJEMALLOC_PROFILING_H
|
||||
@@ -91,3 +91,4 @@ OS_LIBS += CONFIG["DL_LIBS"]
|
||||
DisableStlWrapping()
|
||||
|
||||
include("/mozglue/build/replace_malloc.mozbuild")
|
||||
include("/mozglue/misc/timestamp.mozbuild")
|
||||
|
||||
Reference in New Issue
Block a user