Open Bug 990790 Opened 8 years ago Updated 6 years ago

Allow using Linux perf_event counters with the Gecko profiler

Categories

(Core :: Gecko Profiler, defect)

All
Linux
defect
Not set
normal

Tracking

()

People

(Reporter: jld, Unassigned)

References

Details

Attachments

(3 files)

Something I realized last week — and which it turns out the rr project has apparently been using for quite some time — is that a perf_event fd can be set O_ASYNC and configured to deliver a signal to a given task or process group, in addition to its usual sampling; with F_SETSIG, this can be any signal.  So it's possible to create a perf_event fd to sample a given task (== thread), then set the signal target to that task with F_SETOWN, and now the thread has an interval timer for anything from CPU cycles to page faults to context switches.

The key point is that this stops the thread when a sample occurs and lets us run code that we control on it in userspace, so we can do all the pseudostack processing (and integration with markers) that we normally do, without needing kernel changes.  And if we can patch the kernel, then we can add arbitrary probe points; see also bug 948648.

As an added bonus, this lets us avoid the build issues that existed with the perf tool on B2G.
Duplicate of this bug: 989589
(In reply to Jed Davis [:jld] from comment #0)
> As an added bonus, this lets us avoid the build issues that existed with the
> perf tool on B2G.

Just curious. What were these?
This patch changes the profiler from counting milliseconds to counting page faults.  It doesn't work yet with non-main threads in child processes (or any processes on non-b2g), because a non-superuser task can apparently only attach perf to itself, not another task with the same uid.  Also, it's substantially hacky at present; more of of a proof of concept than anything.
Also, it helps to be able to unwind out of memset and memcpy when profiling page faults (and this may also apply to the planned work on COW events).  There are several variants of those routines in hand-written assembly, and some of them didn't have unwind info; this fixes that.  (I haven't looked at x86 Android or glibc yet.)
This is an interesting thing for the profiler to be able to do, so it would be nice if someone tried to pick it up, but I haven't been working on profiling for quite some time.
Assignee: jld → nobody
You need to log in before you can comment on or make changes to this bug.