This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sockets tapset and script


On Fri, 2006-11-17 at 14:26 -0800, Mike Mason wrote:
> Attached is a sockets tapset and a script that uses the tapset.  

Very nice!  

It seems like tokenize() and str2long() (perhaps renamed simply strtol)
would be good candidates to put in the string tapset so others could use
them.

Since yesterday, we can now access parameters in return probes (BZ
1382). This could simplify some of your script because yo no longer need
to cache parameters on entry probes and then lookup their values in the
return probe.

In print_activity, you can simply do this:
	foreach ([pid, prot, fam] in sk_pid- limit max) { ... }
Then you don't need "if (!--max) break"
This is a bit cleaer and generates faster code.

> Mapping functions are something I think script writers need, not just for sockets, 
> but in a lot of other areas. Some of these functions using mapping arrays. 
> What do people think of this approach?

It is simple and elegant. However, in time-critical code (which your
example is probably not) it may be better to write them in C. A
complicated example would be what I did in errno.stp. Of course that
example doesn't include the reverse map.

I see you worked around the issue with nonexistent map entries are
returned as 0. Also, since setting a map entry to 0 deletes it, there is
no reason to do
	fam_str2num["UNSPEC"] = 0
What you could have done is add 1 to all of the entries, which
simplifies your code considerably:
function sock_fam_str2num:long (family:string)
{
	if (!fam_s2s_init) _fam_str2num_init()
	return fam_str2num[family] - 1
}
function sock_fam_num2str:string (family:long)
{
	if (!fam_n2s_init) _fam_num2str_init()
	str = fam_num2str[family+1]
	if (str == "") str = sprintf ("%d", family)
	return str
}


One possible issue is if we accumulate too many of these arrays in
tapsets, they could take significant space. The language currently has
no way to declare an array static and therefore all arrays have
MAXMAPENTRIES preallocated for their use.

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]