Improve mem precision in sys/context
This commit is contained in:
@@ -79,6 +79,7 @@ pub fn get_all_contexts(mut token: LockToken<'_, L1>) -> Vec<Arc<ContextLock>> {
|
||||
.iter()
|
||||
.filter_map(|block| unsafe { block.load(Ordering::Relaxed).as_ref() })
|
||||
{
|
||||
// TODO: When load balancer implemented, contexts need to be locked altogether
|
||||
// TODO: Lock token violation, downgrade this to L2 later
|
||||
let contexts = unsafe { &block.contexts.reupgradeable_read(token.token()) };
|
||||
all_contexts.extend(contexts.iter().filter_map(|x| x.upgrade()));
|
||||
|
||||
+31
-11
@@ -15,7 +15,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
|
||||
let mut rows = Vec::new();
|
||||
{
|
||||
let mut contexts = percpu::get_all_contexts(token.downgrade());
|
||||
let contexts = percpu::get_all_contexts(token.downgrade());
|
||||
for context_ref in contexts {
|
||||
let context = context_ref.read(token.token());
|
||||
let addr_space = context.addr_space().map(|a| a.clone());
|
||||
@@ -53,7 +53,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
|
||||
let mut stat_string = String::new();
|
||||
stat_string.push(match heap {
|
||||
Some((pages, is_kernel)) => {
|
||||
Some((_, is_kernel)) => {
|
||||
if is_kernel {
|
||||
'K'
|
||||
} else {
|
||||
@@ -99,15 +99,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
memory += heap;
|
||||
}
|
||||
|
||||
let memory_string = if memory >= 1024 * 1024 * 1024 {
|
||||
format!("{} GB", memory / 1024 / 1024 / 1024)
|
||||
} else if memory >= 1024 * 1024 {
|
||||
format!("{} MB", memory / 1024 / 1024)
|
||||
} else if memory >= 1024 {
|
||||
format!("{} KB", memory / 1024)
|
||||
} else {
|
||||
format!("{} B", memory)
|
||||
};
|
||||
let memory_string = format_bytes(memory);
|
||||
|
||||
rows.push((
|
||||
pid,
|
||||
@@ -153,3 +145,31 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
|
||||
Ok(string.into_bytes())
|
||||
}
|
||||
|
||||
fn format_bytes(memory: usize) -> String {
|
||||
const GB: usize = 1024 * 1024 * 1024;
|
||||
const MB: usize = 1024 * 1024;
|
||||
const KB: usize = 1024;
|
||||
|
||||
if memory > GB {
|
||||
format_bytes_inner(memory, GB, "GB")
|
||||
} else if memory > MB {
|
||||
format_bytes_inner(memory, MB, "MB")
|
||||
} else if memory > KB {
|
||||
format_bytes_inner(memory, KB, "KB")
|
||||
} else {
|
||||
format!("{memory} B")
|
||||
}
|
||||
}
|
||||
|
||||
fn format_bytes_inner(memory: usize, divisor: usize, suffix: &'static str) -> String {
|
||||
let mut s = format!("{}", memory / divisor);
|
||||
if s.len() == 1 {
|
||||
let _ = write!(s, ".{:02}", (memory % divisor) / (divisor / 100));
|
||||
} else if s.len() == 2 {
|
||||
let _ = write!(s, ".{:01}", (memory % divisor) / (divisor / 10));
|
||||
}
|
||||
|
||||
let _ = write!(s, " {suffix}");
|
||||
s
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
|
||||
'contexts: for context in percpu::get_all_contexts(token.token()) {
|
||||
let mut context_guard = context.read(token.token());
|
||||
let (context, mut token) = context_guard.token_split();
|
||||
let (context, token) = context_guard.token_split();
|
||||
let mut files_guard = context.files.read(token);
|
||||
let (files, mut token) = files_guard.token_split();
|
||||
writeln!(report, "'{}' {{", context.name).unwrap();
|
||||
@@ -70,7 +70,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result<Vec<u8>> {
|
||||
.map(|k| match k {
|
||||
scheme::Handle::SchemeCreationCapability => "SchemeCreationCapability",
|
||||
scheme::Handle::Scheme(KernelSchemes::Global(g)) => g.as_str(),
|
||||
scheme::Handle::Scheme(KernelSchemes::User(g)) => "[user]",
|
||||
scheme::Handle::Scheme(KernelSchemes::User(_)) => "[user]",
|
||||
scheme::Handle::Scheme(KernelSchemes::SchemeMgr) => "SchemeMgr",
|
||||
})
|
||||
.unwrap_or("[unknown]");
|
||||
|
||||
Reference in New Issue
Block a user