branch: externals/ergoemacs-mode commit 581be0674d69b457dee9791d5445f8eeca2598ca Author: Walter Landry <wlan...@caltech.edu> Commit: Walter Landry <wlan...@caltech.edu>
Remove lots of timing code --- ergoemacs-lib.el | 227 ------------------------------------------------------- 1 file changed, 227 deletions(-) diff --git a/ergoemacs-lib.el b/ergoemacs-lib.el index 4abe2ae..9366819 100644 --- a/ergoemacs-lib.el +++ b/ergoemacs-lib.el @@ -550,72 +550,6 @@ to the `warn' function." (defvar ergoemacs-mn-len nil) (defvar ergoemacs-mx-len nil) - -(defvar ergoemacs-timing-results-buffer "*Ergoemacs Profiling Results*" - "Buffer name for outputting profiling results.") - -(defun ergoemacs-timing-sort-by-call-count (vec1 vec2) - "Sort by highest call count. See `sort'." - (>= (aref vec1 0) (aref vec2 0))) - -(defun ergoemacs-timing-sort-by-total-time (vec1 vec2) - "Sort by highest total time spent in function. See `sort'." - (>= (aref vec1 1) (aref vec2 1))) - -(defun ergoemacs-timing-sort-by-average-time (vec1 vec2) - "Sort by highest average time spent in function. See `sort'." - (>= (aref vec1 2) (aref vec2 2))) - - -(defcustom ergoemacs-timing-sort-by-function - 'ergoemacs-timing-sort-by-total-time - "Non-nil specifies ELP results sorting function. -These functions are currently available: - - `ergoemacs-timing-sort-by-call-count' -- sort by the highest call count - `ergoemacs-timing-sort-by-total-time' -- sort by the highest total time - `ergoemacs-timing-sort-by-average-time' -- sort by the highest average times - -You can write your own sort function. It should adhere to the -interface specified by the PREDICATE argument for `sort'. Each -\"element of LIST\" is really a 4 element vector where element 0 -is the call count, element 1 is the total time spent in the -function, element 2 is the average time spent in the function, -and element 3 is the symbol's name string." - :type 'function - :group 'ergoemacs-mode) - -(defsubst ergoemacs-timing-pack-number (number width) - "Pack the NUMBER string into WIDTH characters, watching out for -very small or large numbers" - (if (<= (length number) width) - number - ;; check for very large or small numbers - (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number) - (concat (substring - (match-string 1 number) - 0 - (- width (match-end 2) (- (match-beginning 2)) 3)) - "..." - (match-string 2 number)) - (substring number 0 width)))) - -(defun ergoemacs-timing-results-jump-to-component (&optional event) - "Jump to component linked to the current button. -EVENT is used when this is calledf rom a mouse event." - (interactive (list last-nonmenu-event)) - (if event (posn-set-point (event-end event))) - (ergoemacs-component-find-definition - (get-text-property (point) 'ergoemacs-component))) - -(defvar ergoemacs-timing-component-map - (let ((map (make-sparse-keymap))) - (define-key map [mouse-1] 'ergoemacs-timing-results-jump-to-component) - (define-key map [follow-link] 'mouse-face) - (define-key map "\C-m" 'ergoemacs-timing-results-jump-to-component) - map) - "Keymap used on the component maps.") - (defcustom ergoemacs-timing-find-regexp (concat"^\\s-*(ergoemacs-timing" find-function-space-re "%s\\(\\s-\\|$\\)") "The regexp used by `ergoemacs-timing-find-no-select' to search for a timing definition. @@ -628,167 +562,6 @@ insert the face name." (unless (assoc 'ergoemacs-timing find-function-regexp-alist) (push (cons 'ergoemacs-timing 'ergoemacs-timing-find-regexp) find-function-regexp-alist)) -(defun ergoemacs-timing-find-no-select (timing-definition file) - "Find TIMING-DEFINITION in FILE. -This uses `find-function-search-for-symbol'." - (let* ((el-file (and file (concat (file-name-sans-extension file) ".el"))) - (sym (intern (format "%s" timing-definition)))) - (find-function-search-for-symbol sym 'ergoemacs-timing el-file))) - -(defun ergoemacs-timing-results-jump (&optional event) - "Jump to timing item linked to the current button. -EVENT is used when this is called from a mouse event." - (interactive (list last-nonmenu-event)) - (if event (posn-set-point (event-end event))) - (let ((file (get-text-property (point) 'ergoemacs-timing-file)) - (symbol (get-text-property (point) 'ergoemacs-timing-symbol))) - (when file - (ergoemacs-component-find-1 - symbol 'ergoemacs-timing 'switch-to-buffer - (save-excursion - (ergoemacs-timing-find-no-select symbol file)))))) - -(defvar ergoemacs-timing-jump-map - (let ((map (make-sparse-keymap))) - (define-key map [mouse-1] 'ergoemacs-timing-results-jump) - (define-key map [follow-link] 'mouse-face) - (define-key map "\C-m" 'ergoemacs-timing-results-jump) - map) - "Jump to a timing definition.") - -(defun ergoemacs-timing-output-result--sym (symname &optional file) - "Insert SYMNAME with appropriate links." - (let ((sym (format "%s" symname))) - (unless (catch 'found - (dolist (lst '(("initialize-\\(.*\\)\\'" "Initialize ") - ("create-component-\\(.*\\)\\'" "Create Component ") - ("translate-keymap-\\(.*\\)\\'" "Translate Keymap "))) - (when (string-match (nth 0 lst) sym) - (insert (nth 1 lst) - (propertize (match-string 1 sym) - 'ergoemacs-component (intern (match-string 1 sym)) - 'keymap ergoemacs-timing-component-map - 'mouse-face 'highlight - 'face 'link - 'help-echo "mouse-1 or RET jumps to definition")) - (throw 'found t))) - nil) - (if file - (insert (propertize sym - 'ergoemacs-timing-symbol (intern sym) - 'ergoemacs-timing-file file - 'keymap ergoemacs-timing-jump-map - 'mouse-face 'highlight - 'face 'link - 'help-echo "mouse-1 or RET jumps to definition")) - (insert sym))))) - -(defun ergoemacs-timing-output-result (resultvec) - "Output the RESULTVEC into the results buffer. RESULTVEC is a 4 -or more element vector where aref 0 is the call count, aref 1 is -the total time spent in the function, aref 2 is the average time -spent in the function, aref 3 is the minimum time spent on the -function, aref 4 is the maximum time spend on the function, and -aref 3 is the symbol's string name. All other elements in the -vector are ignored." - (let* ((cc (aref resultvec 0)) - (tt (aref resultvec 1)) - (at (aref resultvec 2)) - (mn (aref resultvec 3)) - (mx (aref resultvec 4)) - (symname (aref resultvec 5)) - (file (aref resultvec 6)) - callcnt totaltime avetime mntime mxtime) - (setq callcnt (number-to-string cc) - totaltime (number-to-string tt) - avetime (number-to-string at) - mntime (number-to-string mn) - mxtime (number-to-string mx)) - ;; possibly prune the results - (ergoemacs-timing-output-result--sym symname file) - (insert-char 32 (+ ergoemacs-field-len (- (length symname)) 2)) - ;; print stuff out, formatting it nicely - (insert callcnt) - (insert-char 32 (+ ergoemacs-cc-len (- (length callcnt)) 2)) - (let ((ttstr (ergoemacs-timing-pack-number totaltime ergoemacs-et-len)) - (atstr (ergoemacs-timing-pack-number avetime ergoemacs-at-len)) - (mnstr (ergoemacs-timing-pack-number mntime ergoemacs-mn-len)) - (mxstr (ergoemacs-timing-pack-number mxtime ergoemacs-mx-len))) - (insert ttstr) - (insert-char 32 (+ ergoemacs-et-len (- (length ttstr)) 2)) - (insert atstr) - (insert-char 32 (+ ergoemacs-at-len (- (length atstr)) 2)) - (insert mnstr) - (insert-char 32 (+ ergoemacs-mn-len (- (length mnstr)) 2)) - (insert mxstr)) - (insert "\n"))) - -(defun ergoemacs-timing-results () - "Display current ergoemacs-mode profiling results. -Based on `elp-results'." - (interactive) - (let ((curbuf (current-buffer)) - (resultsbuf (get-buffer-create ergoemacs-timing-results-buffer))) - (set-buffer resultsbuf) - (erase-buffer) - ;; get the length of the longest function name being profiled - (let* ((longest 0) - (title "What") - (titlelen (length title)) - (ergoemacs-field-len titlelen) - (cc-header "Count") - (ergoemacs-cc-len (length cc-header)) - (et-header "Elapsed") - (ergoemacs-et-len (length et-header)) - (at-header "Average") - (ergoemacs-at-len (length at-header)) - (mn-header "Min") - (ergoemacs-mn-len (length mn-header)) - (mx-header "Max") - (ergoemacs-mx-len (length mx-header)) - (resvec '())) - (maphash - (lambda(key item) - (let* ((symname (format "%s" key)) - (cc (aref item 0)) - (tt (aref item 1)) - (mn (aref item 2)) - (mx (aref item 3)) - (file (aref item 4))) - (setq longest (max longest (length symname))) - (push (vector cc tt (if (zerop cc) 0.0 - (/ (float tt) (float cc))) - mn mx symname file) - resvec))) - ergoemacs-timing-hash) - (setq ergoemacs-field-len (max titlelen longest)) - (let ((column 0)) - (setq header-line-format - (mapconcat - (lambda (title) - (prog1 - (concat - (propertize " " - 'display (list 'space :align-to column) - 'face 'fixed-pitch) - title) - (setq column (+ column 2 - (if (= column 0) - ergoemacs-field-len - (length title)))))) - (list title cc-header et-header at-header - mn-header mx-header) ""))) - ;; if sorting is enabled, then sort the results list. in either - ;; case, call ergoemacs-timing-output-result to output the result in the - ;; buffer - (if ergoemacs-timing-sort-by-function - (setq resvec (sort resvec ergoemacs-timing-sort-by-function))) - (mapc #'ergoemacs-timing-output-result resvec)) - ;; now pop up results buffer - (set-buffer curbuf) - (pop-to-buffer resultsbuf) - (goto-char (point-min)))) - (provide 'ergoemacs-lib) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ergoemacs-lib.el ends here