mz_alloc/lib.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Chooses a global memory allocator based on Cargo features.
11
12use mz_ore::metrics::MetricsRegistry;
13
14#[cfg(all(feature = "jemalloc", not(miri)))]
15#[global_allocator]
16static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
17
18/// Registers metrics for the global allocator into the provided registry.
19///
20/// What metrics are registered varies by platform. Not all platforms use
21/// allocators that support metrics.
22#[cfg(any(not(feature = "jemalloc"), miri))]
23#[allow(clippy::unused_async)]
24pub async fn register_metrics_into(_: &MetricsRegistry) {
25 // No-op on platforms that don't use jemalloc.
26}
27
28/// Registers metrics for the global allocator into the provided registry.
29///
30/// What metrics are registered varies by platform. Not all platforms use
31/// allocators that support metrics.
32#[cfg(all(feature = "jemalloc", not(miri)))]
33pub async fn register_metrics_into(registry: &MetricsRegistry) {
34 mz_prof::jemalloc::JemallocMetrics::register_into(registry).await;
35}