#!/usr/sbin/dtrace -CZs /* * browserspy_time_all.d - trace and give short report of browser URI, Image loads and requests and DNS lookups. * * All URI Requests have a matching load-start and load-done * * All Image loads start with a load-init, if they need to be retrived from the net then load-start * will fire at the start of the network load and load-done will fire at the end. * * All DNS lookups start with a dnslookup-init, if the lookup needs to be done over the network then dnslookup-start * will fire at the start of the network query and dnslookup-done will fire at the end. * * URI structure - spec: * ://:@://.;?# * * Probes: * mozilla:::load-init * mozilla:::load-start * mozilla:::load-done * Args: * arg0 is of type void * - unique_id * arg1 is an enum nsTraceLoadType - TYPE_URI or TYPE_IMAGE * arg2 is of type struct nsTraceLoadInfo * - pointer to the URI info * * mozilla:::dnslookup-init * mozilla:::dnslookup-start * mozilla:::dnslookup-done * Args: * arg0 is of type void * - unique_id * arg1 is of type struct nsTraceDNSLookupInfo * - pointer to the DNS lookup info * */ #pragma D option quiet /* Any member of nsTraceLoadInfo can be returned as "" except spec and scheme */ struct nsTraceLoadInfo { char * contentType; /* mime type e.g. text/html - can be */ char * spec; /* Complete URI of above structure */ char * prePath; /* scheme://user:password@host:port */ char * scheme; /* protocol - http, file ... */ char * userPass; /* username:password */ char * username; char * password; char * hostPort; /* host:port or just host if port = -1 */ char * host; int port; char * path; /* path = ;?# */ char * filePath; /* . */ char * fileName; /* */ char * fileExtension; /* */ char * param; char * query; char * ref; int imagestatus; }; enum nsTraceLoadType { TYPE_URI = 1, TYPE_IMAGE }; struct nsTraceDNSLookupInfo { char * host; char * address; int status; }; dtrace:::BEGIN { printf("Tracing Browser Network Activity... Hit Ctrl-C to end.\n"); } moz*:::dnslookup-init { @dnstotal["DNS_LOAD", "Lookups - Network and Cache"] = count(); } moz*:::dnslookup-start { @dnstotal["DNS_REQ", "Network Requests - Started"] = count(); startDNS[pid, arg0] = timestamp; } moz*:::dnslookup-done /startDNS[pid, arg0] / { @dnstotal["DNS_REQ", "Network Requests - Done"] = count(); this->elapsedDNS = timestamp - startDNS[pid, arg0]; this->infoDNS = (struct nsTraceDNSLookupInfo *) copyin(arg1, sizeof (struct nsTraceDNSLookupInfo)); this->ho = copyinstr((uintptr_t)this->infoDNS->host); this->add = copyinstr((uintptr_t)this->infoDNS->address); @dns[pid, uid, this->infoDNS->status, this->add, this->ho] = count(); @dnsavg[pid, uid, this->infoDNS->status, this->add, this->ho] = avg(this->elapsedDNS); @dnssum[pid, uid, this->infoDNS->status, this->add, this->ho] = sum(this->elapsedDNS); startDNS[pid, arg0] = 0; } moz*:::load-init { @loadtotal["IMAGE_LOAD", "Image Loads - Network and Cache"] = count(); } moz*:::load-start { type[pid, arg0] = arg1 == TYPE_URI ? "URI": "IMAGE_REQ"; } moz*:::load-start /type[pid, arg0] == "URI" || type[pid, arg0] == "IMAGE_REQ"/ { @loadtotal[type[pid, arg0], "Network Requests - Started"] = count(); start[pid, arg0] = timestamp; } moz*:::load-done /start[pid, arg0] && (type[pid, arg0] == "URI" || type[pid, arg0] == "IMAGE_REQ")/ { @loadtotal[type[pid, arg0], "Network Requests - Done"] = count(); this->elapsed = timestamp - start[pid, arg0]; this->info = (struct nsTraceLoadInfo *) copyin(arg2, sizeof (struct nsTraceLoadInfo)); this->sc = copyinstr((uintptr_t)this->info->scheme); @scheme[pid, uid, type[pid, arg0], this->sc] = count(); @schemeavg[pid, uid, type[pid, arg0], this->sc] = avg(this->elapsed); @schemesum[pid, uid, type[pid, arg0], this->sc] = sum(this->elapsed); this->ct = copyinstr((uintptr_t)this->info->contentType) ; @ctype[pid, uid, type[pid, arg0], this->ct == "" ? "":this->ct] = count(); @ctypeavg[pid, uid, type[pid, arg0], this->ct == "" ? "":this->ct] = avg(this->elapsed); @ctypesum[pid, uid, type[pid, arg0], this->ct == "" ? "":this->ct] = sum(this->elapsed); this->fe = copyinstr((uintptr_t)this->info->fileExtension) ; @fext[pid, uid, type[pid, arg0], this->fe == "" ? "":this->fe] = count(); @fextavg[pid, uid, type[pid, arg0], this->fe == "" ? "":this->fe] = avg(this->elapsed); @fextsum[pid, uid, type[pid, arg0], this->fe == "" ? "":this->fe] = sum(this->elapsed); this->hs = copyinstr((uintptr_t)this->info->host) ; @host[pid, uid, type[pid, arg0], this->hs == "" ? "":this->hs] = count(); @hostavg[pid, uid, type[pid, arg0], this->hs == "" ? "":this->hs] = avg(this->elapsed); @hostsum[pid, uid, type[pid, arg0], this->hs == "" ? "":this->hs] = sum(this->elapsed); start[pid, arg0] = 0; type[pid, arg0] = NULL; } dtrace:::END { /* URI Stats */ setopt("aggsortpos", "0"); printf("\nPROBE STATS:\n"); printf("\n%-11s %-38s %8s\n", "TYPE", "TOTAL", "COUNT"); printa("%-11s %-38s %@8d\n", @dnstotal); printf("\n%-11s %-38s %8s\n", "TYPE", "TOTAL", "COUNT"); printa("%-11s %-38s %@8d\n", @loadtotal); printf("\nBrowser DNS lookup requests,\n\n"); normalize(@dnsavg, 1000000); normalize(@dnssum, 1000000); setopt("aggsortpos", "2"); printf("%8s %8s %10s %8s %11s %11s %15s %-36s\n", "PID", "UID", "STATUS", "COUNT", "AVG(msec)", "SUM(msec)", "IP", "HOST"); printa("%8d %8d %10d %@8d %@11d %@11d %15s %-36s\n", @dns, @dnsavg, @dnssum); printf("\nURI structure:\n"); printf("://:@://.;?#\n"); printf("\nBrowser requests by scheme,\n\n"); normalize(@schemeavg, 1000000); normalize(@schemesum, 1000000); setopt("aggsortpos", "2"); printf("%8s %8s %10s %8s %11s %11s %-36s\n", "PID", "UID", "TYPE", "COUNT", "AVG(msec)", "SUM(msec)", "SCHEME"); printa("%8d %8d %10s %@8d %@11d %@11d %-36s\n", @scheme, @schemeavg, @schemesum); printf("\nBrowser requests by content type,\n\n"); normalize(@ctypeavg, 1000000); normalize(@ctypesum, 1000000); printf("%8s %8s %10s %8s %11s %11s %-36s\n", "PID", "UID", "TYPE", "COUNT", "AVG(msec)", "SUM(msec)", "CONTENT_TYPE"); printa("%8d %8d %10s %@8d %@11d %@11d %-36s\n", @ctype, @ctypeavg, @ctypesum); printf("\nBrowser requests by file extension,\n\n"); normalize(@fextavg, 1000000); normalize(@fextsum, 1000000); printf("%8s %8s %10s %8s %11s %11s %-36s\n", "PID", "UID", "TYPE", "COUNT", "AVG(msec)", "SUM(msec)", "FILE_EXT"); printa("%8d %8d %10s %@8d %@11d %@11d %-36s\n", @fext, @fextavg, @fextsum); printf("\nBrowser requests by host,\n\n"); normalize(@hostavg, 1000000); normalize(@hostsum, 1000000); printf("%8s %8s %10s %8s %11s %11s %-36s\n", "PID", "UID", "TYPE", "COUNT", "AVG(msec)", "SUM(msec)", "HOST"); printa("%8d %8d %10s %@8d %@11d %@11d %-36s\n", @host, @hostavg, @hostsum); }