G''Day Folks,
I''ve just used a translator in a way I''ve never done before,
but also in
an absurdly obvious way that conjures the clouds of doubt. I''m using a
translator to "translate". Prevously I''ve used them as
walkers.
As an example, the output is this,
# fopread.d
Sampling... Hit Ctrl-C to end.
^C
CMD VTYPE BYTES
bash chr 38
more chr 55
find reg 481
bash reg 962
more reg 1652
nfsmapid reg 2871
sshd sock 3484
more fifo 184320
sshd chr 185175
grep reg 5152957
and the script is,
-----fopread.d-----
#!/usr/sbin/dtrace -s
#pragma D option quiet
typedef struct vtype2str {
string vtype;
};
translator struct vtype2str < int T > {
/* the order has been picked for performance reasons */
vtype T == 1 ? "reg" :
T == 9 ? "sock" :
T == 4 ? "chr" :
T == 6 ? "fifo" :
T == 8 ? "proc" :
T == 2 ? "dir" :
T == 3 ? "blk" :
T == 5 ? "lnk" :
T == 7 ? "door" :
T == 10 ? "port" :
T == 11 ? "bad" : "non";
};
dtrace:::BEGIN
{
printf("Sampling... Hit Ctrl-C to end.\n");
}
fbt::fop_read:entry
{
self->type = xlate <struct vtype2str *>(args[0]->v_type)->vtype;
self->size = args[1]->uio_resid;
self->uiop = args[1];
}
fbt::fop_read:return
/self->uiop/
{
this->resid = self->uiop->uio_resid;
@readers[execname, self->type] = sum(self->size - this->resid);
self->type = 0;
self->size = 0;
self->uiop = 0;
}
dtrace:::END
{
printf("%-16s %6s %9s\n", "CMD", "VTYPE",
"BYTES");
printa("%-16s %6s %@9d\n", @readers);
}
-----fopread.d-----
Anyhow, I''ll start using them in a few places unless someone points out
a
problem with this approach. (I''m thinking of creating a library of
them).
cheers,
Brendan
[Sydney, Australia]