Applescript中的磁盘活动

时间:2008-09-15 17:05:19

标签: macos io applescript

如何在Applescript中轮询磁盘活动?检查磁盘X是否每N秒读取,写入或空闲并执行某些操作。

4 个答案:

答案 0 :(得分:2)

通常,轮询的效率低于发生事件时通知的效率。此外,如果您正在检查某些内容是否正在从磁盘读取,您可能会自己访问所述磁盘,可能会影响您要观察的内容。

自10.5以来,OSX包含了一个名为文件系统事件框架的东西,该框架提供了文件系统更改的课程粒度通知。您的问题是这只是Objective-C。关于这个API,Apple有一些不错的documentation

幸运的是,还有call method AppleScript命令。这允许您使用AppleScript中的Objective-C对象。这是documentation

我也没有任何经验,因此文档参考。希望这可以让你前进。

答案 1 :(得分:0)

您可以定期运行终端命令iostat。您必须将结果解析为可以消化的形式。

如果您对各种UNIX命令行工具了解得足够多,我建议iostat将输出管道输出到awk或sed以提取您想要的信息。

答案 2 :(得分:0)

你应该真的看看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);
}

来自here

运行使用

sudo dtrace -s bitsize.d

答案 3 :(得分:0)

如上所述Porkchop D. Clown,您可以使用iostat。您可以使用的命令是:

 iostat -c 50 -w 5

每5秒运行iostat 50次。