问题
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