def _ReadAndCacheCassLog(): with Cons.MT("Reading Cassandra log ..."): lines = [] found_reset = False lines1 = [] # WARN [main] 2016-09-20 02:20:39,250 MemSsTableAccessMon.java:115 - Mutant: ResetMon pattern = re.compile(r"WARN \[(main|MigrationStage:\d+)\]" \ " (?P<datetime>\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d,\d\d\d)" \ " MemSsTableAccessMon.java:\d+ -" \ " Mutant: (?P<event>ResetMon)") # Note: s0 only for now. dn = "%s/work/mutant/log/%s/s0/cassandra" % (os.path.expanduser("~"), Util0.JobId()) fn = "%s/system.log" % dn Cons.P("fn=%s" % fn) with open(fn) as fo: for line in fo.readlines(): line = line.strip() mo = pattern.match(line) if mo is not None: found_reset = True Conf.SetExpStartTime(Util0.ShortDateTime(mo.group("datetime"))) del lines[:] lines.append(line) # Keep reading zipped files like system.log.1.zip, until ResetMon is found i = 1 while found_reset == False: fn = "%s/system.log.%d.zip" % (dn, i) Cons.P("ResetMon not found. Reading more from file %s ..." % fn) with zipfile.ZipFile(fn, "r") as z: for fn1 in z.namelist(): #Cons.P(fn1) for line in z.read(fn1).split("\n"): line = line.strip() #Cons.P(line) mo = pattern.match(line) if mo is not None: found_reset = True Conf.SetExpStartTime(Util0.ShortDateTime(mo.group("datetime"))) del lines1[:] lines1.append(line) if len(lines1) != 0: lines1.extend(lines) lines = list(lines1) del lines1[:] i += 1 fn = "%s/work/mutant/misc/logs/cassandra/system-%s" \ % (os.path.expanduser("~"), Conf.ExpStartTime()) with open(fn, "w") as fo: for line in lines: fo.write("%s\n" % line) Cons.P("Created a Cassandra log file %s %d" % (fn, os.path.getsize(fn))) return lines