Applescriptでディスクアクティビティをポーリングするにはどうすればよいですか?ディスクXがN秒ごとに読み取り、書き込み、またはアイドル状態になっているかどうかを確認し、何かを実行します。
4 に答える
一般に、ポーリングは、何かが発生したときに通知を受けるよりも効率的ではありません。さらに、何かがディスクから読み取られているかどうかを確認している場合、おそらくそのディスクに自分でアクセスしており、観察しようとしているものに影響を与える可能性があります。
10.5 以降、OSX にはファイル システム イベント フレームワークと呼ばれるものが含まれています。これは、ファイル システムへの変更をきめ細かく通知します。あなたの場合の問題は、これがObjective-Cのみであることです。Apple には、この API に関する優れたドキュメントがあります。
幸いなことに、call method
AppleScript コマンドもあります。これにより、AppleScript 内から Objective-C オブジェクトを操作できます。これに関するドキュメントがあります。
私はどちらも経験がないため、ドキュメントを参照しています。うまくいけば、これでうまくいくはずです。
ターミナルコマンドiostatを定期的に実行できます。結果を解析して、消化できる形式にする必要があります。
さまざまなUNIXコマンドラインツールについて十分に知っている場合は、iostatが出力をawkまたはsedにパイプして、必要な情報だけを抽出することをお勧めします。
Dtrace を実際に確認する必要があります。このようなことを行う能力があります。
#!/usr/sbin/dtrace -s
/*
* bitesize.d - analyse disk I/O size by process.
* Written using DTrace (Solaris 10 build 63).
*
* This produces a report for the size of disk events caused by
* processes. These are the disk events sent by the block I/O driver.
*
* If applications must use the disks, we generally prefer they do so
* sequentially with large I/O sizes.
*
* 15-Jun-2005, ver 1.00
*
* USAGE: bitesize.d # wait several seconds, then hit Ctrl-C
*
* FIELDS:
* PID process ID
* CMD command and argument list
* value size in bytes
* count number of I/O operations
*
* NOTES:
* The application may be requesting smaller sized operations, which
* are being rounded up to the nearest sector size or UFS block size.
* To analyse what the application is requesting, DTraceToolkit programs
* such as Proc/fddist may help.
*
* SEE ALSO: seeksize.d, iosnoop
*
* Standard Disclaimer: This is freeware, use at your own risk.
*
* 31-Mar-2004 Brendan Gregg Created this, build 51.
* 10-Oct-2004 " " Rewrote to use the io provider, build 63.
*/
#pragma D option quiet
/*
* Print header
*/
dtrace:::BEGIN
{
printf("Sampling... Hit Ctrl-C to end.\n");
}
/*
* Process io start
*/
io:::start
{
/* fetch details */
this->size = args[0]->b_bcount;
cmd = (string)curpsinfo->pr_psargs;
/* store details */
@Size[pid,cmd] = quantize(this->size);
}
/*
* Print final report
*/
dtrace:::END
{
printf("\n%8s %s\n","PID","CMD");
printa("%8d %s\n%@d\n",@Size);
}
ここから。
実行するには
sudo dtrace -s bitsize.d
Porkchop D. Clownが述べたように、iostat を使用できます。使用できるコマンドは次のとおりです。
iostat -c 50 -w 5
これにより、iostat が 5 秒ごとに 50 回実行されます。