DTrace Mozilla - load probes 2 or what's my browser up to?

Hi - well I bloged recently about adding in load probes to firefox. In this initial cut we where just getting the URI passed back in the probe, which was a good start, but I wanted to pass in a more useful info data structure to the probe that broke down the URI into it's constituent parts, which would be a lot more useful in a dscript.

URI Structure:

<scheme>://<username>:<password>@<hostname>:<port>//<directory><basename>.<extension>;<param>?<query>#<ref>

Getting the data into the probe

Well thanks to help from biesi on mozilla #developers I was able to use the Channel being passed into the probe function to get at the URI and URL, allowing me to break down the URI into it's various parts. I then popped these pieces into a data struct and passed this back as a probe arg. So far so good. The fun started when I then tried to pull the data back out, but thankfully with a bit of help from Brendan Gregg I got it sorted. I thought others might find this useful, so here goes.

Probes:
mozilla<pid>:::load-start
mozilla<pid>:::load-done

Args:
arg0 is of type void \* - its a unique_id
arg1 is an enum nsTraceLoadType - TYPE_URI or TYPE_IMAGE
arg2 is of type struct nsTraceLoadInfo \* - pointer to an info data struct

struct nsTraceLoadInfo {
char \* contentType;
char \* spec;
char \* scheme;
char \* username;
char \* password;
char \* hostPort;
char \* host;
int port;
char \* path;
char \* filePath;
char \* fileName;
char \* fileExtension;
char \* param;
char \* query;
char \* ref;
};

enum nsTraceLoadType {
TYPE_URI = 1,
TYPE_IMAGE
};

Getting data back out in a d script

Well the trick that is needed is to use a few of our copyin friends, to be honest it was the second one that had me stumped, thanks Brendan :)

moz\*:::load-start
{
this->info = (struct nsTraceLoadInfo \*) copyin(arg2, sizeof (struct nsTraceLoadInfo));
printf("spec: %s\\n", copyinstr((uintptr_t)this->info->spec));
printf("port: %s\\n", this->info->port));
}

this->info: the arg2 is a pointer to a nsTraceLoadInfo data blob in userland that needs to be copied into the kernel for the d script to access. The copyin does just that returning a pointer to this in-kernel-memory blob, hence the need for the cast.

printf: now you can access the data in the blob no worries, as the printf of the port data shows, but what about the strings in the data struct. Well these are just char \* pointers but to userland  data, that hasn't yet been copied over. So you need to do a copyinstr to get this string data into the d script. Ahh now you tell me ;)

What's my browser up to?

Well now that we can get at the broken down URI data on all the browser page loads we can have a little fun. Check out the output from a browserspy.d script Brendan put together below.

$ browserspy.d 

Tracing... Hit Ctrl-C to end.

Browser requests by scheme,

PID UID SCHEME COUNT
1578 65535 https 1
1578 65535 file 2
1578 65535 about 6
1578 65535 http 19

Browser requests by content type,

PID UID CONTENT TYPE COUNT
1578 65535 application/x-unknown-content-type 2
1578 65535 text/html 6
1578 65535 20

Browser requests by file extension,

PID UID FILE EXT COUNT
1578 65535 cgi 1
1578 65535 jspa 1
1578 65535 php 2
1578 65535 idl 3
1578 65535 html 4
1578 65535 11

Browser requests by username (if used),

PID UID USERNAME COUNT
1578 65535 22

Browser requests by host,

PID UID COUNT HOST
1578 65535 1 blogs.sun.com
1578 65535 1 bugzilla.mozilla.org
1578 65535 1 docs.sun.com
1578 65535 1 forums.suselinuxsupport.de
1578 65535 1 lists.freebsd.org
1578 65535 1 mail.opensolaris.org
1578 65535 1 www.abercornbasin.com
1578 65535 2
1578 65535 2 blog.mozilla.com
1578 65535 2 www.mozilla.org
1578 65535 2 www.opensolaris.org
1578 65535 3 lxr.mozilla.org
1578 65535 4 www.google.ie

Top 10 sites,

PID UID COUNT SITE
1578 65535 1 http://www.google.ie/search?hl=en&q=mozilla+dtrace&btnG=Search&meta=
1578 65535 1 http://www.google.ie/search?hl=en&q=mozilla+dtrace+robert&btnG=Search&meta=
1578 65535 1 http://www.google.ie/search?q=jim+grizansio+blogs+sun&hl=en&filter=0
1578 65535 1 http://www.google.ie/search?source=ig&hl=en&q=alan+xserver+provider+dtrace&btnG=Google+Search&meta=
1578 65535 1 http://www.opensolaris.org/jive/forum.jspa?forumID=7
1578 65535 1 http://www.opensolaris.org/os/project/mozilla-dtrace/;jsessionid=D2C184F6D4B2316D68920A330AC0FB4D
1578 65535 1 https://bugzilla.mozilla.org/show_bug.cgi?id=370906
1578 65535 2 file:///usr/share/doc/soldevex/html/developer_guide.html
1578 65535 2 http://blog.mozilla.com/rob-sayre/2007/09/06/land-of-dtrace/
1578 65535 2 http://www.mozilla.org/projects/firefox/3.0a8pre/releasenotes/

What's next?

Well I want add in Image load probes and then get this patch back up to bugzilla [#370906]. At the minute I know where to put the image load start, but to figure out where to put the done probes I'll need to dig into the mozilla developer's brains :) I'll also start playing with some timing scripts which should be fun as we have load-start and load-done enabled.

 





 


 

Comments:

Post a Comment:
Comments are closed for this entry.
About

jmr

Search

Top Tags
Categories
Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today