mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-15 15:55:18 +02:00
[processGraph] statistics in a separate file (no more inside status file)
This commit is contained in:
parent
3f001d46d8
commit
b7d906adb7
1 changed files with 32 additions and 5 deletions
|
@ -160,17 +160,15 @@ class StatusData:
|
||||||
self.status = Status.NONE
|
self.status = Status.NONE
|
||||||
self.nodeName = nodeName
|
self.nodeName = nodeName
|
||||||
self.nodeType = nodeType
|
self.nodeType = nodeType
|
||||||
self.statistics = Statistics()
|
|
||||||
self.graph = ''
|
self.graph = ''
|
||||||
|
|
||||||
def toDict(self):
|
def toDict(self):
|
||||||
return {k: (v.toDict() if getattr(v, "toDict", None) else v) for k, v in self.__dict__.items()}
|
return self.__dict__
|
||||||
|
|
||||||
def fromDict(self, d):
|
def fromDict(self, d):
|
||||||
self.status = Status._member_map_[d['status']]
|
self.status = Status._member_map_[d['status']]
|
||||||
self.nodeName = d['nodeName']
|
self.nodeName = d['nodeName']
|
||||||
self.nodeType = d['nodeType']
|
self.nodeType = d['nodeType']
|
||||||
self.statistics.fromDict(d['statistics'])
|
|
||||||
self.graph = d['graph']
|
self.graph = d['graph']
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,7 +180,7 @@ class StatisticsThread(threading.Thread):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.node = node
|
self.node = node
|
||||||
self.running = True
|
self.running = True
|
||||||
self.statistics = self.node.status.statistics
|
self.statistics = self.node.statistics
|
||||||
self.initStats()
|
self.initStats()
|
||||||
|
|
||||||
def initStats(self):
|
def initStats(self):
|
||||||
|
@ -205,7 +203,7 @@ class StatisticsThread(threading.Thread):
|
||||||
self.statistics.ramUsage.append(psutil.virtual_memory().percent)
|
self.statistics.ramUsage.append(psutil.virtual_memory().percent)
|
||||||
self.statistics.swapUsage.append(psutil.swap_memory().percent)
|
self.statistics.swapUsage.append(psutil.swap_memory().percent)
|
||||||
self.statistics.vramUsage.append(0)
|
self.statistics.vramUsage.append(0)
|
||||||
self.node.saveStatusFile()
|
self.node.saveStatistics()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
|
@ -228,6 +226,7 @@ class Node:
|
||||||
for k, v in kwargs.items():
|
for k, v in kwargs.items():
|
||||||
self.attributes[k]._value = v
|
self.attributes[k]._value = v
|
||||||
self.status = StatusData(self.name, self.nodeType())
|
self.status = StatusData(self.name, self.nodeType())
|
||||||
|
self.statistics = Statistics()
|
||||||
|
|
||||||
def __getattr__(self, k):
|
def __getattr__(self, k):
|
||||||
try:
|
try:
|
||||||
|
@ -320,6 +319,9 @@ class Node:
|
||||||
def statusFile(self):
|
def statusFile(self):
|
||||||
return os.path.join(pg.cacheFolder, self.internalFolder(), 'status')
|
return os.path.join(pg.cacheFolder, self.internalFolder(), 'status')
|
||||||
|
|
||||||
|
def statisticsFile(self):
|
||||||
|
return os.path.join(pg.cacheFolder, self.internalFolder(), 'statistics')
|
||||||
|
|
||||||
def logFile(self):
|
def logFile(self):
|
||||||
return os.path.join(pg.cacheFolder, self.internalFolder(), 'log')
|
return os.path.join(pg.cacheFolder, self.internalFolder(), 'log')
|
||||||
|
|
||||||
|
@ -349,6 +351,27 @@ class Node:
|
||||||
json.dump(data, jsonFile, indent=4)
|
json.dump(data, jsonFile, indent=4)
|
||||||
shutil.move(statusFilepathWriting, statusFilepath)
|
shutil.move(statusFilepathWriting, statusFilepath)
|
||||||
|
|
||||||
|
def updateStatisticsFromCache(self):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
statisticsFile = self.statisticsFile()
|
||||||
|
if not os.path.exists(statisticsFile):
|
||||||
|
return
|
||||||
|
with open(statisticsFile, 'r') as jsonFile:
|
||||||
|
statisticsData = json.load(jsonFile)
|
||||||
|
self.statistics.fromDict(statisticsData)
|
||||||
|
|
||||||
|
def saveStatistics(self):
|
||||||
|
data = self.statistics.toDict()
|
||||||
|
statisticsFilepath = self.statisticsFile()
|
||||||
|
folder = os.path.dirname(statisticsFilepath)
|
||||||
|
if not os.path.exists(folder):
|
||||||
|
os.makedirs(folder)
|
||||||
|
statisticsFilepathWriting = statisticsFilepath + '.writing.' + str(uuid.uuid4())
|
||||||
|
with open(statisticsFilepathWriting, 'w') as jsonFile:
|
||||||
|
json.dump(data, jsonFile, indent=4)
|
||||||
|
shutil.move(statisticsFilepathWriting, statisticsFilepath)
|
||||||
|
|
||||||
def upgradeStatusTo(self, newStatus):
|
def upgradeStatusTo(self, newStatus):
|
||||||
if int(newStatus.value) <= int(self.status.status.value):
|
if int(newStatus.value) <= int(self.status.status.value):
|
||||||
print('WARNING: downgrade status on node "{}" from {} to {}'.format(self.name, self.status.status.name,
|
print('WARNING: downgrade status on node "{}" from {} to {}'.format(self.name, self.status.status.name,
|
||||||
|
@ -591,6 +614,10 @@ class Graph:
|
||||||
for node in self.nodes.values():
|
for node in self.nodes.values():
|
||||||
node.updateStatusFromCache()
|
node.updateStatusFromCache()
|
||||||
|
|
||||||
|
def updateStatisticsFromCache(self):
|
||||||
|
for node in self.nodes.values():
|
||||||
|
node.updateStatisticsFromCache()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.updateInternals()
|
self.updateInternals()
|
||||||
self.updateStatusFromCache()
|
self.updateStatusFromCache()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue