Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upPass new method in CollectServoSizes to get size of ObjectPrivateVisitor #20430
Conversation
highfive
commented
Mar 26, 2018
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @nox (or someone else) soon. |
highfive
commented
Mar 26, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Mar 26, 2018
|
Please squash these commits as well. |
| @@ -199,6 +202,21 @@ pub fn init_service_workers(sw_senders: SWManagerSenders) { | |||
| ServiceWorkerManager::spawn_manager(sw_senders); | |||
| } | |||
|
|
|||
| #[no_mangle] | |||
| #[allow(unsafe_code)] | |||
| pub unsafe extern "C" fn MemoryReporter(obj: *mut JSObject) -> bool { | |||
This comment has been minimized.
This comment has been minimized.
| if obj.is_null() { | ||
| return false; | ||
| } | ||
| if is_platform_object(obj) || is_dom_proxy(obj) { |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 26, 2018
Member
This can be simplified to:
pub unsafe extern "C" fn MemoryReporter(obj: *mut JSObject) -> bool {
!obj.is_null() && (is_platform_object(obj) || is_dom_proxy(obj))
}| @@ -207,6 +225,8 @@ pub fn init() { | |||
| // Create the global vtables used by the (generated) DOM | |||
| // bindings to implement JS proxies. | |||
| RegisterBindings::RegisterProxyHandlers(); | |||
|
|
|||
| js::glue::InitializeMemoryReporter(serde::export::Some(MemoryReporter)); | |||
This comment has been minimized.
This comment has been minimized.
| #[no_mangle] | ||
| #[allow(unsafe_code)] | ||
| pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { | ||
| let dom_class_opt = get_dom_class(obj); |
This comment has been minimized.
This comment has been minimized.
| pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { | ||
| let dom_class_opt = get_dom_class(obj); | ||
|
|
||
| match dom_class_opt { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| match dom_class_opt { | ||
| Ok(v) => { | ||
| let pass_ptr = private_from_object(obj) as *const c_void; |
This comment has been minimized.
This comment has been minimized.
| match dom_class_opt { | ||
| Ok(v) => { | ||
| let pass_ptr = private_from_object(obj) as *const c_void; | ||
| if !(pass_ptr.is_null()) { |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 26, 2018
Member
Let's write this as:
if dom_object.is_null() {
return 0;
}
let mut ops = ...;
| let pass_ptr = private_from_object(obj) as *const c_void; | ||
| if !(pass_ptr.is_null()) { | ||
| let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None); | ||
| let _result = (v.malloc_size_of)(&mut ops, pass_ptr); |
This comment has been minimized.
This comment has been minimized.
| #[allow(unsafe_code)] | ||
| pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> { | ||
| let mut reports = vec![]; | ||
|
|
||
| unsafe { | ||
| let rt = JS_GetRuntime(cx); | ||
| let mut stats = ::std::mem::zeroed(); | ||
| if CollectServoSizes(rt, &mut stats) { | ||
| if CollectServoSizes(rt, &mut stats, serde::export::Some(get_size)) { |
This comment has been minimized.
This comment has been minimized.
| // malloc_enclosing_size_of function. | ||
| let mut ops = MallocSizeOfOps::new(::servo_allocator::usable_size, None, None); | ||
|
|
||
| for (_, document) in self.documents.borrow().iter() { |
This comment has been minimized.
This comment has been minimized.
|
I'm excited to see these changes almost ready! |
|
@jdm I rebased from the latest changes in master, updated according to your comments and squashed the commits. I saw one flag in the change view of cargo.toml which says no newline at end of file, is this something I need to change? |
|
No, that should be fine. |
| @@ -312,14 +315,33 @@ pub unsafe fn new_rt_and_cx() -> Runtime { | |||
| Runtime(runtime) | |||
| } | |||
|
|
|||
| #[no_mangle] | |||
| #[allow(unsafe_code)] | |||
| pub unsafe extern "C" fn get_size(obj: *mut JSObject) -> usize { | |||
This comment has been minimized.
This comment has been minimized.
| @@ -1581,30 +1579,11 @@ impl ScriptThread { | |||
|
|
|||
| fn collect_reports(&self, reports_chan: ReportsChan) { | |||
| let mut path_seg = String::from("url("); | |||
| let mut dom_tree_size = 0; | |||
| let mut reports = vec![]; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
aeweston98
Mar 27, 2018
Author
Contributor
I am interpreting this to mean that since we don't add any dom-tree entries to the reports vector anymore we can use the return of get_reports directly. ie. reports_chan.send(get_reports(self.get_cx(), path_seg)); Is that what you meant?
This comment has been minimized.
This comment has been minimized.
jdm
Mar 27, 2018
Member
Oh, my mistake. I was skimming the changes and didn't look closely enough. You can ignore this comment.
| dom_tree_size += malloc_size_of_including_self(&mut ops, document.window()); | ||
|
|
||
| if reports.len() > 0 { | ||
| path_seg.push_str(", "); |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 27, 2018
Member
We're missing the joining , now. Let's do the following instead of this loop:
let documents = self.documents.borrow();
let urls = itertools::join(documents.values().map(|d| d.url().as_str()), ", ")
let path_seg = format!("url({})", urls);
(you'll need to add an extern crate itertools to script/lib.rs and add itertools to script/Cargo.toml, too)
This comment has been minimized.
This comment has been minimized.
aeweston98
Mar 27, 2018
Author
Contributor
This change results in a compilation error no method named values found for type std::cell::Ref<'_, script_thread::Documents>. I looked at the impl for Documents, but was not able to fix the problem. I will continue working on it tomorrow.
This comment has been minimized.
This comment has been minimized.
jdm
Mar 27, 2018
Member
Oh, I made the wrong assumption about the type of self.documents. You can use documents.iter().map(|(_, d)| d.url().as_str()) instead.
This comment has been minimized.
This comment has been minimized.
aeweston98
Mar 27, 2018
•
Author
Contributor
When I put this in as is, it results in a compilation error on d.url() borrowed value does not live long enough (see attached screenshot for details). I think this is caused by as_str() returning a &str. I replaced as_str() with to_string() and it compiled and I tested it and the colon separated list of urls shows up. Please let me know if that change is ok.
This comment has been minimized.
This comment has been minimized.
| @@ -200,6 +202,12 @@ pub fn init_service_workers(sw_senders: SWManagerSenders) { | |||
| ServiceWorkerManager::spawn_manager(sw_senders); | |||
| } | |||
|
|
|||
| #[no_mangle] | |||
| #[allow(unsafe_code)] | |||
| pub unsafe extern "C" fn is_dom_object(obj: *mut JSObject) -> bool { | |||
This comment has been minimized.
This comment has been minimized.
|
@bors-servo r+ |
|
|
Pass new method in CollectServoSizes to get size of ObjectPrivateVisitor <!-- Please describe your changes on the following line: --> These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an [open pull request](servo/rust-mozjs#409). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #7084 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20430) <!-- Reviewable:end -->
|
|
|
@jdm It was the lack of EOF in Cargo.toml which caused test-tidy to fail, fixed now. Also updated to latest changes in master. |
|
@bors-servo r+ |
|
|
Pass new method in CollectServoSizes to get size of ObjectPrivateVisitor <!-- Please describe your changes on the following line: --> These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an [open pull request](servo/rust-mozjs#409). --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #7084 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20430) <!-- Reviewable:end -->
|
|

aeweston98 commentedMar 26, 2018
•
edited
These changes are the servo changes to allow the measurement of DOM objects with the ObjectPrivateVisitor API. Two new functions have been added MemoryReporter and get_size, which are passed as function pointers to two updated mozjs functions. Currently these changes rely on a branch version of mozjs, which has an open pull request.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is