Skip to content

Commit

Permalink
core: display time spent in user-config in home buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Jun 16, 2018
1 parent d3c5945 commit f1f8db0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
23 changes: 13 additions & 10 deletions core/core-configuration-layer.el
Original file line number Diff line number Diff line change
Expand Up @@ -2446,18 +2446,21 @@ depends on it."
(let ((stats (configuration-layer/configured-packages-stats
configuration-layer--used-packages)))
(spacemacs-buffer/insert-page-break)
(spacemacs-buffer/append
(format "\n%s packages loaded in %.3fs (e:%s r:%s l:%s b:%s)"
(cadr (assq 'total stats))
configuration-layer--spacemacs-startup-time
(cadr (assq 'elpa stats))
(cadr (assq 'recipe stats))
(cadr (assq 'local stats))
(cadr (assq 'built-in stats))))
(with-current-buffer (get-buffer-create spacemacs-buffer-name)
(let ((buffer-read-only nil))
(spacemacs-buffer//center-line)
(insert "\n")))))
(spacemacs-buffer/append
(format "\n%s packages loaded in %.3fs (e:%s r:%s l:%s b:%s)"
(cadr (assq 'total stats))
configuration-layer--spacemacs-startup-time
(cadr (assq 'elpa stats))
(cadr (assq 'recipe stats))
(cadr (assq 'local stats))
(cadr (assq 'built-in stats))))
(spacemacs-buffer//center-line)
(spacemacs-buffer/append (format "\n(%.3fs spent in your user-config)"
dotspacemacs--user-config-elapsed-time))
(spacemacs-buffer//center-line)
(insert "\n")))))

(defun configuration-layer//get-indexed-elpa-package-names ()
"Return a list of all ELPA packages in indexed packages and dependencies."
Expand Down
16 changes: 15 additions & 1 deletion core/core-dotspacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
(defconst dotspacemacs-test-results-buffer "*dotfile-test-results*"
"Name of the buffer to display dotfile test results.")

(defvar dotspacemacs--user-config-elapsed-time 0
"Time spent in `dotspacemacs/user-config' function.
Useful for users in order to given them a hint of potential bottleneck in
their configuration.")

(let* ((env (getenv "SPACEMACSDIR"))
(env-dir (when env (expand-file-name (concat env "/"))))
(env-init (and env-dir (expand-file-name "init.el" env-dir)))
Expand Down Expand Up @@ -500,6 +505,14 @@ Returns non nil if the layer has been effectively inserted."
(load-file (dotspacemacs/location))
t))

(defun dotspacemacs//profile-user-config (f &rest args)
"Compute time taken by the `dotspacemacs/user-config' function.
Set the variable"
(let ((stime (current-time)))
(apply f args)
(setq dotspacemacs--user-config-elapsed-time
(float-time (time-subtract (current-time) stime)))))

(defun dotspacemacs/sync-configuration-layers (&optional arg)
"Synchronize declared layers in dotfile with spacemacs.
Expand Down Expand Up @@ -644,7 +657,8 @@ If ARG is non nil then Ask questions to the user before installing the dotfile."
(if (file-exists-p dotspacemacs)
(unless (with-demoted-errors "Error loading .spacemacs: %S"
(load dotspacemacs))
(dotspacemacs/safe-load)))))
(dotspacemacs/safe-load))))
(advice-add 'dotspacemacs/user-config :around 'dotspacemacs//profile-user-config))

(defun spacemacs/title-prepare (title-format)
"A string is printed verbatim except for %-constructs.
Expand Down

0 comments on commit f1f8db0

Please sign in to comment.