Changeset 10463


Ignore:
Timestamp:
Aug 13, 2008, 6:46:28 PM (11 years ago)
Author:
wws
Message:

Simple interface to mtrace, for finding malloc memory leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/library/leaks.lisp

    r10404 r10463  
    205205        (push i res)))
    206206    res))
     207
     208;; Linux-only malloc leak finding
     209#+(and :linux-host :linux-target)
     210(progn
     211
     212(defun start-mtrace (log-file)
     213  (touch log-file)
     214  (setf log-file (probe-file log-file))
     215  (setenv "MALLOC_TRACE" (namestring log-file))
     216  (gc)
     217  (#_mtrace))
     218
     219(defun end-mtrace ()
     220  (gc)
     221  (#_muntrace))
     222
     223(defun parse-mtrace-log (log-file)
     224  (with-open-file (s log-file)
     225    (let ((hash (make-hash-table :test 'equal))
     226          (eof (list :eof)))
     227      (loop for line = (read-line s nil eof)
     228            until (eq line eof)
     229            when (and (> (length line) 2)
     230                      (equal "@ " (subseq line 0 2)))
     231              do
     232           (setf line (subseq line 2))
     233           (let ((plus-pos (search " + " line))
     234                 (minus-pos (search " - " line)))
     235             (cond (plus-pos
     236                    (let* ((where (subseq line 0 plus-pos))
     237                           (addr-and-size (subseq line (+ plus-pos 3)))
     238                           (space-pos (position #\space addr-and-size))
     239                           (addr (subseq addr-and-size 0 space-pos))
     240                           (size (subseq addr-and-size (1+ space-pos))))
     241                      (setf (gethash addr hash) (list where size))))
     242                   (minus-pos
     243                    (let ((addr (subseq line (+ minus-pos 3))))
     244                      (remhash addr hash))))))
     245      (let ((res nil))
     246        (maphash (lambda (key value)
     247                   (push (append value (list key)) res))
     248                 hash)
     249        res))))
     250
     251)  ;; end of linux-only code
Note: See TracChangeset for help on using the changeset viewer.