From c07c7ac2d3d32af3ab181bd5812a8e9fd00f147e Mon Sep 17 00:00:00 2001 From: iipeace Date: Sun, 10 Nov 2024 22:17:19 +0900 Subject: [PATCH] printtrace: Fix UNTIL time condition bug Signed-off-by: iipeace --- guider/guider.py | 104 ++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/guider/guider.py b/guider/guider.py index 40b125dc..7f4d1c86 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "241109" +__revision__ = "241110" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -32,13 +32,13 @@ err = sys.exc_info()[1] sys.exit("[ERROR] failed to import essential package: %s" % err.args[0]) -# convert an unsupported type # +# handle backward compatibility between Python 2 and 3 try: long # pylint: disable=used-before-assignment except: long = int -# prevent MemoryError in python2 # +# python 2's xrange is equivalent to range in Python 3 try: xrange # pylint: disable=used-before-assignment except: @@ -26098,15 +26098,15 @@ def printTrace(console=False, targets=None, cb=None, parser=None): else: refilter = watchcond = None - # get times for tail and until option # + # get times for since and until option # current = SysMgr.getUptime() - since, until = SysMgr.getTimeValues(["TAIL", "UNTIL"], current) + since, until = SysMgr.getTimeValues(["SINCE", "UNTIL"], current) if since or until: checkTime = True - if since and since < 0: + if since < 0: since += current - if until and until < 0: - until += until + if until < 0: + until += current else: checkTime = False @@ -26191,11 +26191,8 @@ def printTrace(console=False, targets=None, cb=None, parser=None): else: since = 0 - if until: - if until < ltime: - continue - else: - break + if until and until <= ltime: + break if since == until == 0: checkTime = False @@ -27131,9 +27128,9 @@ def printJournal(console=False): else: refilter = watchcond = None - # get times for tail and until option # + # get times for since and until option # current = time.time() - since, until = SysMgr.getTimeValues(["TAIL", "UNTIL"], current) + since, until = SysMgr.getTimeValues(["SINCE", "UNTIL"], current) # apply relative time # if since < 0: @@ -27412,13 +27409,13 @@ def printKmsg(console=False): else: refilter = watchcond = None - # get times for tail and until option # + # get times for since and until option # current = SysMgr.getUptime() - tail, until = SysMgr.getTimeValues(["TAIL", "UNTIL"], current) + since, until = SysMgr.getTimeValues(["SINCE", "UNTIL"], current) # apply relative time # - if tail < 0: - tail += current + if since < 0: + since += current if until < 0: until += current @@ -27462,14 +27459,14 @@ def printKmsg(console=False): pass # check time condition # - if tail or until: + if since or until: try: if not line.startswith("["): raise Exception("no time") ltime = float(line[1:].split("]", 1)[0]) - if tail and ltime < tail: + if since and ltime < since: continue elif until and ltime >= until: SysMgr.printWarn( @@ -27547,10 +27544,10 @@ def printKmsg(console=False): ) # check time condition # - if tail or until: + if since or until: try: ltime = float(ltime) - if tail and ltime < tail: + if since and ltime < since: continue elif until and ltime >= until: SysMgr.printWarn( @@ -27595,7 +27592,7 @@ def printKmsg(console=False): ltime = UtilMgr.convColor(ltime, "GREEN") log = "[%s] (%s) %s" % (ltime, level, log) # skip special info # - elif tail or until: + elif since or until: continue # print message # @@ -34507,7 +34504,7 @@ def getHomePath(): return None @staticmethod - def getLogEvents(tail=0, until=0, sort="seconds"): + def getLogEvents(since=0, until=0, sort="seconds"): logEvents = [] # get print flag # @@ -34552,12 +34549,12 @@ def getLogEvents(tail=0, until=0, sort="seconds"): path = None # convert time # - if tail or until: + if since or until: diff = SysMgr.getUptime() - UtilMgr.getClockTime( dlt=True ) - if tail: - tail -= diff + if since: + since -= diff if until: until -= diff @@ -34574,11 +34571,11 @@ def getLogEvents(tail=0, until=0, sort="seconds"): inputParam.insert(1, "-I" + (path if path else "")) # set time condition # - if tail or until: + if since or until: inputParam.append( ( "-q" - + ("TAIL:%s," % tail if tail else "") + + ("SINCE:%s," % since if since else "") + ("UNTIL:%s," % until if until else "") ).rstrip(",") ) @@ -34705,7 +34702,7 @@ def initLogWatcher(data): # set env variables # envOpt = ( - "-qWATCHLOG:%s,TAIL,WATCHLOGCMD:GUIDER event %s%s%s" + "-qWATCHLOG:%s,SINCE,WATCHLOGCMD:GUIDER event %s%s%s" % (target, event, portOpt, exitCond) ) if name == "FILE": @@ -38622,8 +38619,8 @@ def printHelp(force=False, isExit=True): # {0:1} {1:1} -q DLTTIME - {3:1} all {2:1} and execute specific commands to save also their output when terminated - # {0:1} {1:1} -a -o -q PRINTCMD:"DLT#GUIDER printdlt -a -q LASTFILE\, TAIL:-3\, UNTIL -d L -Q", DLTTIME - # {0:1} {1:1} -a -o -q PRINTCMD:"KERNEL#GUIDER printkmsg -a -q TAIL:-3\, UNTIL -d L -Q" + # {0:1} {1:1} -a -o -q PRINTCMD:"DLT#GUIDER printdlt -a -q LASTFILE\, SINCE:-3\, UNTIL -d L -Q", DLTTIME + # {0:1} {1:1} -a -o -q PRINTCMD:"KERNEL#GUIDER printkmsg -a -q SINCE:-3\, UNTIL -d L -Q" # {0:1} {1:1} -a -o -q PRINTCMD:"ls#ls -lha" - {3:1} all {2:1} and quit when specific {2:1} are terminated @@ -40011,9 +40008,9 @@ def printHelp(force=False, isExit=True): # {0:1} {1:1} -Q - {2:1} generated since specific time in real-time - # {0:1} {1:1} -q TAIL - # {0:1} {1:1} -q TAIL:1235.123 - # {0:1} {1:1} -q TAIL:-3.0 + # {0:1} {1:1} -q SINCE + # {0:1} {1:1} -q SINCE:1235.123 + # {0:1} {1:1} -q SINCE:-3.0 - {2:1} generated until specific time in real-time # {0:1} {1:1} -q UNTIL -Q @@ -41427,8 +41424,8 @@ def _getDesc(s, t=0): # {0:1} {1:1} -j -q SAVEJSONSTAT - {2:1} {3:1} and execute specific commands to save also their output when terminated - # {0:1} {1:1} -a -o -q PRINTCMD:"DLT#GUIDER printdlt -a -q TAIL:-3\, UNTIL -d L -Q", DLTTIME - # {0:1} {1:1} -a -o -q PRINTCMD:"KERNEL#GUIDER printkmsg -a -q TAIL:-3\, UNTIL -d L -Q" + # {0:1} {1:1} -a -o -q PRINTCMD:"DLT#GUIDER printdlt -a -q SINCE:-3\, UNTIL -d L -Q", DLTTIME + # {0:1} {1:1} -a -o -q PRINTCMD:"KERNEL#GUIDER printkmsg -a -q SINCE:-3\, UNTIL -d L -Q" - {2:1} without threshold condition until CMD_RELOAD event is received # {0:1} {1:1} -q NOTHRESHOLD @@ -41749,8 +41746,8 @@ def _getDesc(s, t=0): # {0:1} {1:1} -g test - {2:1} generated since specific time - # {0:1} {1:1} -q TAIL - # {0:1} {1:1} -q TAIL:1235.123 + # {0:1} {1:1} -q SINCE + # {0:1} {1:1} -q SINCE:1235.123 - {2:1} generated until specific time # {0:1} {1:1} -q UNTIL @@ -41797,8 +41794,8 @@ def _getDesc(s, t=0): # {0:1} {1:1} -q RETRYCONN:1000 - {2:1} generated since specific time - # {0:1} {1:1} -q TAIL - # {0:1} {1:1} -q TAIL:1235.123 + # {0:1} {1:1} -q SINCE + # {0:1} {1:1} -q SINCE:1235.123 - {2:1} generated until specific time # {0:1} {1:1} -q UNTIL @@ -44104,13 +44101,13 @@ def _getDesc(s, t=0): # {0:1} {1:1} "./*.dlt" -q PRINTFILE, NRFILE:5 - Find trace files from specific time - # {0:1} {1:1} "./*.dlt" -q PRINTFILE, NRFILE:1, NRMSG:1, TAIL:123.123 -dL + # {0:1} {1:1} "./*.dlt" -q PRINTFILE, NRFILE:1, NRMSG:1, SINCE:123.123 -dL # {0:1} {1:1} "./**" -q PRINTFILE, NRMSG:1 -dL - # {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10 - # {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10, USEUPTIME - # {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:2024-04-11T01:30:00Z, UNTIL:2024-04-13T00:00:00Z - # {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10 -J - # {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10, SETCURRENT:1234.123 + # {0:1} {1:1} "./*.dlt" -q FINDFILE, SINCE:-2000, UNTIL:-10 + # {0:1} {1:1} "./*.dlt" -q FINDFILE, SINCE:-2000, UNTIL:-10, USEUPTIME + # {0:1} {1:1} "./*.dlt" -q FINDFILE, SINCE:2024-04-11T01:30:00Z, UNTIL:2024-04-13T00:00:00Z + # {0:1} {1:1} "./*.dlt" -q FINDFILE, SINCE:-2000, UNTIL:-10 -J + # {0:1} {1:1} "./*.dlt" -q FINDFILE, SINCE:-2000, UNTIL:-10, SETCURRENT:1234.123 - {2:1} from the last trace file # {0:1} {1:1} -q LASTFILE @@ -51053,7 +51050,7 @@ def stopHandler(signum=None, frame=None): ) for log in SysMgr.getLogEvents( - tail=SysMgr.startTime, until=SysMgr.getUptime() + since=SysMgr.startTime, until=SysMgr.getUptime() ): try: # get log time # @@ -75997,10 +75994,7 @@ def doSplit(): sys.exit(-1) # get direction # - if "TAIL" in SysMgr.environList: - which = "END" - else: - which = "START" + which = "END" if "TAIL" in SysMgr.environList else "START" # get chunk size # chunk = SysMgr.environList.get("CHUNK", [None])[0] @@ -90160,7 +90154,7 @@ def _popFields(struct, items): # save timestamp # SysMgr.updateUptime() - # get times for tail and until option # + # get times for since and until option # if "USEUPTIME" in SysMgr.environList: current = UtilMgr.getClockTime(dlt=True) currentDiff = current - SysMgr.getUptime() @@ -90169,7 +90163,7 @@ def _popFields(struct, items): current = time.time() currentDiff = current - time.time() useUptime = False - since, until = SysMgr.getTimeValues(["TAIL", "UNTIL"], current) + since, until = SysMgr.getTimeValues(["SINCE", "UNTIL"], current) # initialize dlt-daemon info # origShowAll = SysMgr.showAll