Apache-Traffic
view release on metacpan or search on metacpan
$end = timegm(0, 0, 0, (localtime($end))[3..5]);
tie(%STATS, 'IPC::Shareable', SHMKEY, { create => 'no' })
or return error("unable to tie to shared memory: $!");
if (-e DBPATH) { # DBM FILE WON'T EXIST UNTIL HANDLER HAS RUN FOR > 1 DAY
$db_obj = tie %db, 'DB_File', DBPATH, O_RDONLY, MODE
or return error("unable to open dbm file: $!");
}
@users = () if ($all);
foreach(@users) {
# LOOKUP THE USERNAME IF WE WERE PASSED A UID
$_ = (getpwuid $_)[0] || $_ if ($_ =~ /^\d+$/);
# LOOKUP THE UID
(defined($uid = (getpwnam $_)[2])) || ($uid = $_);
# STORE THE USERNAME INDEXED BY UID (unless $wantuid is true)
$uids{$uid} = ($wantuid ? $uid : $_);
}
while($start <= $end) {
unless ($all) {
foreach(keys %uids) { # MAKE SURE WE RETURN VALUES FOR EVERY USER
$hash{$start}{ $uids{$_} } = { bytes => 0, hits => 0 };
}
$ref = thaw($db{$start});
} else {
$start += ONEDAY;
next;
}
if ($all) {
foreach(keys %$ref) {
unless (defined $uids{$_}) {
$uids{$_} = $_;
if ((/^\d+$/) and (! $wantuid)) {
$uids{$_} = (getpwuid $_)[0] || $_;
}
}
}
}
foreach(keys %uids) {
next unless (exists $ref->{$_});
$hash{$start}{ $uids{$_} }{bytes} = $ref->{$_}{bytes};
$hash{$start}{ $uids{$_} }{hits} = $ref->{$_}{hits};
}
$start += ONEDAY;
( run in 0.269 second using v1.01-cache-2.11-cpan-8d75d55dd25 )