|
12 | 12 |
|
13 | 13 |
|
14 | 14 | def graphOfData(logf, dtstr): |
| 15 | + |
15 | 16 | lis = open(logf,'r').readlines() |
16 | 17 | dta = [li for li in lis if li[:8]==dtstr] |
17 | 18 |
|
@@ -55,78 +56,35 @@ def graphOfData(logf, dtstr): |
55 | 56 |
|
56 | 57 |
|
57 | 58 | def getLogStats(nightlogf, matchlogf, thisdy): |
58 | | - with open(nightlogf,'r') as inf: |
59 | | - loglines = inf.readlines() |
60 | | - |
61 | | - #logf = os.path.basename(nightlogf) |
62 | | - #spls = logf.split('-') |
63 | | - #thisdy= spls[1] |
64 | | - matchstr = 'RUNTIME' |
65 | | - |
66 | | - # <13>Nov 1 11:49:55 nightlyJob: RUNTIME 10554 showerReport ALL 202211 |
67 | | - startFAM = 0 |
68 | | - startRD = 0 |
69 | | - dts = [] |
70 | | - tss = [] |
71 | | - tsks = [] |
72 | | - secs = [] |
73 | | - msgs = [] |
74 | | - for li in loglines: |
75 | | - if matchstr in li: |
76 | | - li = ' '.join(li.split()) # remove double-spaces eg when date is ' 6 Jan' as opposed to '16 Jan' |
77 | | - spls = li.split() |
78 | | - msg = '' |
79 | | - for s in range(6, len(spls)): |
80 | | - msg = msg + ' ' + spls[s] |
81 | | - if 'start findAllMatches' in msg: |
82 | | - startFAM = int(spls[5]) |
83 | | - dts.append(thisdy) |
84 | | - tss.append(spls[2]) |
85 | | - tsks.append(spls[3].replace(':','')) |
86 | | - secs.append(int(spls[5])) |
87 | | - msgs.append(msg.strip()) |
88 | | - |
89 | | - with open(matchlogf,'r') as inf: |
90 | | - loglines = inf.readlines() |
| 59 | + # logline example |
| 60 | + # <13>May 8 06:10:02 nightlyJob: start nightlyJob |
| 61 | + outdir = os.path.split(nightlogf)[0] |
91 | 62 |
|
92 | | - # scan for findAllMatches data first |
93 | | - for li in loglines: |
94 | | - if matchstr in li: |
95 | | - spls = li.split() |
96 | | - if 'runDistrib' in spls[3]: |
97 | | - continue |
98 | | - msg = '' |
99 | | - for s in range(6, len(spls)): |
100 | | - msg = msg + ' ' + spls[s] |
101 | | - if 'start runDistrib' in msg: |
102 | | - startRD = int(spls[5]) |
103 | | - dts.append(thisdy) |
104 | | - tss.append(spls[2]) |
105 | | - tsks.append(spls[3].replace(':','')) |
106 | | - secs.append(int(spls[5])+startFAM) |
107 | | - msgs.append(msg.strip()) |
| 63 | + loglines = open(nightlogf,'r').readlines() |
| 64 | + bsfs = [x for x in loglines if 'start'in x or 'finish' in x or 'end' in x] |
| 65 | + bsfs = [x for x in bsfs if x[0]=='<'] |
108 | 66 |
|
109 | | - # rescan for runDistrib data |
110 | | - for li in loglines: |
111 | | - if matchstr in li: |
112 | | - spls = li.split() |
113 | | - if 'runDistrib' not in spls[3]: |
114 | | - continue |
115 | | - msg = '' |
116 | | - for s in range(6, len(spls)): |
117 | | - msg = msg + ' ' + spls[s] |
118 | | - dts.append(thisdy) |
119 | | - tss.append(spls[2]) |
120 | | - tsks.append(spls[3].replace(':','')) |
121 | | - secs.append(int(spls[5]) + startFAM + startRD) |
122 | | - msgs.append(msg.strip()) |
| 67 | + loglines = open(matchlogf,'r').readlines() |
| 68 | + msfs = [x for x in loglines if 'start'in x or 'finish' in x or 'end' in x] |
| 69 | + msfs = [x for x in msfs if x[0]=='<'] |
123 | 70 |
|
124 | | - df = pd.DataFrame(zip(dts,tss,secs,tsks,msgs), columns=['dts','tss','secs','tsk','msgs']) |
125 | | - df = df.sort_values(by=['tss']) |
126 | | - #print(df) |
127 | | - outdir = os.path.split(nightlogf)[0] |
128 | | - df.to_csv(os.path.join(outdir, 'perfNightly.csv'), mode='a', header=False, index=False) |
129 | | - |
| 71 | + alldata = msfs + bsfs |
| 72 | + alldata.sort() |
| 73 | + starttime = None |
| 74 | + yr = datetime.datetime.now().year |
| 75 | + with open(os.path.join(outdir, 'perfNightly1.csv'), 'a+') as outf: |
| 76 | + for rw in alldata: |
| 77 | + dtpart = rw[4:19] |
| 78 | + evtdt = datetime.datetime.strptime(f'{yr} {dtpart}', '%Y %b %d %H:%M:%S') |
| 79 | + if 'start nightlyJob' in rw: |
| 80 | + starttime = evtdt |
| 81 | + elapsed_secs = (evtdt - starttime).seconds |
| 82 | + txtpart = rw[20:] |
| 83 | + task = txtpart[:txtpart.find(':')] |
| 84 | + msg = txtpart[txtpart.find(':')+1:].replace(',', ' ') |
| 85 | + outstr = f'{evtdt.strftime("%Y%m%d,%H:%M:%S")},{elapsed_secs},{task},{msg}\n' |
| 86 | + outf.write(outstr) |
| 87 | + |
130 | 88 |
|
131 | 89 | if __name__ == '__main__': |
132 | 90 | dtstr = sys.argv[1] |
|
0 commit comments