@@ -42,6 +42,10 @@ xflags::xflags! {
4242 optional --mimalloc
4343 /// Use jemalloc allocator for server.
4444 optional --jemalloc
45+ // Enable memory profiling support.
46+ //
47+ // **Warning:** This will produce a slower build of rust-analyzer, use only for profiling.
48+ optional --enable-profiling
4549
4650 /// Install the proc-macro server.
4751 optional --proc-macro-server
@@ -67,6 +71,10 @@ xflags::xflags! {
6771 optional --mimalloc
6872 /// Use jemalloc allocator for server
6973 optional --jemalloc
74+ // Enable memory profiling support.
75+ //
76+ // **Warning:** This will produce a slower build of rust-analyzer, use only for profiling.
77+ optional --enable-profiling
7078 optional --client-patch-version version: String
7179 /// Use cargo-zigbuild
7280 optional --zig
@@ -125,6 +133,7 @@ pub struct Install {
125133 pub server : bool ,
126134 pub mimalloc : bool ,
127135 pub jemalloc : bool ,
136+ pub enable_profiling : bool ,
128137 pub proc_macro_server : bool ,
129138 pub dev_rel : bool ,
130139 pub force_always_assert : bool ,
@@ -143,6 +152,7 @@ pub struct Release {
143152pub struct Dist {
144153 pub mimalloc : bool ,
145154 pub jemalloc : bool ,
155+ pub enable_profiling : bool ,
146156 pub client_patch_version : Option < String > ,
147157 pub zig : bool ,
148158 pub pgo : Option < PgoTrainingCrate > ,
@@ -280,6 +290,7 @@ pub(crate) enum Malloc {
280290 System ,
281291 Mimalloc ,
282292 Jemalloc ,
293+ Dhat ,
283294}
284295
285296impl Malloc {
@@ -288,6 +299,7 @@ impl Malloc {
288299 Malloc :: System => & [ ] [ ..] ,
289300 Malloc :: Mimalloc => & [ "--features" , "mimalloc" ] ,
290301 Malloc :: Jemalloc => & [ "--features" , "jemalloc" ] ,
302+ Malloc :: Dhat => & [ "--features" , "dhat" ] ,
291303 }
292304 }
293305}
@@ -301,12 +313,15 @@ impl Install {
301313 Malloc :: Mimalloc
302314 } else if self . jemalloc {
303315 Malloc :: Jemalloc
316+ } else if self . enable_profiling {
317+ Malloc :: Dhat
304318 } else {
305319 Malloc :: System
306320 } ;
307321 Some ( ServerOpt {
308322 malloc,
309- dev_rel : self . dev_rel ,
323+ // Profiling requires debug information.
324+ dev_rel : self . dev_rel || self . enable_profiling ,
310325 pgo : self . pgo . clone ( ) ,
311326 force_always_assert : self . force_always_assert ,
312327 } )
@@ -331,6 +346,8 @@ impl Dist {
331346 Malloc :: Mimalloc
332347 } else if self . jemalloc {
333348 Malloc :: Jemalloc
349+ } else if self . enable_profiling {
350+ Malloc :: Dhat
334351 } else {
335352 Malloc :: System
336353 }
0 commit comments