refactor: record doom-init-time in doom-after-init-hook

This commit is contained in:
Henrik Lissner 2022-09-23 22:03:38 +02:00
parent dda848e089
commit a3a275624e
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 10 additions and 11 deletions

View file

@ -262,9 +262,6 @@ If this is a daemon session, load them all immediately instead."
;;
;;; Benchmark
(defvar doom-init-time nil
"The time it took, in seconds, for Doom Emacs to initialize.")
(defun doom-display-benchmark-h (&optional return-p)
"Display a benchmark including number of packages and modules loaded.
@ -273,9 +270,7 @@ If RETURN-P, return the message as a string instead of displaying it."
"Doom loaded %d packages across %d modules in %.03fs"
(- (length load-path) (length (get 'load-path 'initial-value)))
(hash-table-count doom-modules)
(or doom-init-time
(setq doom-init-time
(float-time (time-subtract (current-time) before-init-time))))))
doom-init-time))
;;
@ -370,11 +365,7 @@ If RETURN-P, return the message as a string instead of displaying it."
;; time, and by keeping a history of them, you get a snapshot
;; of your config in time.
(file-name-concat
doom-profile-dir (format "init.%d.elc" emacs-major-version)))
;; If the config is being reloaded, let's pretend it hasn't be
;; initialized by unsetting this (see note in
;; `doom-profile--generate-load-modules' for details).
doom-init-time)
doom-profile-dir (format "init.%d.elc" emacs-major-version))))
;; If `user-init-file' is t, then `load' will store the name of
;; the next file it loads into `user-init-file'.
(setq user-init-file t)

View file

@ -163,6 +163,9 @@
(defconst doom-modules-version "22.09.0-pre"
"Current version of Doom Emacs.")
(defvar doom-init-time nil
"The time it took, in seconds, for Doom Emacs to initialize.")
(defconst doom-profile
(if-let (profile (getenv-internal "DOOMPROFILE"))
(save-match-data
@ -592,6 +595,11 @@ triggered. This is the absolute latest point in the startup process."
(dolist (var '(exec-path load-path process-environment))
(put var 'initial-value (default-toplevel-value var)))))
(add-hook! 'doom-after-init-hook :depth -110
(defun doom--end-init-h ()
"Set `doom-init-time'."
(setq doom-init-time (float-time (time-subtract (current-time) before-init-time)))))
;; This is the absolute latest a hook can run in Emacs' startup process.
(define-advice command-line-1 (:after (&rest _) run-after-init-hook)
(doom-run-hooks 'doom-after-init-hook))