{"id":844,"date":"2012-02-11T23:01:20","date_gmt":"2012-02-12T07:01:20","guid":{"rendered":"http:\/\/www.visophyte.org\/blog\/?p=844"},"modified":"2012-02-11T23:01:20","modified_gmt":"2012-02-12T07:01:20","slug":"aboutnosy-can-now-show-cpu-usage-using-jsprobes","status":"publish","type":"post","link":"https:\/\/www.visophyte.org\/blog\/2012\/02\/11\/aboutnosy-can-now-show-cpu-usage-using-jsprobes\/","title":{"rendered":"about:nosy can now show CPU usage using jsprobes"},"content":{"rendered":"<p>Refresher: about:nosy was introduced one week ago as a way to see the memory usage of your tabs and extensions (that live in compartments).\u00a0 It sorta looked like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-845\" title=\"about:nosy with nothing expanded\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-overview-scaled.png\" alt=\"\" width=\"596\" height=\"432\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-overview-scaled.png 596w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-overview-scaled-300x217.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/p>\n<p>Except those (green) bars on the right are new.\u00a0 The ones on the left, they show memory.\u00a0 The ones on the right, they show CPU usage.\u00a0 New data points enter on the left, surf across to the right, then fall into oblivion.\u00a0 I have it on good authority that researchers are looking into some way of labeling these things so that you don&#8217;t have to read a blog post to understand them.\u00a0 But until they do, I have a blogging gig, so let&#8217;s hope it takes them a bit longer.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-846\" title=\"about:nosy memory and cpu usage for devmo weather demo\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-devmo-weather-cpu.png\" alt=\"\" width=\"552\" height=\"46\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-devmo-weather-cpu.png 552w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/about-nosy-devmo-weather-cpu-300x25.png 300w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/p>\n<p>The above is a picture of the bars belonging to a tab viewing a <a href=\"https:\/\/developer.mozilla.org\/en-US\/demos\/detail\/animation-of-weather-fronts\">Mozilla Demo Studio demo by ybochatay<\/a> <a href=\"https:\/\/developer.mozilla.org\/en-US\/demos\/detail\/animation-of-weather-fronts\/launch\">https:\/\/developer.mozilla.org\/en-US\/demos\/detail\/animation-of-weather-fronts\/launch<\/a>.\u00a0 What&#8217;s really neat about this example is that you can see it was going to town on the CPU in the past (right; past), then usage fell off a cliff.\u00a0 Why?\u00a0 Because I changed from that tab to the about:nosy tab.\u00a0 I&#8217;m going to assume that&#8217;s Firefox&#8217;s setTimeout\/setInterval throttling of background tabs was at work and the team is to be congratulated for that.\u00a0 If it&#8217;s the case that the demo or the demo framework is very responsible, kudos to those involved parties.<\/p>\n<p>We track CPU utilization on a per-compartment basis, taking care to only attribute usage to a single compartment per thread at a time.\u00a0 In the event of ill-behaved parties spinning a nested event loop, we are not currently clever enough to stop the clock in this implementation.\u00a0 Native code costs like reflows that are incurred with the JS still on the stack will happily be attributed to the compartment.<\/p>\n<p>The magic that powers the CPU tracking is <a href=\"http:\/\/www.cs.washington.edu\/homes\/burg\/\">Brian Burg<\/a>&#8216;s jsprobes implementation.\u00a0 See his <a href=\"http:\/\/brrian.tumblr.com\/post\/10571624125\/jsprobes\">blog post<\/a> and master probe hacker (<a href=\"http:\/\/blog.mozilla.com\/sfink\/tag\/etw\/\">ETW<\/a>!) <a href=\"http:\/\/blog.mozilla.com\/sfink\/\">Steve Fink<\/a>&#8216;s <a href=\"http:\/\/blog.mozilla.com\/sfink\/2011\/09\/21\/js-probes\/\">blog post<\/a> on its magical powers.<\/p>\n<p><strong>If you are adventurous&#8230;<\/strong><\/p>\n<p>&#8230;you can build your own Firefox build with jsprobes.\u00a0 The patch series to use is my updated fork <a href=\"https:\/\/bitbucket.org\/asuth\/jsprobes-patches\">found here on bitbucket<\/a>.\u00a0 You&#8217;ll want to build with &#8220;ac_add_options &#8211;enable-jsprobes&#8221;.\u00a0 The one non-jsprobes change in there is to cause all XPConnect memory reporters to provide the address of their compartment just like system compartments do.\u00a0 Doing so allows us to correlate compartment CPU usage to the compartment&#8217;s memory reporter information without going crazy.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-847\" title=\"about:gc timeline graph\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-timeline.png\" alt=\"\" width=\"546\" height=\"364\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-timeline.png 546w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-timeline-300x200.png 300w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/p>\n<p>You can verify things work by trying out <a href=\"https:\/\/github.com\/asutherland\/about-jsprobes\">about:jsprobes<\/a>, a simple extension you can hack on to play with probes.\u00a0 You can also check out the Steve Fink created\/Brian Burg jsprobes-enabled* <a href=\"https:\/\/bitbucket.org\/asuth\/aboutgc\/\">about:gc implementation<\/a> which provides us with the screenshots in the immediate vicinity of this sentence.\u00a0 I&#8217;m not sure what those squiggly things on the left and the bottom of the boxes filled with pretty lines and dots are; I&#8217;ll see if I can find a blog post explaining them.<\/p>\n<p>Or you can grab the source for <a href=\"https:\/\/github.com\/asutherland\/about-nosy\/\">about:nosy<\/a>.<\/p>\n<p>* I think this is the attribution breakdown based on my own inference; I could be wrong.\u00a0 Either way, they&#8217;re both awesome.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-848\" title=\"aboutgc-pause-reclamation\" src=\"http:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-pause-reclamation.png\" alt=\"\" width=\"540\" height=\"366\" srcset=\"https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-pause-reclamation.png 540w, https:\/\/www.visophyte.org\/blog\/wp-content\/uploads\/2012\/02\/aboutgc-pause-reclamation-300x203.png 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/p>\n<p><strong>If you are not adventurous&#8230;<\/strong><\/p>\n<p><strong><\/strong>&#8230;I will hopefully spin some try builds in the near future.\u00a0 Wait for those.\u00a0 Right now about:nosy still has unacceptable levels of performance impact on your session once you get a bunch of tabs so the custom builds would be one-off novelty uses for 30 seconds.<\/p>\n<p>But while you wait, maybe you would like to <a href=\"https:\/\/github.com\/asutherland\/about-jsprobes\/blob\/c1ee125e4b123e30be9de16c2d2fad475e97f1ac\/about-jsprobes.js#L208\">peruse the probes that power the CPU monitoring<\/a>?<\/p>\n<p><strong>In closing?<\/strong><\/p>\n<p>It&#8217;s worth noting that there are other viable ways to track compartment CPU usage, but jsprobes are the funnest.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Refresher: about:nosy was introduced one week ago as a way to see the memory usage of your tabs and extensions (that live in compartments).\u00a0 It sorta looked like this: Except those (green) bars on the right are new.\u00a0 The ones &hellip; <a href=\"https:\/\/www.visophyte.org\/blog\/2012\/02\/11\/aboutnosy-can-now-show-cpu-usage-using-jsprobes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[3,8,4],"tags":[115,114,110,113],"class_list":["post-844","post","type-post","status-publish","format-standard","hentry","category-mozilla","category-program-execution","category-visualizing","tag-aboutgc","tag-aboutjsprobes","tag-aboutnosy","tag-jsprobes"],"_links":{"self":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/comments?post=844"}],"version-history":[{"count":10,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/844\/revisions"}],"predecessor-version":[{"id":858,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/posts\/844\/revisions\/858"}],"wp:attachment":[{"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/media?parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/categories?post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.visophyte.org\/blog\/wp-json\/wp\/v2\/tags?post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}