Changeset 12682


Ignore:
Timestamp:
05/15/10 10:20:40 (12 years ago)
Author:
ehuelsmann
Message:

Add APIs to access data gathered in the profiler
to detect (lisp) hot spots.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/autoloads.lisp

    r12587 r12682  
    285285;; Profiler.
    286286(in-package "PROFILER")
    287 (export '(*granularity* show-call-counts with-profiling))
    288 (autoload 'show-call-counts "profiler")
     287(export '(*granularity* show-call-counts show-hot-counts with-profiling))
     288(autoload '(show-call-counts show-hot-counts) "profiler")
    289289(autoload-macro 'with-profiling "profiler")
    290290
  • trunk/abcl/src/org/armedbear/lisp/profiler.lisp

    r11391 r12682  
    4747
    4848(defstruct (profile-info
    49             (:constructor make-profile-info (object count)))
     49            (:constructor make-profile-info (object full-count hot-count)))
    5050  object
    51   count)
     51  full-count
     52  hot-count)
    5253
    5354;; Returns list of all symbols with non-zero call counts.
     
    5960          (when (fboundp sym)
    6061            (let* ((definition (fdefinition sym))
    61                    (count (sys:call-count definition)))
    62               (unless (zerop count)
     62                   (full-count (sys:call-count definition))
     63                   (hot-count (sys:hot-count definition)))
     64              (unless (zerop full-count)
    6365                (cond ((typep definition 'generic-function)
    64                        (push (make-profile-info definition count) result)
    65                        (dolist (method (mop::generic-function-methods definition))
    66                          (setf count (sys:call-count (sys:%method-function method)))
    67                          (unless (zerop count)
    68                            (push (make-profile-info method count) result))))
     66                       (push (make-profile-info definition
     67                                                full-count hot-count) result)
     68                       (dolist (method
     69                                 (mop::generic-function-methods definition))
     70                         (let ((function (sys:%method-function method)))
     71                           (setf full-count (sys:call-count function))
     72                           (setf hot-count (sys:hot-count function)))
     73                         (unless (zerop full-count)
     74                           (push (make-profile-info method full-count
     75                                                    hot-count) result))))
    6976                      (t
    70                        (push (make-profile-info sym count) result)))))))))
     77                       (push (make-profile-info sym full-count hot-count)
     78                             result)))))))))
    7179    (remove-duplicates result :key 'profile-info-object :test 'eq)))
    7280
     
    9199(defun show-call-count (info max-count)
    92100  (let* ((object (profile-info-object info))
    93          (count (profile-info-count info)))
     101         (count (profile-info-full-count info)))
     102    (if max-count
     103        (format t "~5,1F ~8D ~S~A~%"
     104                (/ (* count 100.0) max-count)
     105                count
     106                (object-name object)
     107                (if (object-compiled-function-p object)
     108                    ""
     109                    " [interpreted function]"))
     110        (format t "~8D ~S~A~%"
     111                count
     112                (object-name object)
     113                (if (object-compiled-function-p object)
     114                    ""
     115                    " [interpreted function]")))))
     116
     117(defun show-hot-count (info max-count)
     118  (let* ((object (profile-info-object info))
     119         (count (profile-info-hot-count info)))
    94120    (if max-count
    95121        (format t "~5,1F ~8D ~S~A~%"
     
    109135(defun show-call-counts ()
    110136  (let ((list (list-called-objects)))
    111     (setf list (sort list #'< :key 'profile-info-count))
     137    (setf list (sort list #'< :key 'profile-info-full-count))
    112138    (let ((max-count nil))
    113139      (when (eq *type* :time)
    114140        (let ((last-info (car (last list))))
    115141          (setf max-count (if last-info
    116                               (profile-info-count last-info)
     142                              (profile-info-full-count last-info)
    117143                              nil))
    118144          (when (eql max-count 0)
     
    120146      (dolist (info list)
    121147        (show-call-count info max-count))))
     148  (values))
     149
     150(defun show-hot-counts ()
     151  (let ((list (list-called-objects)))
     152    (setf list (sort list #'< :key 'profile-info-hot-count))
     153    (let ((max-count nil))
     154      (when (eq *type* :time)
     155        (let ((last-info (car (last list))))
     156          (setf max-count (if last-info
     157                              (profile-info-hot-count last-info)
     158                              nil))
     159          (when (eql max-count 0)
     160            (setf max-count nil))))
     161      (dolist (info list)
     162        (show-hot-count info max-count))))
    122163  (values))
    123164
Note: See TracChangeset for help on using the changeset viewer.