1 ;;; semantic/chart.el --- Utilities for use with semantic tag tables
3 ;; Copyright (C) 1999-2001, 2003, 2005, 2008-2017 Free Software
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; A set of simple functions for charting details about a file based on
26 ;; the output of the semantic parser.
30 (require 'semantic
/db
)
31 (require 'semantic
/find
)
35 (defun semantic-chart-tags-by-class (&optional tagtable
)
36 "Create a bar chart representing the number of tags for a given tag class.
37 Each bar represents how many toplevel tags in TAGTABLE
38 exist with a given class. See `semantic-symbol->name-assoc-list'
39 for tokens which will be charted.
40 TAGTABLE is passed to `semantic-something-to-tag-table'."
42 (let* ((stream (semantic-something-to-tag-table
43 (or tagtable
(current-buffer))))
44 (names (mapcar 'cdr semantic-symbol-
>name-assoc-list
))
48 (semantic-brute-find-tag-by-class (car symname
)
51 semantic-symbol-
>name-assoc-list
)))
52 (chart-bar-quickie 'vertical
53 "Semantic Toplevel Tag Volume"
58 (defun semantic-chart-database-size (&optional tagtable
)
59 "Create a bar chart representing the size of each file in semanticdb.
60 Each bar represents how many toplevel tags in TAGTABLE
61 exist in each database entry.
62 TAGTABLE is passed to `semantic-something-to-tag-table'."
64 (unless (and (fboundp 'semanticdb-minor-mode-p
)
65 (semanticdb-minor-mode-p))
66 (error "Semanticdb is not enabled"))
67 (let* ((db semanticdb-current-database
)
68 (dbt (semanticdb-get-database-tables db
))
73 (numnuts (mapcar (lambda (dba)
76 (if (slot-boundp dba
'tags
)
77 (length (oref dba tags
))
80 (setq names
(cdr names
))))
83 (fh (/ (- (frame-height) 7) 4)))
84 (setq numnuts
(sort numnuts
(lambda (a b
) (> (car a
) (car b
)))))
85 (setq names
(mapcar 'cdr numnuts
)
86 nums
(mapcar 'car numnuts
))
87 (if (> (length names
) fh
)
89 (setcdr (nthcdr fh names
) nil
)
90 (setcdr (nthcdr fh nums
) nil
)))
91 (chart-bar-quickie 'horizontal
92 "Semantic DB Toplevel Tag Volume"
97 (defun semantic-chart-token-complexity (tok)
98 "Calculate the `complexity' of token TOK."
100 (semantic-tag-end tok
)
101 (semantic-tag-start tok
)))
103 (defun semantic-chart-tag-complexity
104 (&optional class tagtable
)
105 "Create a bar chart representing the complexity of some tags.
106 Complexity is calculated for tags of CLASS. Each bar represents
107 the complexity of some tag in TAGTABLE. Only the most complex
108 items are charted. TAGTABLE is passed to
109 `semantic-something-to-tag-table'."
111 (let* ((sym (if (not class
) 'function
))
113 (semantic-find-tags-by-class
114 sym
(semantic-something-to-tag-table (or tagtable
117 (name (cond ((semantic-tag-with-position-p (car stream
))
118 (buffer-name (semantic-tag-buffer (car stream
))))
120 (cplx (mapcar (lambda (tok)
121 (cons tok
(semantic-chart-token-complexity tok
)))
123 (namelabel (cdr (assoc 'function semantic-symbol-
>name-assoc-list
)))
126 (setq cplx
(sort cplx
(lambda (a b
) (> (cdr a
) (cdr b
)))))
127 (while (and cplx
(<= (length names
) (/ (- (frame-height) 7) 4)))
128 (setq names
(cons (semantic-tag-name (car (car cplx
)))
130 nums
(cons (cdr (car cplx
)) nums
)
132 ;; ;; (setq names (mapcar (lambda (str)
133 ;; ;; (substring str (- (length str) 10)))
135 (chart-bar-quickie 'horizontal
136 (format "%s Complexity in %s"
137 (capitalize (symbol-name sym
))
140 nums
"Complexity (Lines of code)")
143 (declare-function semanticdb-get-typecache
"semantic/db-typecache")
144 (declare-function semantic-calculate-scope
"semantic/scope")
146 (defun semantic-chart-analyzer ()
147 "Chart the extent of the context analysis."
149 (require 'semantic
/db-typecache
)
150 (require 'semantic
/scope
)
151 (let* ((p (semanticdb-find-translate-path nil nil
))
153 (tab semanticdb-current-table
)
154 (tc (semanticdb-get-typecache tab
))
155 (tclen (+ (length (oref tc filestream
))
156 (length (oref tc includestream
))))
157 (scope (semantic-calculate-scope))
158 (fslen (length (oref scope fullscope
)))
159 (lvarlen (length (oref scope localvar
)))
161 (chart-bar-quickie 'vertical
162 (format "Analyzer Overhead in %s" (buffer-name))
163 '("includes" "typecache" "scopelen" "localvar")
165 (list plen tclen fslen lvarlen
)
169 (provide 'semantic
/chart
)
171 ;;; semantic/chart.el ends here