Changeset 12711


Ignore:
Timestamp:
Aug 28, 2009, 1:45:18 PM (10 years ago)
Author:
gz
Message:

From Dominic Schulz: extend parse-mtrace-log to take into account frees and reallocs, add pretty-print-mtrace-summary

File:
1 edited

Legend:

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

    r12339 r12711  
    235235  (with-open-file (s log-file)
    236236    (let ((hash (make-hash-table :test 'equal))
     237          (free-list '())
    237238          (eof (list :eof)))
    238239      (loop for line = (read-line s nil eof)
     
    242243              do
    243244           (setf line (subseq line 2))
    244            (let ((plus-pos (search " + " line))
    245                  (minus-pos (search " - " line)))
     245           (let ((plus-pos (or (search " + " line) (search " > " line)))
     246                 (minus-pos (or (search " - " line) (search " < " line))))
    246247             (cond (plus-pos
    247248                    (let* ((where (subseq line 0 plus-pos))
     
    252253                      (setf (gethash addr hash) (list where size))))
    253254                   (minus-pos
    254                     (let ((addr (subseq line (+ minus-pos 3))))
    255                       (remhash addr hash))))))
     255                    (let* ((where (subseq line 0 minus-pos))
     256                           (addr (subseq line (+ minus-pos 3)))
     257                           (found (nth-value 1 (gethash addr hash))))
     258                      (if found
     259                        (remhash addr hash)
     260                        (push (list where addr) free-list)))))))
    256261      (let ((res nil))
    257262        (maphash (lambda (key value)
    258263                   (push (append value (list key)) res))
    259264                 hash)
    260         res))))
     265        (values res free-list)))))
     266
     267(defun pretty-print-mtrace-summary (file)
     268  (let* ((malloc-sum 0))
     269    (multiple-value-bind (mallocs frees) (parse-mtrace-log file)
     270      (dolist (i mallocs)
     271        (incf malloc-sum (parse-integer (second i) :radix 16 :start 2))
     272        (format t "~&~A" i))
     273      (format t "~&Freed but not malloced:~%~{~A~%~}" frees)
     274      (format t "~&total-malloc-not-freed: ~~A ~A free not malloc: ~A"
     275              (/ malloc-sum 1024.0)
     276              (length mallocs)
     277              (length frees)))))
    261278
    262279;; Return the total number of bytes allocated by malloc()
Note: See TracChangeset for help on using the changeset viewer.