Nuke arch-tags.
[emacs.git] / lisp / cedet / semantic / chart.el
blob9c9a8f3633f5e6895139ec9f08a9801c0d3bd955
1 ;;; semantic/chart.el --- Utilities for use with semantic tag tables
3 ;; Copyright (C) 1999, 2000, 2001, 2003, 2005, 2008, 2009, 2010, 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/>.
23 ;;; Commentary:
25 ;; A set of simple functions for charting details about a file based on
26 ;; the output of the semantic parser.
29 (require 'semantic)
30 (require 'chart)
31 (require 'semantic/db)
32 (require 'semantic/tag)
34 (eval-when-compile (require 'semantic/find))
36 ;;; Code:
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'."
44 (interactive)
45 (let* ((stream (semantic-something-to-tag-table
46 (or tagtable (current-buffer))))
47 (names (mapcar 'cdr semantic-symbol->name-assoc-list))
48 (nums (mapcar
49 (lambda (symname)
50 (length
51 (semantic-brute-find-tag-by-class (car symname)
52 stream)
54 semantic-symbol->name-assoc-list)))
55 (chart-bar-quickie 'vertical
56 "Semantic Toplevel Tag Volume"
57 names "Tag Class"
58 nums "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'."
66 (interactive)
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))
72 (names (mapcar 'car
73 (object-assoc-list
74 'file
75 dbt)))
76 (numnuts (mapcar (lambda (dba)
77 (prog1
78 (cons
79 (if (slot-boundp dba 'tags)
80 (length (oref dba tags))
82 (car names))
83 (setq names (cdr names))))
84 dbt))
85 (nums nil)
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)
91 (progn
92 (setcdr (nthcdr fh names) nil)
93 (setcdr (nthcdr fh nums) nil)))
94 (chart-bar-quickie 'horizontal
95 "Semantic DB Toplevel Tag Volume"
96 names "File"
97 nums "Volume")
100 (defun semantic-chart-token-complexity (tok)
101 "Calculate the `complexity' of token TOK."
102 (count-lines
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'."
113 (interactive)
114 (let* ((sym (if (not class) 'function))
115 (stream
116 (semantic-find-tags-by-class
117 sym (semantic-something-to-tag-table (or tagtable
118 (current-buffer)))
120 (name (cond ((semantic-tag-with-position-p (car stream))
121 (buffer-name (semantic-tag-buffer (car stream))))
122 (t "")))
123 (cplx (mapcar (lambda (tok)
124 (cons tok (semantic-chart-token-complexity tok)))
125 stream))
126 (namelabel (cdr (assoc 'function semantic-symbol->name-assoc-list)))
127 (names nil)
128 (nums nil))
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)))
132 names)
133 nums (cons (cdr (car cplx)) nums)
134 cplx (cdr cplx)))
135 ;; ;; (setq names (mapcar (lambda (str)
136 ;; ;; (substring str (- (length str) 10)))
137 ;; ;; names))
138 (chart-bar-quickie 'horizontal
139 (format "%s Complexity in %s"
140 (capitalize (symbol-name sym))
141 name)
142 names namelabel
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."
151 (interactive)
152 (require 'semantic/db-typecache)
153 (require 'semantic/scope)
154 (let* ((p (semanticdb-find-translate-path nil nil))
155 (plen (length p))
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")
167 "Overhead Entries"
168 (list plen tclen fslen lvarlen)
169 "Number of tags")
172 (provide 'semantic/chart)
174 ;;; semantic/chart.el ends here