12
12
// FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias`
13
13
14
14
use intrinsics:: { abort, cttz32} ;
15
- use libc:: { c_int, c_void, size_t} ;
16
- use ptr:: RawPtr ;
15
+ use libc:: { c_char, c_int, c_void, size_t} ;
16
+ use ptr:: { RawPtr , mut_null, null} ;
17
+ use option:: { None , Option } ;
17
18
18
19
#[ link( name = "jemalloc" , kind = "static" ) ]
19
20
extern {
@@ -22,6 +23,9 @@ extern {
22
23
fn je_xallocx ( ptr : * mut c_void , size : size_t , extra : size_t , flags : c_int ) -> size_t ;
23
24
fn je_dallocx ( ptr : * mut c_void , flags : c_int ) ;
24
25
fn je_nallocx ( size : size_t , flags : c_int ) -> size_t ;
26
+ fn je_malloc_stats_print ( write_cb : Option < extern "C" fn ( cbopaque : * mut c_void , * c_char ) > ,
27
+ cbopaque : * mut c_void ,
28
+ opts : * c_char ) ;
25
29
}
26
30
27
31
// -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough
@@ -99,6 +103,16 @@ pub fn usable_size(size: uint, align: uint) -> uint {
99
103
unsafe { je_nallocx ( size as size_t , mallocx_align ( align) ) as uint }
100
104
}
101
105
106
+ /// Print implementation-defined allocator statistics.
107
+ ///
108
+ /// These statistics may be inconsistent if other threads use the allocator during the call.
109
+ #[ unstable]
110
+ pub fn stats_print ( ) {
111
+ unsafe {
112
+ je_malloc_stats_print ( None , mut_null ( ) , null ( ) )
113
+ }
114
+ }
115
+
102
116
/// The allocator for unique pointers.
103
117
#[ cfg( stage0) ]
104
118
#[ lang="exchange_malloc" ]
0 commit comments