【问题标题】:Disk Activity in ApplescriptApplescript 中的磁盘活动
【发布时间】:2010-09-09 01:10:23
【问题描述】:

如何在 Applescript 中轮询磁盘活动?每 N 秒检查一次磁盘 X 是否正在被读取、写入或空闲,然后执行一些操作。

【问题讨论】:

    标签: macos io applescript


    【解决方案1】:

    一般来说,轮询的效率低于在发生某事时得到通知。此外,如果您正在检查是否正在从磁盘读取某些内容,您可能会自己访问该磁盘,这可能会影响您尝试观察的内容。

    从 10.5 开始,OSX 包含一个称为文件系统事件框架的东西,它提供文件系统更改的课程粒度通知。你的问题是这只是Objective-C。 Apple 对此 API 有一些很好的documentation

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

    我都没有这方面的经验,因此参考了文档。希望这能让你继续前进。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:

          正如Porkchop D. Clown 提到的,您可以使用 iostat。您可以使用的命令是:

           iostat -c 50 -w 5
          

          每 5 秒运行 iostat 50 次。

          【讨论】:

            猜你喜欢
            • 2013-03-09
            • 2010-09-28
            • 1970-01-01
            • 1970-01-01
            • 2019-12-04
            • 2014-02-08
            • 2021-09-22
            • 2022-01-17
            相关资源
            最近更新 更多