mozjemalloc_profiling.h (1782B)
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/. */ 6 7 #ifndef _MOZJEMALLOC_PROFILING_H 8 #define _MOZJEMALLOC_PROFILING_H 9 10 #include "mozilla/RefCounted.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/TimeStamp.h" 13 #include "mozjemalloc_types.h" 14 #include "mozmemory_wrap.h" 15 16 namespace mozilla { 17 18 struct PurgeStats { 19 arena_id_t arena_id; 20 const char* arena_label; 21 const char* caller; 22 23 // The number of previously-dirty pages that are now clean. 24 size_t pages_dirty = 0; 25 26 // The total number of pages that were cleaned (includes previously an pages). 27 size_t pages_total = 0; 28 29 // The number of pages that can't be purged because of alignment because 30 // of logical/hardware page alignment. 31 size_t pages_unpurgable = 0; 32 33 size_t system_calls = 0; 34 size_t chunks = 0; 35 36 PurgeStats(arena_id_t aId, const char* aLabel, const char* aCaller) 37 : arena_id(aId), arena_label(aLabel), caller(aCaller) {} 38 }; 39 40 #ifdef MOZJEMALLOC_PROFILING_CALLBACKS 41 class MallocProfilerCallbacks 42 : public external::AtomicRefCounted<MallocProfilerCallbacks> { 43 public: 44 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(MallocProfilerCallbacks) 45 46 virtual ~MallocProfilerCallbacks() {} 47 48 using TS = mozilla::TimeStamp; 49 50 virtual void OnPurge(TS aStart, TS aEnd, const PurgeStats& aStats, 51 ArenaPurgeResult aResult) = 0; 52 }; 53 54 MOZ_JEMALLOC_API void jemalloc_set_profiler_callbacks( 55 RefPtr<MallocProfilerCallbacks>&& aCallbacks); 56 #endif 57 58 } // namespace mozilla 59 60 #endif // ! _MOZJEMALLOC_PROFILING_H