cross-platform browser instrumentation using javascript

23
cross-platform browser instrumentation using JavaScript jsprobes Brian Burg (@brrian / [email protected])

Upload: others

Post on 30-Apr-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: cross-platform browser instrumentation using JavaScript

cross-platform browser instrumentation

using JavaScript

jsprobes    

Brian Burg (@brrian / [email protected])

Page 2: cross-platform browser instrumentation using JavaScript

Background:    browser  research  template  1            

Become  puzzled  by  a  ques:on  

2            

Get  real  data  and  analyze  

3            

Write  paper  with  answers  

images  from  www.phdcomics.com  

Page 3: cross-platform browser instrumentation using JavaScript

Right  now,  this  is  the  hard  part  

1            

Become  puzzled  by  a  ques:on  

2            

Get  real  data  and  analyze  

3            

Write  paper  with  answers  

images  from  www.phdcomics.com  

Page 4: cross-platform browser instrumentation using JavaScript

Browser  instrumenta:on  wishlist  

•  Cross-­‐plaForm/architecture  •  Low/no  performance  overhead  •  Shareable/distributable  •  Run:me  flexibility  •  Familiar  programming  model  •  Cross-­‐language/cross-­‐component  

Page 5: cross-platform browser instrumentation using JavaScript

Exis:ng  approaches:  browser  addons/extensions  

Advantages  •  Somewhat  familiar  programming  model  

•  Easy  to  distribute  •  Cross-­‐plaForm  •  Flexibility  at  run:me  

Disadvantages  •  Can’t  access  all  parts  of  the  stack  

•  Bad  for  cri:cal  path  instrumenta:on  

Image:  Mozilla  Test  Pilot  (www.mozillalabs.com/testpilot/)  

Page 6: cross-platform browser instrumentation using JavaScript

Exis:ng  approaches:  plaForm  instrumenta:on  

Advantages  •  Extremely  low/no  performance  overhead  

•  Can  instrument  any  browser  component  

•  Run:me  flexibility  

Disadvantages  •  Needs  escalated  (root)  privileges/kernel  mod  

•  PlaForm-­‐specific  •  Limited  programming  language/model  

•  Cannot  distribute  

Images:  dtrace.org,  en.wikipedia.org/wiki/SystemTap  

Page 7: cross-platform browser instrumentation using JavaScript

Exis:ng  approaches:  modifying  browser  source  

Advantages  •  Can  do  anything!  •  (possible)  low  performance  impact  

Disadvantages  •  Difficult  to  understand  and  modify  

•  Easy  to  cause  crashes  •  Hard  to  distribute/share/reuse  

•  Very  fragile  vs.  upstream  changes  

Page 8: cross-platform browser instrumentation using JavaScript

jsprobes:  an  experiment  

•  A  browser  instrumenta:on  framework…    – With  instrumenta:on  wri_en  in  JavaScript  – Accessible  via  XPCOM  to  addons  – Available  on  all  plaForms/architectures  – Which  encourages  experimenta:on  – That  can  gather  many  kinds  of  data  – Fast  enough  to  gather  low-­‐level  data  

Page 9: cross-platform browser instrumentation using JavaScript

jsprobes  terminology  

probe  point            

Source  loca:on  to  instrument  

probe  handler            

What  to  do  at  probe  point  

probe  values            

Data  to  record  at  probe  point  

images  from  www.phdcomics.com  

Page 10: cross-platform browser instrumentation using JavaScript

jsprobes  use  case  

1.  Find  an  interes:ng  probe  point   probes.GC_DID_START

2.  Decide  which  probe  values  to  use   env.currentTimeMS,

runtime.heapSize

3.  Write  a  probe  handler  for  that  point    pendingGC = [env.currentTimeMS, 0,

runtime.heapSize, 0];

Page 11: cross-platform browser instrumentation using JavaScript

jsprobes  use  case  (2)  

4.  Write  a  matching  handler  to  GC_WILL_END: pendingGC[1] = env.currentTimeMS; pendingGC[3] = runtime.heapSize; data.push(pendingGC);

 5.  Register  handlers  with  the  probes  service.  6.  Periodically  fetch  data  and  do  something,  such  as  aggregate,  graph,  or  report  it.

