1 ;;; semantic/chart.el --- Utilities for use with semantic tag tables
3 ;; Copyright (C) 1999-2001, 2003, 2005, 2008-2011
4 ;; Free Software Foundation, Inc.
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.
31 (require 'semantic
/db
)
32 (require 'semantic
/tag
)
34 (eval-when-compile (require 'semantic
/find
))
38 (defun semantic-chart-tags-by-class (&optional tagtable
)
39 "Create a bar chart representing the number of tags for a given tag class.
40 Each bar represents how many toplevel tags in TAGTABLE
41 exist with a given class. See `semantic-symbol->name-assoc-list'
42 for tokens which will be charted.
43 TAGTABLE is passed to `semantic-something-to-tag-table'."
45 (let* ((stream (semantic-something-to-tag-table
46 (or tagtable
(current-buffer))))
47 (names (mapcar 'cdr semantic-symbol-
>name-assoc-list
))
51 (semantic-brute-find-tag-by-class (car symname
)
54 semantic-symbol-
>name-assoc-list
)))
55 (chart-bar-quickie 'vertical
56 "Semantic Toplevel Tag Volume"
61 (defun semantic-chart-database-size (&optional tagtable
)
62 "Create a bar chart representing the size of each file in semanticdb.
63 Each bar represents how many toplevel tags in TAGTABLE
64 exist in each database entry.
65 TAGTABLE is passed to `semantic-something-to-tag-table'."
67 (unless (and (fboundp 'semanticdb-minor-mode-p
)
68 (semanticdb-minor-mode-p))
69 (error "Semanticdb is not enabled"))
70 (let* ((db semanticdb-current-database
)
71 (dbt (semanticdb-get-database-tables db
))
76 (numnuts (mapcar (lambda (dba)
79 (if (slot-boundp dba
'tags
)
80 (length (oref dba tags
))
83 (setq names
(cdr names
))))
86 (fh (/ (- (frame-height) 7) 4)))
87 (setq numnuts
(sort numnuts
(lambda (a b
) (> (car a
) (car b
)))))
88 (setq names
(mapcar 'cdr numnuts
)
89 nums
(mapcar 'car numnuts
))
90 (if (> (length names
) fh
)
92 (setcdr (nthcdr fh names
) nil
)
93 (setcdr (nthcdr fh nums
) nil
)))
94 (chart-bar-quickie 'horizontal
95 "Semantic DB Toplevel Tag Volume"
100 (defun semantic-chart-token-complexity (tok)
101 "Calculate the `complexity' of token TOK."
103 (semantic-tag-end tok
)
104 (semantic-tag-start tok
)))
106 (defun semantic-chart-tag-complexity
107 (&optional class tagtable
)
108 "Create a bar chart representing the complexity of some tags.
109 Complexity is calculated for tags of CLASS. Each bar represents
110 the complexity of some tag in TAGTABLE. Only the most complex
111 items are charted. TAGTABLE is passed to
112 `semantic-something-to-tag-table'."
114 (let* ((sym (if (not class
) 'function
))
116 (semantic-find-tags-by-class
117 sym
(semantic-something-to-tag-table (or tagtable
120 (name (cond ((semantic-tag-with-position-p (car stream
))
121 (buffer-name (semantic-tag-buffer (car stream
))))
123 (cplx (mapcar (lambda (tok)
124 (cons tok
(semantic-chart-token-complexity tok
)))
126 (namelabel (cdr (assoc 'function semantic-symbol-
>name-assoc-list
)))
129 (setq cplx
(sort cplx
(lambda (a b
) (> (cdr a
) (cdr b
)))))
130 (while (and cplx
(<= (length names
) (/ (- (frame-height) 7) 4)))
131 (setq names
(cons (semantic-tag-name (car (car cplx
)))
133 nums
(cons (cdr (car cplx
)) nums
)
135 ;; ;; (setq names (mapcar (lambda (str)
136 ;; ;; (substring str (- (length str) 10)))
138 (chart-bar-quickie 'horizontal
139 (format "%s Complexity in %s"
140 (capitalize (symbol-name sym
))
143 nums
"Complexity (Lines of code)")
146 (declare-function semanticdb-get-typecache
"semantic/db-typecache")
147 (declare-function semantic-calculate-scope
"semantic/scope")
149 (defun semantic-chart-analyzer ()
150 "Chart the extent of the context analysis."
152 (require 'semantic
/db-typecache
)
153 (require 'semantic
/scope
)
154 (let* ((p (semanticdb-find-translate-path nil nil
))
156 (tab semanticdb-current-table
)
157 (tc (semanticdb-get-typecache tab
))
158 (tclen (+ (length (oref tc filestream
))
159 (length (oref tc includestream
))))
160 (scope (semantic-calculate-scope))
161 (fslen (length (oref scope fullscope
)))
162 (lvarlen (length (oref scope localvar
)))
164 (chart-bar-quickie 'vertical
165 (format "Analyzer Overhead in %s" (buffer-name))
166 '("includes" "typecache" "scopelen" "localvar")
168 (list plen tclen fslen lvarlen
)
172 (provide 'semantic
/chart
)
174 ;;; semantic/chart.el ends here