lehe <timlee126@...> writes:
> 1. Is oprofile better than gprof in terms of helping optimizing code time
> performance? Like checking branch misprediction, etc;
gprof and oprofile are quite different.
gprof works on a single binary instrumented (by GCC) to measure execution. So
it can eg. compute exact call counts.
oprofile works on the entire system (all processes, interrupt handlers, ...)
and uses sampling (so results are statistical, not exact).
oprofile can use CPU performance counters to get detailed information about
the execution of the CPU, so is probably better for branch misprediction.
> 2. Why does oprofile require root while gprof doesn't?
It needs root since it works on the entire system and accesses non-sharable
hardware counters, and uses a kernel interface that is not protected for
indivial user access.
I think perhaps perfmon2 can profile a single binary without root privileges,
but it require patching the kernel (which does require root of course), so may
not help you.