Page 12: cross-platform browser instrumentation using JavaScript

Demo!  (source  available  at  h_ps://bitbucket.org/burg/aboutgc)    

Page 13: cross-platform browser instrumentation using JavaScript

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

Handler  registry          

Page 14: cross-platform browser instrumentation using JavaScript

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

Handler  registry          

probe handler code

probe handler code

probe handler code

Register  probe  handler  with  service  

Page 15: cross-platform browser instrumentation using JavaScript

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

Probe  point  reached.  

1  Handler  registry  

       

probe handler code

probe handler code

probe handler code

Register  probe  handler  with  service  

Page 16: cross-platform browser instrumentation using JavaScript

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

Data  gathered,  serialized,  

and  enqueued  

Handler  registry          

probe handler code

probe handler code

probe handler code

Probe  point  reached.  

Register  probe  handler  with  service  

Page 17: cross-platform browser instrumentation using JavaScript

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

asynchronously  deserialize  data  and  run  handlers  

Handler  registry          

probe handler code

probe handler code

probe handler code

Data  gathered,  serialized,  

and  enqueued  

Register  probe  handler  with  service  

Page 18: cross-platform browser instrumentation using JavaScript

Handler  registry          

probe handler code

probe handler code

probe handler code

Register  probe  handler  with  service  

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

asynchronously  deserialize  data  and  run  handlers  

Data  gathered,  serialized,  

and  enqueued  

Post  async  messages  back  to  main  thread  

Page 19: cross-platform browser instrumentation using JavaScript

Handler  registry          

probe handler code

probe handler code

probe handler code

Register  probe  handler  with  service  

jsprobes  architecture  

Main  browser    thread  +  heap  

Probe  handler  thread  +  heap  

asynchronously  deserialize  data  and  run  handlers  

Data  gathered,  serialized,  

and  enqueued  

Post  async  messages  back  to  main  thread  

Dispatch  message  to  callbacks  

Page 20: cross-platform browser instrumentation using JavaScript

Architecture  implica:ons  

•  Probe  points  can  fire  at  :mes  unsafe  for  JS  •  Probe  handlers  have  read-­‐only  access*  •  Handler  must  specify  what  data  to  collect  •  Probe  data  must  be  representable  in  JS  •  Probe  data  must  be  be  serializable**  

 

*  Side-­‐effects  would  complicate  reasoning  when  mul:ple  handlers  are  registered  for  the  same  probe  point  

**  Probe  data  is  marshalled  using  the  HTML  5  structured  cloning  algorithm.  This  can  be  extended  to  support  new  data  types.  

Page 21: cross-platform browser instrumentation using JavaScript

jsprobes:  current  status  

•  Cross-­‐plaForm/architecture  •  Low/no  performance  overhead  (TODO)  •  Shareable/distributable  (TODO)  •  Run:me  flexibility  •  Familiar  programming  model  •  Cross-­‐language/cross-­‐component  

Current  implementa:on  available  at  h_ps://bitbucket.org/burg/jsprobes-­‐patches    

Page 22: cross-platform browser instrumentation using JavaScript

Let’s  fill  in  the  research  template…  1                      

2            3          

3  

images  from  www.phdcomics.com  

Use  jsprobes  to    make  an  addon    that  measures    

per-­‐site  heap  size  

“Do  websites  have  a  typical  heap  size?”  

Implement  beLer    heap  size  heurisMcs  based  on  real  data  

Page 23: cross-platform browser instrumentation using JavaScript

Future  work  

•  More  sophis:cated  implementa:on  – No  “probe  effect”  when  probes  inac:ve  – Low  performance  impact  when  ac:ve  

•  Add  probe  points  to  more  components  •  Expose  more  types  of  data  to  probe  handlers  

 Brian  Burg  –  University  of  Washington    [email protected]    www.brrian.net    

www.twi_er.com/brrian      h_ps://bitbucket.org/burg/  h_p://brrian.tumblr.com