【问题标题】:Is there any alterntive to wait3 to get rusage structure in shell scripting?是否有其他方法可以等待在 shell 脚本中获得 rusage 结构?
【发布时间】:2016-08-03 06:17:21
【问题描述】:

我试图监控子进程的峰值内存使用情况。time -v 是一个选项,但它在 solaris 中不起作用。那么有什么方法可以从 shell 脚本中获取 rusage 结构中的详细信息?

【问题讨论】:

    标签: linux time solaris rusage


    【解决方案1】:

    你可以使用/usr/bin/timex

    来自the /usr/bin/timex man page

    给定的命令被执行;经过时间、用户时间和系统 执行时间以秒为单位报告。可选地,处理 可以列出命令及其所有子项的会计数据或 执行间隔期间的汇总和总系统活动 可以举报。

    ...

    -p 列出命令及其所有子进程的进程记帐记录。 此选项仅在安装了流程记帐软件时才有效。 子选项 f、h、k、m、r 和 t 修改数据项 报道。选项如下:

    ...

    acctadm 的手册页开始,以启用进程记帐。

    请注意,在 Solaris 上,getrusage()wait3() 不会返回内存使用统计信息。请参阅http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/syscall/rusagesys.c 上的(有些过时的)getrusage() 源代码和http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/sys/common/wait.c#158 上的wait3() 源代码(这实际上是 OpenSolaris 源代码,Oracle 放弃了对它的支持,它可能不代表当前的 Solaris 实现,尽管Solaris 11.2 上的少数测试表明 RSS 数据实际上仍然为零。)

    另外,来自Solaris getrusage() man page

    ru_maxrssru_ixrssru_idrssru_isrss 成员 rusage 结构在此实现中设置为 0。

    几乎可以肯定还有其他获取数据的方法,例如dtrace

    编辑:

    dtrace 看起来没有多大帮助,不幸的是。尝试使用 dtrace -s memuse.d -c bash 运行此 dtrace 脚本

    #!/usr/sbin/dtrace -s
    
    #pragma D option quiet
    
    profile:::profile-1001hz
    / pid == $target /
    {
        @pct[ pid ] = max( curpsinfo->pr_pctmem );
    }
    
    dtrace:::END
    {
        printa( "pct: %@u %a\n", @pct );
    }
    

    导致以下错误信息:

    dtrace: failed to compile script memuse.d: line 8: translator does not define conversion for member: pr_pctmem
    

    dtrace 在 Solaris 上似乎不提供对进程内存使用情况的访问。事实上,procfs 数据的 Solaris 11.2 /usr/lib/dtrace/procfs.d 转换器中有这样的注释:

    /*
     * Translate from the kernel's proc_t structure to a proc(4) psinfo_t struct.
     * We do not provide support for pr_size, pr_rssize, pr_pctcpu, and pr_pctmem.
     * We also do not fill in pr_lwp (the lwpsinfo_t for the representative LWP)
     * because we do not have the ability to select and stop any representative.
     * Also, for the moment, pr_wstat, pr_time, and pr_ctime are not supported,
     * but these could be supported by DTrace in the future using subroutines.
     * Note that any member added to this translator should also be added to the
     * kthread_t-to-psinfo_t translator, below.
     */
    

    浏览 Illumos.org 源代码,搜索 ps_rssize,表明 procfs 数据仅在需要时计算,并且不会在进程运行时不断更新。 (见http://src.illumos.org/source/search?q=pr_rssize&defs=&refs=&path=&hist=&project=illumos-gate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2012-07-10
      • 2022-08-18
      • 2018-06-17
      相关资源
      最近更新 更多