This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/core-debug.el
justbur ddf9d3f647 core: Add missing require
Mostly for compiler, but also makes the dependencies clearer
2015-12-21 00:42:38 -05:00

60 lines
2.1 KiB
EmacsLisp

;;; core-debug.el --- Spacemacs Core File
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(require 'profiler)
;; Keep debug-on-error on for stuff that is lazily loaded
(add-hook 'after-init-hook (lambda () (setq debug-on-error t)))
(when (member "--profile" command-line-args)
(setq command-line-args (delete "--profile" command-line-args))
(profiler-start 'cpu+mem)
(add-hook 'after-init-hook
(lambda ()
(run-with-idle-timer 2 nil (lambda ()
(profiler-report)
(profiler-stop))))))
(when (member "--timed-requires" command-line-args)
(setq command-line-args (delete "--timed-requires" command-line-args))
(defvar spacemacs-load-time-threshold 0.15
"Generate message if file takes longer than this number of
seconds to load")
(with-current-buffer (get-buffer-create "*load-times*")
(insert (format "All files that took longer than %.3f seconds to load\n\n"
spacemacs-load-time-threshold)))
(defadvice require (around spacemacs//timed-require activate)
(let ((start (current-time)) res delta)
(setq res ad-do-it
delta (float-time (time-since start)))
(when (> delta spacemacs-load-time-threshold)
(with-current-buffer "*load-times*"
(goto-char (point-max))
(insert (format "File %s: Required %s: %.3f sec\n"
load-file-name (ad-get-arg 0) delta))))
res))
(defadvice load (around spacemacs//timed-load activate)
(let ((start (current-time)) res delta)
(setq res ad-do-it
delta (float-time (time-since start)))
(when (> delta spacemacs-load-time-threshold)
(with-current-buffer "*load-times*"
(goto-char (point-max))
(insert (format "File %s: Loaded %s: %.3f sec\n"
load-file-name (ad-get-arg 0) delta))))
res)))
(provide 'core-debug)