At 06 Nov 2007 19:40:28 +0200,
Juho Snellman wrote:
> > This has numerous flaws:
> > - Does not handle the effects of GC on code. (It shouldn't be
> > very hard to fix this, to my understanding, just stick the
> > unregister-at-the-old-place/register-at-the-new-place calls
> > inside the GC.)
> Another option would be to maintain a weak-keyed code object -> pc
> hash-table, and have an after-gc-hook that checks for code objects
> that moved, and registers/deregisters them with oprofile. This would
> have the benefit of keeping the whole thing Lisp-side.
> (It seems to me that all of the other stuff that the patch touches in
> the runtime would also be better off living in Lisp).
I've had this gut feeling as well, in fact. In reality I chose a
quick-and-dirty route first, as getting some sleep was a priority atm..
> > - It is not precise, as it doesn't count the code object entry
> > points (of which, if I'm understanding it correctly, there
> > can be a multitude.) It basically means that it would underestimate
> > the statistics for the often-called quick-running functions.
> Can't say whether you're understanding things correctly, since you
> forgot to attach heap-annotation.lisp :)
Whoops, that's what happens when you rely on git-diff to give you the
full delta... Attached it below.
By the way, the thing has now got a permanent branch off SBCL master
(Yes, the SSL certificate is invalid...)
> > - It does not, to my knowledge, handle any of the code which
> > was loaded from the core, as the only two code object
> > registration paths handled are %COMPILE and LOAD-AS-FASL.
> > (Should also be trivial to fix.)
> You can get the code objects with MAP-ALLOCATED-OBJECTS, look for
> objects of type SB-KERNEL:CODE-COMPONENT.
regards, Samium Gromoff
---( src/code/heap-annotation.lisp )----------------------------------
(sb!alien:define-alien-routine op-open-agent sb!alien:int)
(sb!alien:define-alien-routine op-do-write-native-code sb!alien:void
(sb!alien:define-alien-routine op-do-unload-native-code sb!alien:void
(sb!alien:define-alien-routine op-close-agent sb!alien:void)
(defun oprofile-announce-code-object (code-object size)
(let ((dinfo (%code-debug-info code-object)))
(let ((name (and dinfo (sb!c::debug-info-name dinfo))))
(let ((addr (code-instructions code-object)))
(op-do-write-native-code (format nil "~S" name) addr size))))))
(defun oprofile-closedown-code-object (code-object)
(op-do-unload-native-code (code-instructions code-object)))