improve alloc stats interface; fix admin command formatting
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
2a304c2b6c
commit
16e76d45cb
5 changed files with 20 additions and 24 deletions
|
@ -1,9 +1,9 @@
|
|||
//! Default allocator with no special features
|
||||
|
||||
/// Always returns the empty string
|
||||
/// Always returns None
|
||||
#[must_use]
|
||||
pub fn memory_stats() -> String { String::default() }
|
||||
pub fn memory_stats() -> Option<String> { None }
|
||||
|
||||
/// Always returns the empty string
|
||||
/// Always returns None
|
||||
#[must_use]
|
||||
pub fn memory_usage() -> String { String::default() }
|
||||
pub fn memory_usage() -> Option<String> { None }
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage() -> String {
|
||||
String::default() //TODO: get usage
|
||||
}
|
||||
//TODO: get usage
|
||||
pub fn memory_usage() -> Option<string> { None }
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_stats() -> String { "Extended statistics are not available from hardened_malloc.".to_owned() }
|
||||
pub fn memory_stats() -> Option<String> {
|
||||
Some("Extended statistics are not available from hardened_malloc.".to_owned())
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use tikv_jemallocator as jemalloc;
|
|||
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_usage() -> String {
|
||||
pub fn memory_usage() -> Option<String> {
|
||||
use mallctl::stats;
|
||||
|
||||
let mibs = |input: Result<usize, mallctl::Error>| {
|
||||
|
@ -27,14 +27,14 @@ pub fn memory_usage() -> String {
|
|||
let metadata = mibs(stats::metadata::read());
|
||||
let resident = mibs(stats::resident::read());
|
||||
let retained = mibs(stats::retained::read());
|
||||
format!(
|
||||
Some(format!(
|
||||
"allocated: {allocated:.2} MiB\nactive: {active:.2} MiB\nmapped: {mapped:.2} MiB\nmetadata: {metadata:.2} \
|
||||
MiB\nresident: {resident:.2} MiB\nretained: {retained:.2} MiB\n"
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn memory_stats() -> String {
|
||||
pub fn memory_stats() -> Option<String> {
|
||||
const MAX_LENGTH: usize = 65536 - 4096;
|
||||
|
||||
let opts_s = "d";
|
||||
|
@ -51,7 +51,7 @@ pub fn memory_stats() -> String {
|
|||
unsafe { ffi::malloc_stats_print(Some(malloc_stats_cb), opaque, opts_p) };
|
||||
|
||||
str.truncate(MAX_LENGTH);
|
||||
format!("<pre><code>{str}</code></pre>")
|
||||
Some(format!("<pre><code>{str}</code></pre>"))
|
||||
}
|
||||
|
||||
extern "C" fn malloc_stats_cb(opaque: *mut c_void, msg: *const c_char) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue