时间:2021-07-01 10:21:17 帮助过:3人阅读
集計用のPerlスクリプトです。
#!/usr/bin/perl
use strict;
use warnings;
my (%file_map, $do_print, %has_io, %rthreads, %rtimes, %rbytes, %wthreads, %wtimes, %wbytes,
%aio_rthreads, %aio_rtimes, %aio_rbytes, %aio_wthreads, %aio_wtimes, %aio_wbytes);
$do_print = 0;
while (my $line = <>) {
chomp($line);
my ($call, $pid, $tid, $fd, $size) = split(/\t/, $line);
if (($call eq ‘read‘) or ($call eq ‘write‘)
or ($call eq ‘aio_read‘) or ($call eq ‘aio_write‘)) {
if (!defined($file_map{"$pid,$fd"})) {
$file_map{"$pid,$fd"} = readlink("/proc/$pid/fd/$fd") or next;
}
my $file = $file_map{"$pid,$fd"};
if (substr($file, 0, 1) eq ‘/‘) {
$do_print = 1;
$has_io{$file} = 1;
if ($call eq ‘read‘) {
$rthreads{$file}->{$tid} = 1;
$rtimes{$file}++;
$rbytes{$file} += $size;
} elsif ($call eq ‘write‘) {
$wthreads{$file}->{$tid} = 1;
$wtimes{$file}++;
$wbytes{$file} += $size;
} elsif ($call eq ‘aio_read‘) {
$aio_rthreads{$file}->{$tid} = 1;
$aio_rtimes{$file}++;
$aio_rbytes{$file} += $size;
} elsif ($call eq ‘aio_write‘) {
$aio_wthreads{$file}->{$tid} = 1;
$aio_wtimes{$file}++;
$aio_wbytes{$file} += $size;
}
}
} elsif ($call eq ‘close‘) {
if (defined($file_map{"$pid,$fd"})) {
delete($file_map{"$pid,$fd"});
}
} elsif ($call eq ‘print‘) {
my ($sec, $min, $hour, $day, $mon, $year) = localtime();
printf "%04d-%02d-%02d %02d:%02d:%02d\n",
$year + 1900, $mon + 1, $day, $hour, $min, $sec;
if ($do_print == 1) {
print "-------- Synchronous I/O -------- ------- Asynchronous I/O --------\n";
print "rTH r/s rKB/s wTH w/s wKB/s rTH r/s rKB/s wTH w/s wKB/s File\n";
foreach my $file (sort keys %has_io) {
printf "%3d %5d %6d %3d %5d %6d %3d %5d %6d %3d %5d %6d %s\n",
scalar(keys(%{$rthreads{$file}})),
defined($rtimes{$file}) ? $rtimes{$file} : 0,
defined($rbytes{$file}) ? $rbytes{$file} / 1024 : 0,
scalar(keys(%{$wthreads{$file}})),
defined($wtimes{$file}) ? $wtimes{$file} : 0,
defined($wbytes{$file}) ? $wbytes{$file} / 1024 : 0,
scalar(keys(%{$aio_rthreads{