LoginSignup
1
0

More than 5 years have passed since last update.

Solaris11.4 の Dtrace で特定ディレクトリのwriteとreadの回数・サイズの合計を取得する

Last updated at Posted at 2018-11-05

特定のディレクトリに対する write と read の統計情報を取得する例

Solaris11.4 の Dtrace 新機能である fileops プロバイダーを利用して特定のディレクトリに対する read と write の回数とサイズの合計を取得する例です。

write-read-sum.d
#!/usr/sbin/dtrace -qs
fileops:::write,fileops:::read
/args[0]->fi_dirname == "/var/tmp" /
{

  @op_cnt[probename] = count();
  @op_size[probename] = sum(args[4]);

}
dtrace:::END
{
 printa("Count: %16s %@16d\n", @op_cnt);
 printa("Size : %16s %@16d\n", @op_size);
}

上記をファイル保存して、実行権を与えて実行します。
Control+C を押すと終了して、結果が出力されます。

# chmod +x write-read-sum.d
#  ./write-read-sum.d 
^C
Count:             read              389
Count:            write              878
Size :             read         25427969
Size :            write         61833363

write,read の引数

fileopsの read,write のプローブを使用していますが、これらの引数は以下の通りです。

write
開いているファイルに書き込みが行われたときに起動するプローブ。
args[0]は、ファイルに対応する fileinfo_t 構造体をポイントしています。
args[1]は、オペレーションの待ち時間が格納されます。
args[2]は、ファイルオフセットが格納されます。
args[3]は、要求されたバイト数が格納されます。
args[4]は、実際に書き込まれた実際のバイト数が格納されます。

read
開いているファイルから読み込みが行われたときに起動するプローブ。
args[0]は、ファイルに対応する fileinfo_t 構造体をポイントしています。
args[1]は、オペレーションの待ち時間が格納されます。
args[2]は、ファイルオフセットが格納されます。
args[3]は、要求されたバイト数が格納されます。
args[4]は、実際に読み取られたバイト数が格納されます。

fileinfo_t 構造体

typedef struct fileinfo {
         string fi_name;                 /* 名前 (basename of fi_pathname) */
         string fi_dirname;              /* ディレクトリ (dirname of fi_pathname) */
         string fi_pathname;             /* フルパス */
         offset_t fi_offset;             /* ファイル内のオフセット */
         string fi_fs;                   /* ファイルシステム */
         string fi_mount;                /* ファイルシステムのマウントポイント */
} fileinfo_t;
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0