root/cherokee/trunk/contrib/tracelor.py

Revision 1594, 1.4 kB (checked in by alo, 5 months ago)

--

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 ##
4 ## Cherokee trace colorizer
5 ##
6 ## If cherokee is compiled with the --enable-trace parameter, it can
7 ## be traced by using the CHEROKEE_TRACE environment variable or
8 ## cherokee-tweak.
9 ##
10 ## Copyright: Alvaro Lopez Ortega <alvaro@alobbs.com>
11 ## Licensed: GPL v2
12 ##
13
14 import sys
15
16 RESET_COLOR = "\033[0m"
17 HIGHLIGHT   = "\033[1;31;40m"
18
19 _threads = {}
20 _colors  = []
21 _color_n =  0
22
23 def build_colors():
24     global _colors
25     for a in range(40,48):
26         for b in range(30,38):
27             if a-10 == b:
28                 continue
29             color = '\033[0;%d;%dm' % (a,b)
30             _colors.append(color)
31    
32 def thread_color (thread):
33     global _threads
34     global _color_n
35     if not thread in _threads.keys():
36         color = _colors[_color_n]
37         _threads[thread] = color
38         _color_n += 1
39     return _threads[thread]
40
41 def main():
42     build_colors()
43
44     while True:
45         line = sys.stdin.readline()
46         if len(line) < 1:
47             break
48
49         # Thread
50         thread = None
51         if line[0] == '{':       
52             end = line.find('}')
53             if end > 0:
54                 thread = line[1:end]
55                 color  = thread_color (thread)
56                 line = '%s%s%s %s' % (color, thread, RESET_COLOR, line[end+2:])
57
58         # Words
59         for w in sys.argv:
60             line = line.replace(w, HIGHLIGHT + w + RESET_COLOR)
61
62         # Nothing else to do..
63         print line,
64
65 if __name__ == '__main__':
66     main()
Note: See TracBrowser for help on using the browser.