1

我正在尝试将以下 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);
}
4

0 回答 0