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 += [
|
EXPORTS += [
|
||||||
"malloc_decls.h",
|
"malloc_decls.h",
|
||||||
|
"mozjemalloc_profiling.h",
|
||||||
"mozjemalloc_types.h",
|
"mozjemalloc_types.h",
|
||||||
"mozmemory.h",
|
"mozmemory.h",
|
||||||
"mozmemory_utils.h",
|
"mozmemory_utils.h",
|
||||||
@@ -72,3 +73,4 @@ TEST_DIRS += ["test"]
|
|||||||
|
|
||||||
if CONFIG["NIGHTLY_BUILD"]:
|
if CONFIG["NIGHTLY_BUILD"]:
|
||||||
DEFINES["NON_RANDOM_ARENA_IDS"] = True
|
DEFINES["NON_RANDOM_ARENA_IDS"] = True
|
||||||
|
DEFINES["MOZJEMALLOC_PROFILING_CALLBACKS"] = True
|
||||||
|
|||||||
@@ -124,6 +124,7 @@
|
|||||||
#include "mozmemory_wrap.h"
|
#include "mozmemory_wrap.h"
|
||||||
#include "mozjemalloc.h"
|
#include "mozjemalloc.h"
|
||||||
#include "mozjemalloc_types.h"
|
#include "mozjemalloc_types.h"
|
||||||
|
#include "mozjemalloc_profiling.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
@@ -642,6 +643,10 @@ static Atomic<size_t> gRecycledSize;
|
|||||||
|
|
||||||
static size_t opt_dirty_max = DIRTY_MAX_DEFAULT;
|
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.
|
// Return the smallest chunk multiple that is >= s.
|
||||||
#define CHUNK_CEILING(s) (((s) + kChunkSizeMask) & ~kChunkSizeMask)
|
#define CHUNK_CEILING(s) (((s) + kChunkSizeMask) & ~kChunkSizeMask)
|
||||||
|
|
||||||
@@ -2177,6 +2182,16 @@ void* MozVirtualAlloc(void* lpAddress, size_t dwSize, uint32_t flAllocationType,
|
|||||||
|
|
||||||
#endif // XP_WIN
|
#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) {
|
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()
|
DisableStlWrapping()
|
||||||
|
|
||||||
include("/mozglue/build/replace_malloc.mozbuild")
|
include("/mozglue/build/replace_malloc.mozbuild")
|
||||||
|
include("/mozglue/misc/timestamp.mozbuild")
|
||||||
|
|||||||
@@ -48,12 +48,9 @@ SOURCES += [
|
|||||||
"Debug.cpp",
|
"Debug.cpp",
|
||||||
"LoggingCore.cpp",
|
"LoggingCore.cpp",
|
||||||
"MmapFaultHandler.cpp",
|
"MmapFaultHandler.cpp",
|
||||||
"Now.cpp",
|
|
||||||
"Printf.cpp",
|
"Printf.cpp",
|
||||||
"SIMD.cpp",
|
"SIMD.cpp",
|
||||||
"StackWalk.cpp",
|
"StackWalk.cpp",
|
||||||
"TimeStamp.cpp",
|
|
||||||
"Uptime.cpp",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if CONFIG["TARGET_CPU"].startswith("x86"):
|
if CONFIG["TARGET_CPU"].startswith("x86"):
|
||||||
@@ -94,7 +91,6 @@ if CONFIG["OS_ARCH"] == "WINNT":
|
|||||||
]
|
]
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
"GetKnownFolderPath.cpp",
|
"GetKnownFolderPath.cpp",
|
||||||
"TimeStamp_windows.cpp",
|
|
||||||
"WindowsDiagnostics.cpp",
|
"WindowsDiagnostics.cpp",
|
||||||
"WindowsDllMain.cpp",
|
"WindowsDllMain.cpp",
|
||||||
"WindowsDpiInitialization.cpp",
|
"WindowsDpiInitialization.cpp",
|
||||||
@@ -112,17 +108,6 @@ if CONFIG["OS_ARCH"] == "WINNT":
|
|||||||
"PreXULSkeletonUI.cpp",
|
"PreXULSkeletonUI.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
elif CONFIG["OS_ARCH"] == "Darwin":
|
|
||||||
SOURCES += [
|
|
||||||
"TimeStamp_darwin.cpp",
|
|
||||||
]
|
|
||||||
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
|
|
||||||
SOURCES += [
|
|
||||||
"TimeStamp_posix.cpp",
|
|
||||||
]
|
|
||||||
elif CONFIG["COMPILE_ENVIRONMENT"]:
|
|
||||||
error("No TimeStamp implementation on this platform. Build will not succeed")
|
|
||||||
|
|
||||||
if CONFIG["OS_ARCH"] == "WINNT":
|
if CONFIG["OS_ARCH"] == "WINNT":
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
"ConditionVariable_windows.cpp",
|
"ConditionVariable_windows.cpp",
|
||||||
@@ -157,3 +142,5 @@ if CONFIG["CC_TYPE"] in ("clang", "clang-cl"):
|
|||||||
|
|
||||||
for var in ("MOZ_APP_BASENAME", "MOZ_APP_VENDOR"):
|
for var in ("MOZ_APP_BASENAME", "MOZ_APP_VENDOR"):
|
||||||
DEFINES[var] = '"%s"' % CONFIG[var]
|
DEFINES[var] = '"%s"' % CONFIG[var]
|
||||||
|
|
||||||
|
include("/mozglue/misc/timestamp.mozbuild")
|
||||||
|
|||||||
25
mozglue/misc/timestamp.mozbuild
Normal file
25
mozglue/misc/timestamp.mozbuild
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||||
|
# vim: set filetype=python:
|
||||||
|
# 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/.
|
||||||
|
|
||||||
|
SOURCES += [
|
||||||
|
"/mozglue/misc/Now.cpp",
|
||||||
|
"/mozglue/misc/TimeStamp.cpp",
|
||||||
|
"/mozglue/misc/Uptime.cpp",
|
||||||
|
]
|
||||||
|
if CONFIG["OS_TARGET"] == "WINNT":
|
||||||
|
SOURCES += [
|
||||||
|
"/mozglue/misc/TimeStamp_windows.cpp",
|
||||||
|
]
|
||||||
|
elif CONFIG["OS_TARGET"] == "Darwin":
|
||||||
|
SOURCES += [
|
||||||
|
"/mozglue/misc/TimeStamp_darwin.cpp",
|
||||||
|
]
|
||||||
|
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
|
||||||
|
SOURCES += [
|
||||||
|
"/mozglue/misc/TimeStamp_posix.cpp",
|
||||||
|
]
|
||||||
|
elif CONFIG["COMPILE_ENVIRONMENT"]:
|
||||||
|
error("No TimeStamp implementation on this platform. Build will not succeed")
|
||||||
Reference in New Issue
Block a user