A network benchmarker for Perl programs?
I had an idea for the Benchmarking chapter of Mastering Perl but I don't have time to implement it. But, with many of my ideas, someone probably already has.
The DBI::Profile module hooks into DBI calls to monitor database queries. The autodie replaces some built-ins so they error-out differently.
Could we do the same thing with the low level networking calls to measure octets read and sent? Of course, there would be a performance hit (as with the those two modules), but that's what we expect when we benchmark. Maybe it would work like Devel::Cover where it writes intermediate data files that another program analyzes to create the report.
I've been looking around for extra-script solutions to this, and they tend to be uniformly linux-specific and wrong. I also want something that handles the entire process group, so child processes count.
As far as I can see, the various network tools aren't process aware; they can see ports and IPs, but per process stuff. A process can have a local port to itself, but that doesn't mean it keeps it, letting another process use it for a bit.
> Could we do the same thing with the low level networking calls to measure octets read and sent?
You can override built-ins: sysread/syswrite.
BEGIN { *CORE::GLOBAL::sysread = sub(*\$$;$) { &_sysread; }; };
BEGIN { *CORE::GLOBAL::syswrite = sub(*$;$$) { &_syswrite; }; };
You could probably use DTrace to tie in to the underlying network layer. Although, I am not skilled enough in DTrace to provide an example.