Skip to content
This repository
Browse code

Python script to analyze tags file size

  • Loading branch information...
commit f980d5d303a2d1009fc8cba87791b12938ac053f 1 parent 18ad44c
Peter Odding authored May 11, 2011

Showing 1 changed file with 39 additions and 0 deletions. Show diff stats Hide diff stats

  1. 39  why-so-slow.py
39  why-so-slow.py
... ...
@@ -0,0 +1,39 @@
  1
+#!/usr/bin/python
  2
+
  3
+'''
  4
+Determine which files are contributing the most to the size of a tags file. You
  5
+can specify the location of the tags file as a command line argument. If you
  6
+pass a numeric argument, no more than that many files will be reported.
  7
+
  8
+Author: Peter Odding <peter@peterodding.com>
  9
+Last Change: May 11, 2011
  10
+URL: https://github.com/xolox/vim-easytags/blob/master/why-so-slow.py
  11
+'''
  12
+
  13
+import os, sys
  14
+
  15
+tagsfile = '~/.vimtags'
  16
+topfiles = 10
  17
+
  18
+for arg in sys.argv[1:]:
  19
+  if os.path.isfile(arg):
  20
+    tagsfile = arg
  21
+  else:
  22
+    topfiles = int(arg)
  23
+
  24
+infile = open(os.path.expanduser(tagsfile))
  25
+counters = {}
  26
+
  27
+for line in infile:
  28
+  fields = line.split('\t')
  29
+  filename = fields[1]
  30
+  counters[filename] = counters.get(filename, 0) + len(line)
  31
+infile.close()
  32
+
  33
+sortedfiles = sorted([(s, n) for (n, s) in counters.iteritems()], reverse=True)
  34
+for filesize, filename in sortedfiles[:topfiles]:
  35
+  if filename.startswith(os.environ['HOME']):
  36
+    filename = filename.replace(os.environ['HOME'], '~')
  37
+  print '%i KB - %s' % (filesize / 1024, filename)
  38
+
  39
+# vim: ts=2 sw=2 et

0 notes on commit f980d5d

Please sign in to comment.
Something went wrong with that request. Please try again.