自定义工具如何输出像dtrace脚本这样的聚合

时间:2013-07-29 13:22:38

标签: instruments dtrace

我正在尝试将以下dtrace脚本转换为自定义工具。我们应该如何配置END探针以显示聚合输出的输出。

pid$target:myApp:main:entry/((pid == $target))/{
    starttime = timestamp;
}

objc$target:myApp*::entry/((pid == $target))/{
    starttimeformethod[probemod,probefunc] = timestamp;
    methodhasenteredatleastonce[probemod,probefunc] = 1;
}

objc$target:myApp*::return/((( /*XRAYPREDICATELHS*/(methodhasenteredatleastonce[probemod,probefunc] == 1/*XRAYPREDICATERHS*/)) && ((pid == $target))))/{

    this->executiontime = (timestamp - starttimeformethod[probemod,probefunc]) / 1000;
    @overallexecutions[probemod,probefunc] = count();
    @overallexecutiontime[probemod,probefunc] = sum(this->executiontime);
    @averageexecutiontime[probemod,probefunc] = avg(this->executiontime);
}

END 
{
    milliseconds = (timestamp - starttime) / 1000000;
    normalize(@overallexecutiontime, 1000);
    printf("Ran for %u ms\n", milliseconds);
    printf("%30s, %30s, %20s, %20s, %20s\n", "Class", "Method", "Total CPU time (ms)",  "Executions", "Average CPU time (us)");
    printa("%30s, %30s, %20@u, %20@u, %20@u\n", @overallexecutiontime, @overallexecutions, @averageexecutiontime);
}

0 个答案:

没有答案