Created
June 10, 2014 12:21
-
-
Save jorgenschaefer/84bc04d947e83b2b9a01 to your computer and use it in GitHub Desktop.
Trivial elisp code to create a basic dot file call graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Save to foo.dot, run dot -Tpng foo.dot -o foo.png, done | |
(defun eldot () | |
(interactive) | |
(let ((nodes (make-hash-table :test #'eq)) | |
(expr nil)) | |
(catch 'done | |
(save-excursion | |
(goto-char (point-min)) | |
(while t | |
(condition-case err | |
(setq expr (read (current-buffer))) | |
(error (throw 'done t))) | |
(when (and (consp expr) | |
(symbolp (car expr)) | |
(string-match "^\\(defun\\|define-minor-mode\\)" | |
(symbol-name (car expr))) | |
(symbolp (cadr expr))) | |
(let ((calls (make-hash-table :test #'eq))) | |
(puthash (cadr expr) calls nodes) | |
(eldot-add-callsites calls (cddr expr))))))) | |
(with-current-buffer (get-buffer-create "*Dot*") | |
(erase-buffer) | |
(insert "graph eldot {\n") | |
(maphash (lambda (function calls) | |
(maphash (lambda (call _) | |
(when (gethash call nodes) | |
(insert (format " \"%s\" -- \"%s\";\n" | |
function call)))) | |
calls)) | |
nodes) | |
(insert "\n}\n") | |
(display-buffer (current-buffer))))) | |
(defun eldot-add-callsites (calls body) | |
(while (consp body) | |
(let ((expr (car body))) | |
(when (and (consp expr) | |
(symbolp (car expr))) | |
(puthash (car expr) t calls)) | |
(when (consp expr) | |
(eldot-add-callsites calls expr))) | |
(setq body (cdr body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment