[Mimedefang] sample code to time malware scans using Time::HiRes

Jeremy Mates jmates at sial.org
Wed Jan 28 19:35:33 EST 2004


* alan premselaar <alien at 12inch.com>
> I'm not sure how to get the filter times into the syslog like that
> however, i'd be willing to help in anyway I can.

Perhaps something like the following in mimdefang-filter:

use Time::HiRes ();

after installing Time::HiRes if needed and enabling syslog support. Then
around the code you want to time (untested, use at own risk):

my $t0 = [Time::HiRes::gettimeofday];
my ($code, $category, $action) = message_contains_virus_clamav();
md_syslog 'info', "$QueueID: clamav duration: " . Time::HiRes::tv_interval($t0); 
You might also want to log the size of the message, or have your log
parser find the Sendmail log for $QueueID to get that information, so
you can correlate scan times with the amount of data being scanned.

To keep the number of log entries down, you could use a duration hash,
then do a single log entry at the end of the filter function.

my %durations;
...
$duration{'clamav'} = Time::HiRes::tv_interval($t0);
...
md_syslog 'info', "$QueueID: durations: " . 
  join(', ', map { $_.'='.$durations{$_} } keys %durations))



More information about the MIMEDefang mailing list