comparison strace_summarise.py @ 0:fee51ab07d09

blanket publication of all existing python files in lib/python on maritain
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 09 Mar 2020 14:58:04 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fee51ab07d09
1 #!/usr/bin/python
2 #----------------------------------------------------------------------
3 # Description : Simplify strace output to allow for easier diffing.
4 # Author : James Hunt <james.hunt@ubuntu.com>
5 # Date : 24 July 2012
6 #----------------------------------------------------------------------
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2, as
9 # published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #----------------------------------------------------------------------
20
21 import os
22 import re
23 import sys
24 import string
25
26 pids = {}
27
28 def process_data(fh):
29 lines = fh.readlines()
30 possible_pid = 0
31 using_pids = 0
32 pid = 0
33 pid_count = 1
34
35 line_num = 0
36 for line in lines:
37
38 line = line.strip()
39 line_num += 1
40 fields = line.split()
41 if line_num % 10000 == 0:
42 print >> sys.stderr,line_num,len(fields),fields[1]
43 if len(fields) > 0:
44 result = re.match("\(?(\d{4,8})\)?", fields[1])
45 #print >> sys.stderr,result.group(),result.group(1)
46 if result and result.group(1):
47 pid = result.group(1)
48 if pid in pids:
49 line = re.sub("(\\b"+pid+"\\b)", pids[pid], line)
50 else:
51 pid_name = "PID%d" % pid_count
52 line = re.sub("(\\b"+pid+"\\b)", pid_name, line)
53 pids[pid] = pid_name
54 pid_count += 1
55
56 # handle addresses (up to 64-bit)
57 line = re.sub("0x0{1,16}", "0xNULL", line)
58 line = re.sub("0x[0-9A-Fa-f]{1,16}", "0xADDR", line)
59
60 # handle timestamps
61 line = re.sub("\d{2}:\d{2}:\d{2}", "HH:MM:SS", line)
62 line = re.sub("\d{4}/\d{2}/\d{2}", "YYYY/MM/DD", line)
63
64 print line
65
66
67 def main():
68 try:
69 script = sys.argv[0]
70 file1 = sys.argv[1]
71 except:
72 sys.exit("ERROR: usage: %s <file1> " % script)
73
74 try:
75 fh1 = open(file1)
76 except:
77 sys.exit("ERROR: unable to open file '%s'" % file1)
78
79 process_data(fh1)
80 print >>sys.stderr,pids
81
82 if __name__ == "__main__":
83 main()