fix bogus links
[openafs-wiki.git] / debugging / threadLogParser.py
1 #!/usr/bin/python 
2
3 import sys,getopt
4
5 def usage():
6     print "Usage : --thread-file=filename --in-function=<function-name>, --exclude-function=<function-name>,<function-name>"
7     print "--in-function :  show only threads whose stack has functions of name <function-name> (or part thereof)"
8     print "--exclude-function :  do not show threads whose stack has functions of name <function-name> (or part thereof)"
9     print "---gdb-output-file : gdb output file to use"
10     sys.exit(2)
11
12 try:
13     opts, args = getopt.getopt(sys.argv[1:], "hg:i:e:", ["help", "gdb-output-file=","in-function=","exclude-function="])
14 except getopt.GetoptError, err:
15     # print help information and exit:
16     print str(err) # will print something like "option -a not recognized"
17     usage()
18     sys.exit(2)
19
20 gdb_ofile="gdb.out"
21 includes=""
22 excludes=[]
23
24 for o, a in opts:
25     if o in ("-h", "--help"):
26         usage()
27         sys.exit()
28     elif o in ("-g", "--gdb-output-file") :
29         gdb_ofile=a
30     elif o in ('-i', "--in-function") :
31         include=a
32     elif o in ('-e', "--exclude-function") :
33        excludes=a.split(",")
34     else :
35         print "Unknown option %s" % o
36         sys.exit(2)
37
38 Threads={}
39 f=file(gdb_ofile,"r")
40 skipnextLine=False
41 while 1: 
42     if not skipnextLine :
43         line=f.readline()   
44     else :
45         skipnextLine=False 
46     if not line: break
47     line=line.strip()
48     if len(line) == 0 : continue
49     if "to continue, or q" in line : continue
50     tokens=line.split()
51     if tokens[0] == "Thread" :
52         thisThread=[]
53         useThread=True
54         hasKeyword=False
55         while 1 :
56             line=f.readline()
57             if not line : break
58             if "to continue, or q" in line : continue
59             line=line.strip()
60             if len(line) == 0 : break
61             ttokens=line.split()
62             if ttokens[0] == "Thread" :  
63                 skipnextLine = True
64                 break
65             if line[0] != "#" :
66                 line += f.readline().strip()
67             thisThread.append(line)
68             for e in excludes :
69                 if e in line :
70                     useThread=False
71             if includes in line : 
72                 hasKeyword=True 
73         if useThread and hasKeyword :
74             Threads[tokens[1]]=thisThread
75                        
76 for t in Threads :
77     print "Thread %s" % t 
78     for line in  Threads[t] :
79        print line
80     print