Custom instruments how to output aggregations like dtrace script

♀尐吖头ヾ 提交于 2019-12-24 09:58:37

问题


I am trying to convert below dtrace script to custom instrument. How should we configure the END probe to show the output the aggregated output.

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);
}

来源:https://stackoverflow.com/questions/17925261/custom-instruments-how-to-output-aggregations-like-dtrace-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!