Skip to content

Commit

Permalink
Add time logging for AllskyTeam#2715
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-developer committed May 30, 2023
1 parent 5aa7d76 commit f0054b2
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions scripts/flow-runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import importlib
from datetime import datetime, timedelta, date
import signal
from collections import deque
import numpy
import shutil

'''
NOTE: `valid_module_paths` must be an array, and the order specified dictates the order of search for a named module.
It is expected that the 'user' supplied modules are searched first, and thus come before the distributed modules path.
This permits the user to copy and modify a distributed module, or create an entirely new replacement for a distributed
module, thus giving the user total control.
'''

def signalHandler(sig, frame):
if sig == signal.SIGTERM or sig == signal.SIGINT:
try:
Expand Down Expand Up @@ -124,17 +126,18 @@ def signalHandler(sig, frame):
shared.log(0, "ERROR: no allsky config directory available in the environment", exitCode=1)

watchdog = False
moduleDebug = False
timeout = 0
try:
configFile = os.path.join(shared.args.allskyConfig, 'module-settings.json')
with open(configFile, 'r') as module_Settings_file:
module_settings = json.load(module_Settings_file)
watchdog = module_settings['watchdog']
timeout = module_settings['timeout']
moduleDebug = module_settings['debugmode']
except:
watchdog = False



shared.args.config = rawSettings
shared.log(4, "INFO: Loading config {0}".format(shared.args.config))
try:
Expand Down Expand Up @@ -180,6 +183,8 @@ def signalHandler(sig, frame):
os.remove(disableFile)

results = {}
if moduleDebug:
flowStartTime = datetime.now()
for shared.step in shared.flow:
if shared.flow[shared.step]["enabled"] and shared.flow[shared.step]["module"] not in globals():
try:
Expand Down Expand Up @@ -254,3 +259,38 @@ def signalHandler(sig, frame):
json.dump(config, updatefile, indent=4)
except json.JSONDecodeError as err:
shared.log(0, "ERROR: Error parsing {0} {1}".format(moduleConfig, err), exitCode=1)

if moduleDebug:
flowEndTime = datetime.now()
flowElapsedTime = (((flowEndTime - flowStartTime).total_seconds()) * 1000) / 1000
queueData = []
allQueueData = {}
if shared.dbHasKey("flowtimer"):
allQueueData = shared.dbGet("flowtimer")
if flowName in allQueueData:
queueData = allQueueData[flowName]

queue = deque(queueData, maxlen = 10)
queue.append(flowElapsedTime)

queueData = list(queue)
allQueueData[flowName] = queueData
shared.dbUpdate("flowtimer", allQueueData)

flowTimingsFolder = os.path.join(shared.allskyTmp,"flowtimings")
shared.checkAndCreateDirectory(flowTimingsFolder)
flowTimeFile = os.path.join(flowTimingsFolder,f"{flowName}-average")
if len(list(queue)) == 10:
average = str(round(numpy.average(list(queue)),1))
with open(flowTimeFile, 'w') as f:
f.write(average)
else:
if shared.isFileWriteable(flowTimeFile):
os.remove(flowTimeFile)
else:
flowTimingsFolder = os.path.join(shared.allskyTmp,"flowtimings")
if shared.dbHasKey("flowtimer"):
shared.dbDeleteKey("flowtimer")

if os.path.exists(flowTimingsFolder):
shutil.rmtree(flowTimingsFolder)

0 comments on commit f0054b2

Please sign in to comment.