From 86cb97b7e200274be967d97bb51b7797136c1f2a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 31 Mar 2015 15:03:56 -0600 Subject: [PATCH] servo: Merge #5441 - Use usize rather than u64 in MemoryReport (from servo:heap-unclassified); r=jdm Source-Repo: https://github.com/servo/servo Source-Revision: 8976bbfe7d8fa061ee7270e4b3553f7fde6050e6 --- servo/components/layout/layout_task.rs | 2 +- servo/components/profile/mem.rs | 49 ++++++++++--------- .../rust-task_info/src/task_basic_info.rs | 32 ++++++------ servo/support/rust-task_info/src/task_info.c | 4 +- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/servo/components/layout/layout_task.rs b/servo/components/layout/layout_task.rs index 4016c3173f8f..c61f84cf0666 100644 --- a/servo/components/layout/layout_task.rs +++ b/servo/components/layout/layout_task.rs @@ -508,7 +508,7 @@ impl LayoutTask { let stacking_context = rw_data.stacking_context.as_ref(); reports.push(Report { path: path!["pages", format!("url({})", self.url), "display-list"], - size: stacking_context.map_or(0, |sc| sc.heap_size_of_children() as u64), + size: stacking_context.map_or(0, |sc| sc.heap_size_of_children()), }); reports_chan.send(reports); diff --git a/servo/components/profile/mem.rs b/servo/components/profile/mem.rs index 8e2ef614ed6d..38e4eb7088d0 100644 --- a/servo/components/profile/mem.rs +++ b/servo/components/profile/mem.rs @@ -32,12 +32,13 @@ macro_rules! path { }} } +/// A single memory-related measurement. pub struct Report { /// The identifying path for this report. pub path: Vec, /// The size, in bytes. - pub size: u64, + pub size: usize, } /// A channel through which memory reports can be sent. @@ -208,7 +209,7 @@ impl Profiler { struct ReportsTree { /// For leaf nodes, this is the sum of the sizes of all reports that mapped to this location. /// For interior nodes, this is the sum of the sizes of all its child nodes. - size: u64, + size: usize, /// For leaf nodes, this is the count of all reports that mapped to this location. /// For interor nodes, this is always zero. @@ -243,7 +244,7 @@ impl ReportsTree { } // Insert the path and size into the tree, adding any nodes as necessary. - fn insert(&mut self, path: &[String], size: u64) { + fn insert(&mut self, path: &[String], size: usize) { let mut t: &mut ReportsTree = self; for path_seg in path.iter() { let i = match t.find_child(&path_seg) { @@ -264,7 +265,7 @@ impl ReportsTree { // Fill in sizes for interior nodes. Should only be done once all the reports have been // inserted. - fn compute_interior_node_sizes(&mut self) -> u64 { + fn compute_interior_node_sizes(&mut self) -> usize { if !self.children.is_empty() { // Interior node. Derive its size from its children. if self.size != 0 { @@ -313,7 +314,7 @@ impl ReportsForest { } // Insert the path and size into the forest, adding any trees and nodes as necessary. - fn insert(&mut self, path: &[String], size: u64) { + fn insert(&mut self, path: &[String], size: usize) { // Get the right tree, creating it if necessary. if !self.trees.contains_key(&path[0]) { self.trees.insert(path[0].clone(), ReportsTree::new(path[0].clone())); @@ -440,7 +441,7 @@ mod system_reporter { } #[cfg(target_os="linux")] - fn get_system_heap_allocated() -> Option { + fn get_system_heap_allocated() -> Option { let mut info: struct_mallinfo; unsafe { info = mallinfo(); @@ -449,11 +450,11 @@ mod system_reporter { // would suffice, but that only gets the small allocations that are put in // the brk heap. We need |hblkhd| as well to get the larger allocations // that are mmapped. - Some((info.hblkhd + info.uordblks) as u64) + Some((info.hblkhd + info.uordblks) as usize) } #[cfg(not(target_os="linux"))] - fn get_system_heap_allocated() -> Option { + fn get_system_heap_allocated() -> Option { None } @@ -462,7 +463,7 @@ mod system_reporter { newp: *mut c_void, newlen: size_t) -> c_int; } - fn get_jemalloc_stat(value_name: &str) -> Option { + fn get_jemalloc_stat(value_name: &str) -> Option { // Before we request the measurement of interest, we first send an "epoch" // request. Without that jemalloc gives cached statistics(!) which can be // highly inaccurate. @@ -494,7 +495,7 @@ mod system_reporter { return None; } - Some(value as u64) + Some(value as usize) } // Like std::macros::try!, but for Option<>. @@ -503,7 +504,7 @@ mod system_reporter { ); #[cfg(target_os="linux")] - fn get_proc_self_statm_field(field: usize) -> Option { + fn get_proc_self_statm_field(field: usize) -> Option { use std::fs::File; use std::io::Read; @@ -511,42 +512,42 @@ mod system_reporter { let mut contents = String::new(); option_try!(f.read_to_string(&mut contents).ok()); let s = option_try!(contents.words().nth(field)); - let npages = option_try!(s.parse::().ok()); - Some(npages * (::std::env::page_size() as u64)) + let npages = option_try!(s.parse::().ok()); + Some(npages * ::std::env::page_size()) } #[cfg(target_os="linux")] - fn get_vsize() -> Option { + fn get_vsize() -> Option { get_proc_self_statm_field(0) } #[cfg(target_os="linux")] - fn get_resident() -> Option { + fn get_resident() -> Option { get_proc_self_statm_field(1) } #[cfg(target_os="macos")] - fn get_vsize() -> Option { + fn get_vsize() -> Option { virtual_size() } #[cfg(target_os="macos")] - fn get_resident() -> Option { + fn get_resident() -> Option { resident_size() } #[cfg(not(any(target_os="linux", target_os = "macos")))] - fn get_vsize() -> Option { + fn get_vsize() -> Option { None } #[cfg(not(any(target_os="linux", target_os = "macos")))] - fn get_resident() -> Option { + fn get_resident() -> Option { None } #[cfg(target_os="linux")] - fn get_resident_segments() -> Vec<(String, u64)> { + fn get_resident_segments() -> Vec<(String, usize)> { use regex::Regex; use std::collections::HashMap; use std::collections::hash_map::Entry; @@ -575,7 +576,7 @@ mod system_reporter { let rss_re = Regex::new(r"^Rss: +(\d+) kB").unwrap(); // We record each segment's resident size. - let mut seg_map: HashMap = HashMap::new(); + let mut seg_map: HashMap = HashMap::new(); #[derive(PartialEq)] enum LookingFor { Segment, Rss } @@ -620,7 +621,7 @@ mod system_reporter { Some(cap) => cap, None => continue, }; - let rss = cap.at(1).unwrap().parse::().unwrap() * 1024; + let rss = cap.at(1).unwrap().parse::().unwrap() * 1024; if rss > 0 { // Aggregate small segments into "other". @@ -639,7 +640,7 @@ mod system_reporter { } } - let mut segs: Vec<(String, u64)> = seg_map.into_iter().collect(); + let mut segs: Vec<(String, usize)> = seg_map.into_iter().collect(); // Note that the sum of all these segments' RSS values differs from the "resident" measurement // obtained via /proc//statm in get_resident(). It's unclear why this difference occurs; @@ -650,7 +651,7 @@ mod system_reporter { } #[cfg(not(target_os="linux"))] - fn get_resident_segments() -> Vec<(String, u64)> { + fn get_resident_segments() -> Vec<(String, usize)> { vec![] } } diff --git a/servo/support/rust-task_info/src/task_basic_info.rs b/servo/support/rust-task_info/src/task_basic_info.rs index 85fd84954edd..78efca0fd4f6 100644 --- a/servo/support/rust-task_info/src/task_basic_info.rs +++ b/servo/support/rust-task_info/src/task_basic_info.rs @@ -10,32 +10,30 @@ //! Interface to the measurements in the task_basic_info struct, gathered by //! invoking `task_info()` with the `TASK_BASIC_INFO` flavor. -use libc::{c_int,uint64_t}; +use libc::{c_int, size_t}; /// Obtains task_basic_info::virtual_size. -pub fn virtual_size() -> Option { - let mut virtual_size: u64 = 0; - let mut rv; - unsafe { - rv = TaskBasicInfoVirtualSize(&mut virtual_size); - } - if rv == 0 { Some(virtual_size) } else { None } +pub fn virtual_size() -> Option { + let mut virtual_size: size_t = 0; + let rv = unsafe { + TaskBasicInfoVirtualSize(&mut virtual_size) + }; + if rv == 0 { Some(virtual_size as usize) } else { None } } /// Obtains task_basic_info::resident_size. -pub fn resident_size() -> Option { - let mut resident_size: u64 = 0; - let mut rv; - unsafe { - rv = TaskBasicInfoResidentSize(&mut resident_size); - } - if rv == 0 { Some(resident_size) } else { None } +pub fn resident_size() -> Option { + let mut resident_size: size_t = 0; + let rv = unsafe { + TaskBasicInfoResidentSize(&mut resident_size) + }; + if rv == 0 { Some(resident_size as usize) } else { None } } #[link(name = "task_info", kind = "static")] extern { - fn TaskBasicInfoVirtualSize(virtual_size: *mut uint64_t) -> c_int; - fn TaskBasicInfoResidentSize(resident_size: *mut uint64_t) -> c_int; + fn TaskBasicInfoVirtualSize(virtual_size: *mut size_t) -> c_int; + fn TaskBasicInfoResidentSize(resident_size: *mut size_t) -> c_int; } #[cfg(test)] diff --git a/servo/support/rust-task_info/src/task_info.c b/servo/support/rust-task_info/src/task_info.c index e8f59082609d..476551c063b2 100644 --- a/servo/support/rust-task_info/src/task_info.c +++ b/servo/support/rust-task_info/src/task_info.c @@ -20,7 +20,7 @@ TaskBasicInfo(struct task_basic_info* info) } int -TaskBasicInfoVirtualSize(int64_t *virtualSize) +TaskBasicInfoVirtualSize(size_t* virtualSize) { struct task_basic_info ti; int rv = TaskBasicInfo(&ti); @@ -29,7 +29,7 @@ TaskBasicInfoVirtualSize(int64_t *virtualSize) } int -TaskBasicInfoResidentSize(int64_t *residentSize) +TaskBasicInfoResidentSize(size_t* residentSize) { struct task_basic_info ti; int rv = TaskBasicInfo(&ti);