Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:51

0001 #!/usr/bin/env python
0002 
0003 import os, re, datetime, argparse
0004 COLUMNS = os.environ.get("COLUMNS", 200)
0005 
0006 
0007 def dt_parse(s):
0008     try:
0009         t = datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S.%f")  
0010     except ValueError:
0011         t = None
0012     pass   
0013     return t 
0014 
0015 class Line(object):
0016     ptn = re.compile("\((?P<a>\d);(?P<n>\d+),(?P<d>\d+)\)\s*launch time\s*(\S*)\s*$")
0017 
0018     @classmethod
0019     def ParseTime(cls, txt):
0020         t = dt_parse(txt[:23])
0021         if t is None:
0022             print("unexpected time format [%s]" % txt)
0023             s = None
0024         else:
0025             s = t.timestamp()       # includes the sub-seconds, needs py3.3+
0026             #s = t.strftime("%s"))   # just seconds
0027         pass
0028         return t, s
0029 
0030 
0031     def __init__(self, txt):
0032 
0033         t, s = self.ParseTime(txt)
0034         self.t = t 
0035         self.s = s 
0036 
0037         typ = self.Type(txt)
0038         self.typ = typ
0039 
0040         self.desc = ""
0041         if typ == "launch":
0042             self.parse_launch_time(txt)
0043         else:
0044             pass
0045         pass
0046 
0047         self.txt = txt 
0048         self.c = txt[23:] 
0049         self.prev = None
0050 
0051     def parse_launch_time(self, txt):
0052         a,n,d,lt = self.ptn.findall(txt)[0]  
0053         a = int(a) 
0054         n = int(n) 
0055         fn = float(n)/1e6
0056         d = int(d) 
0057         lt = float(lt) 
0058         self.desc = "%6.2f/%6.2f " % ( fn, lt ) 
0059 
0060     dt = property(lambda self:self.s - self.prev.s if not (self.prev is None or self.s is None or self.prev.s is None) else 0.)
0061 
0062     @classmethod
0063     def Type(cls, l):
0064         if l.find("launch time") > -1:
0065             typ = "launch"
0066         elif l.find("[[") > -1:
0067             typ = "open"
0068         elif l.find("]]") > -1:
0069             typ = "close"
0070         else:
0071             typ = None
0072         pass 
0073         return typ
0074  
0075     @classmethod
0076     def Select(cls, l):
0077         return not cls.Type(l) is None
0078 
0079     @classmethod
0080     def ShowTime(cls, t):
0081         #tfmt = "%c %f
0082         tfmt = "%H:%M:%S"
0083         return t.strftime(tfmt) if not t is None else "-"*8 
0084 
0085     def __str__(self):
0086         fline = "%s : %10.4f : %10s : %20ss : %s " % ( self.ShowTime(self.t), self.dt, self.typ, self.desc, self.txt )
0087         return fline[:COLUMNS]
0088 
0089 
0090 class TDSLog(object):
0091     """
0092     2021-04-26 23:49:33.732 INFO  [128777] [OPropagator::launch@287] 0 : (0;50214628,1)  launch time 41.9189
0093     """
0094     def __init__(self, path="/tmp/$USER/opticks/tds/python2.7.log"):
0095         path = os.path.expandvars(path)
0096         lines = open(path,"r").read().splitlines()
0097         #lines = filter(Line.Select, lines)
0098         lines = list(map(Line, lines)) 
0099         for i in range(len(lines)):
0100             lines[i].prev = lines[i-1] if i > 0 else None
0101         pass
0102         self.lines = lines
0103         self.path = path 
0104 
0105     def __str__(self):
0106         return "\n".join(list(map(str,self.lines)) + [self.path])          
0107     
0108 
0109 if __name__ == '__main__':
0110     t = TDSLog()
0111     print(t)
0112     q = "OPropagator::launch@287"
0113 
0114 
0115