mirror of
https://github.com/servo/servo.git
synced 2025-06-22 08:08:59 +01:00
Use usize rather than u64 in MemoryReport.
I should have used usize in the first place.
This commit is contained in:
parent
c1cc31b9d6
commit
66902d2c90
4 changed files with 43 additions and 44 deletions
|
@ -480,7 +480,7 @@ impl LayoutTask {
|
||||||
let stacking_context = rw_data.stacking_context.as_ref();
|
let stacking_context = rw_data.stacking_context.as_ref();
|
||||||
reports.push(Report {
|
reports.push(Report {
|
||||||
path: path!["pages", format!("url({})", self.url), "display-list"],
|
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);
|
reports_chan.send(reports);
|
||||||
|
|
|
@ -32,12 +32,13 @@ macro_rules! path {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A single memory-related measurement.
|
||||||
pub struct Report {
|
pub struct Report {
|
||||||
/// The identifying path for this report.
|
/// The identifying path for this report.
|
||||||
pub path: Vec<String>,
|
pub path: Vec<String>,
|
||||||
|
|
||||||
/// The size, in bytes.
|
/// The size, in bytes.
|
||||||
pub size: u64,
|
pub size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A channel through which memory reports can be sent.
|
/// A channel through which memory reports can be sent.
|
||||||
|
@ -208,7 +209,7 @@ impl Profiler {
|
||||||
struct ReportsTree {
|
struct ReportsTree {
|
||||||
/// For leaf nodes, this is the sum of the sizes of all reports that mapped to this location.
|
/// 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.
|
/// 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 leaf nodes, this is the count of all reports that mapped to this location.
|
||||||
/// For interor nodes, this is always zero.
|
/// 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.
|
// 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;
|
let mut t: &mut ReportsTree = self;
|
||||||
for path_seg in path.iter() {
|
for path_seg in path.iter() {
|
||||||
let i = match t.find_child(&path_seg) {
|
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
|
// Fill in sizes for interior nodes. Should only be done once all the reports have been
|
||||||
// inserted.
|
// inserted.
|
||||||
fn compute_interior_node_sizes(&mut self) -> u64 {
|
fn compute_interior_node_sizes(&mut self) -> usize {
|
||||||
if !self.children.is_empty() {
|
if !self.children.is_empty() {
|
||||||
// Interior node. Derive its size from its children.
|
// Interior node. Derive its size from its children.
|
||||||
if self.size != 0 {
|
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.
|
// 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.
|
// Get the right tree, creating it if necessary.
|
||||||
if !self.trees.contains_key(&path[0]) {
|
if !self.trees.contains_key(&path[0]) {
|
||||||
self.trees.insert(path[0].clone(), ReportsTree::new(path[0].clone()));
|
self.trees.insert(path[0].clone(), ReportsTree::new(path[0].clone()));
|
||||||
|
@ -440,7 +441,7 @@ mod system_reporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_system_heap_allocated() -> Option<u64> {
|
fn get_system_heap_allocated() -> Option<usize> {
|
||||||
let mut info: struct_mallinfo;
|
let mut info: struct_mallinfo;
|
||||||
unsafe {
|
unsafe {
|
||||||
info = mallinfo();
|
info = mallinfo();
|
||||||
|
@ -449,11 +450,11 @@ mod system_reporter {
|
||||||
// would suffice, but that only gets the small allocations that are put in
|
// 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
|
// the brk heap. We need |hblkhd| as well to get the larger allocations
|
||||||
// that are mmapped.
|
// that are mmapped.
|
||||||
Some((info.hblkhd + info.uordblks) as u64)
|
Some((info.hblkhd + info.uordblks) as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os="linux"))]
|
#[cfg(not(target_os="linux"))]
|
||||||
fn get_system_heap_allocated() -> Option<u64> {
|
fn get_system_heap_allocated() -> Option<usize> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +463,7 @@ mod system_reporter {
|
||||||
newp: *mut c_void, newlen: size_t) -> c_int;
|
newp: *mut c_void, newlen: size_t) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_jemalloc_stat(value_name: &str) -> Option<u64> {
|
fn get_jemalloc_stat(value_name: &str) -> Option<usize> {
|
||||||
// Before we request the measurement of interest, we first send an "epoch"
|
// Before we request the measurement of interest, we first send an "epoch"
|
||||||
// request. Without that jemalloc gives cached statistics(!) which can be
|
// request. Without that jemalloc gives cached statistics(!) which can be
|
||||||
// highly inaccurate.
|
// highly inaccurate.
|
||||||
|
@ -494,7 +495,7 @@ mod system_reporter {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(value as u64)
|
Some(value as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like std::macros::try!, but for Option<>.
|
// Like std::macros::try!, but for Option<>.
|
||||||
|
@ -503,7 +504,7 @@ mod system_reporter {
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_proc_self_statm_field(field: usize) -> Option<u64> {
|
fn get_proc_self_statm_field(field: usize) -> Option<usize> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
|
@ -511,42 +512,42 @@ mod system_reporter {
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
option_try!(f.read_to_string(&mut contents).ok());
|
option_try!(f.read_to_string(&mut contents).ok());
|
||||||
let s = option_try!(contents.words().nth(field));
|
let s = option_try!(contents.words().nth(field));
|
||||||
let npages = option_try!(s.parse::<u64>().ok());
|
let npages = option_try!(s.parse::<usize>().ok());
|
||||||
Some(npages * (::std::env::page_size() as u64))
|
Some(npages * ::std::env::page_size())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_vsize() -> Option<u64> {
|
fn get_vsize() -> Option<usize> {
|
||||||
get_proc_self_statm_field(0)
|
get_proc_self_statm_field(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_resident() -> Option<u64> {
|
fn get_resident() -> Option<usize> {
|
||||||
get_proc_self_statm_field(1)
|
get_proc_self_statm_field(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="macos")]
|
#[cfg(target_os="macos")]
|
||||||
fn get_vsize() -> Option<u64> {
|
fn get_vsize() -> Option<usize> {
|
||||||
virtual_size()
|
virtual_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="macos")]
|
#[cfg(target_os="macos")]
|
||||||
fn get_resident() -> Option<u64> {
|
fn get_resident() -> Option<usize> {
|
||||||
resident_size()
|
resident_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os="linux", target_os = "macos")))]
|
#[cfg(not(any(target_os="linux", target_os = "macos")))]
|
||||||
fn get_vsize() -> Option<u64> {
|
fn get_vsize() -> Option<usize> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os="linux", target_os = "macos")))]
|
#[cfg(not(any(target_os="linux", target_os = "macos")))]
|
||||||
fn get_resident() -> Option<u64> {
|
fn get_resident() -> Option<usize> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os="linux")]
|
#[cfg(target_os="linux")]
|
||||||
fn get_resident_segments() -> Vec<(String, u64)> {
|
fn get_resident_segments() -> Vec<(String, usize)> {
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
@ -575,7 +576,7 @@ mod system_reporter {
|
||||||
let rss_re = Regex::new(r"^Rss: +(\d+) kB").unwrap();
|
let rss_re = Regex::new(r"^Rss: +(\d+) kB").unwrap();
|
||||||
|
|
||||||
// We record each segment's resident size.
|
// We record each segment's resident size.
|
||||||
let mut seg_map: HashMap<String, u64> = HashMap::new();
|
let mut seg_map: HashMap<String, usize> = HashMap::new();
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum LookingFor { Segment, Rss }
|
enum LookingFor { Segment, Rss }
|
||||||
|
@ -620,7 +621,7 @@ mod system_reporter {
|
||||||
Some(cap) => cap,
|
Some(cap) => cap,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
let rss = cap.at(1).unwrap().parse::<u64>().unwrap() * 1024;
|
let rss = cap.at(1).unwrap().parse::<usize>().unwrap() * 1024;
|
||||||
|
|
||||||
if rss > 0 {
|
if rss > 0 {
|
||||||
// Aggregate small segments into "other".
|
// 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
|
// Note that the sum of all these segments' RSS values differs from the "resident" measurement
|
||||||
// obtained via /proc/<pid>/statm in get_resident(). It's unclear why this difference occurs;
|
// obtained via /proc/<pid>/statm in get_resident(). It's unclear why this difference occurs;
|
||||||
|
@ -650,7 +651,7 @@ mod system_reporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os="linux"))]
|
#[cfg(not(target_os="linux"))]
|
||||||
fn get_resident_segments() -> Vec<(String, u64)> {
|
fn get_resident_segments() -> Vec<(String, usize)> {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,32 +10,30 @@
|
||||||
//! Interface to the measurements in the task_basic_info struct, gathered by
|
//! Interface to the measurements in the task_basic_info struct, gathered by
|
||||||
//! invoking `task_info()` with the `TASK_BASIC_INFO` flavor.
|
//! 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.
|
/// Obtains task_basic_info::virtual_size.
|
||||||
pub fn virtual_size() -> Option<u64> {
|
pub fn virtual_size() -> Option<usize> {
|
||||||
let mut virtual_size: u64 = 0;
|
let mut virtual_size: size_t = 0;
|
||||||
let mut rv;
|
let rv = unsafe {
|
||||||
unsafe {
|
TaskBasicInfoVirtualSize(&mut virtual_size)
|
||||||
rv = TaskBasicInfoVirtualSize(&mut virtual_size);
|
};
|
||||||
}
|
if rv == 0 { Some(virtual_size as usize) } else { None }
|
||||||
if rv == 0 { Some(virtual_size) } else { None }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains task_basic_info::resident_size.
|
/// Obtains task_basic_info::resident_size.
|
||||||
pub fn resident_size() -> Option<u64> {
|
pub fn resident_size() -> Option<usize> {
|
||||||
let mut resident_size: u64 = 0;
|
let mut resident_size: size_t = 0;
|
||||||
let mut rv;
|
let rv = unsafe {
|
||||||
unsafe {
|
TaskBasicInfoResidentSize(&mut resident_size)
|
||||||
rv = TaskBasicInfoResidentSize(&mut resident_size);
|
};
|
||||||
}
|
if rv == 0 { Some(resident_size as usize) } else { None }
|
||||||
if rv == 0 { Some(resident_size) } else { None }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "task_info", kind = "static")]
|
#[link(name = "task_info", kind = "static")]
|
||||||
extern {
|
extern {
|
||||||
fn TaskBasicInfoVirtualSize(virtual_size: *mut uint64_t) -> c_int;
|
fn TaskBasicInfoVirtualSize(virtual_size: *mut size_t) -> c_int;
|
||||||
fn TaskBasicInfoResidentSize(resident_size: *mut uint64_t) -> c_int;
|
fn TaskBasicInfoResidentSize(resident_size: *mut size_t) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -20,7 +20,7 @@ TaskBasicInfo(struct task_basic_info* info)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TaskBasicInfoVirtualSize(int64_t *virtualSize)
|
TaskBasicInfoVirtualSize(size_t* virtualSize)
|
||||||
{
|
{
|
||||||
struct task_basic_info ti;
|
struct task_basic_info ti;
|
||||||
int rv = TaskBasicInfo(&ti);
|
int rv = TaskBasicInfo(&ti);
|
||||||
|
@ -29,7 +29,7 @@ TaskBasicInfoVirtualSize(int64_t *virtualSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TaskBasicInfoResidentSize(int64_t *residentSize)
|
TaskBasicInfoResidentSize(size_t* residentSize)
|
||||||
{
|
{
|
||||||
struct task_basic_info ti;
|
struct task_basic_info ti;
|
||||||
int rv = TaskBasicInfo(&ti);
|
int rv = TaskBasicInfo(&ti);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue