Skip to content

Commit

Permalink
[ui] NodeEditor: refactor ChunksList and add global stats
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiencastan committed Jan 22, 2021
1 parent bd5d447 commit 0ef9931
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 312 deletions.
94 changes: 63 additions & 31 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class ExecMode(Enum):
EXTERN = 2


class StatusData:
class StatusData(BaseObject):
"""
"""
dateTimeFormatting = '%Y-%m-%d %H:%M:%S.%f'

def __init__(self, nodeName, nodeType, packageName, packageVersion):
def __init__(self, nodeName='', nodeType='', packageName='', packageVersion=''):
self.status = Status.NONE
self.execMode = ExecMode.NONE
self.nodeName = nodeName
Expand All @@ -79,6 +79,11 @@ def __init__(self, nodeName, nodeType, packageName, packageVersion):
self.hostname = ""
self.sessionUid = meshroom.core.sessionUid

def merge(self, other):
self.startDateTime = min(self.startDateTime, other.startDateTime)
self.endDateTime = max(self.endDateTime, other.endDateTime)
self.elapsedTime += other.elapsedTime

def reset(self):
self.status = Status.NONE
self.execMode = ExecMode.NONE
Expand Down Expand Up @@ -112,8 +117,12 @@ def toDict(self):
return d

def fromDict(self, d):
self.status = getattr(Status, d.get('status', ''), Status.NONE)
self.execMode = getattr(ExecMode, d.get('execMode', ''), ExecMode.NONE)
self.status = d.get('status', Status.NONE)
if not isinstance(self.status, Status):
self.status = Status[self.status]
self.execMode = d.get('execMode', ExecMode.NONE)
if not isinstance(self.execMode, ExecMode):
self.execMode = ExecMode[self.execMode]
self.nodeName = d.get('nodeName', '')
self.nodeType = d.get('nodeType', '')
self.packageName = d.get('packageName', '')
Expand Down Expand Up @@ -236,7 +245,7 @@ def __init__(self, node, range, parent=None):
self.node = node
self.range = range
self.logManager = LogManager(self)
self.status = StatusData(node.name, node.nodeType, node.packageName, node.packageVersion)
self._status = StatusData(node.name, node.nodeType, node.packageName, node.packageVersion)
self.statistics = stats.Statistics()
self.statusFileLastModTime = -1
self._subprocess = None
Expand All @@ -258,32 +267,32 @@ def name(self):

@property
def statusName(self):
return self.status.status.name
return self._status.status.name

@property
def logger(self):
return self.logManager.logger

@property
def execModeName(self):
return self.status.execMode.name
return self._status.execMode.name

def updateStatusFromCache(self):
"""
Update node status based on status file content/existence.
"""
statusFile = self.statusFile
oldStatus = self.status.status
oldStatus = self._status.status
# No status file => reset status to Status.None
if not os.path.exists(statusFile):
self.statusFileLastModTime = -1
self.status.reset()
self._status.reset()
else:
with open(statusFile, 'r') as jsonFile:
statusData = json.load(jsonFile)
self.status.fromDict(statusData)
self._status.fromDict(statusData)
self.statusFileLastModTime = os.path.getmtime(statusFile)
if oldStatus != self.status.status:
if oldStatus != self._status.status:
self.statusChanged.emit()

@property
Expand Down Expand Up @@ -311,7 +320,7 @@ def saveStatusFile(self):
"""
Write node status on disk.
"""
data = self.status.toDict()
data = self._status.toDict()
statusFilepath = self.statusFile
folder = os.path.dirname(statusFilepath)
if not os.path.exists(folder):
Expand All @@ -322,16 +331,16 @@ def saveStatusFile(self):
renameWritingToFinalPath(statusFilepathWriting, statusFilepath)

def upgradeStatusTo(self, newStatus, execMode=None):
if newStatus.value <= self.status.status.value:
print('WARNING: downgrade status on node "{}" from {} to {}'.format(self.name, self.status.status,
newStatus))
if newStatus.value <= self._status.status.value:
logging.warning('Downgrade status on node "{}" from {} to {}'.format(self.name, self._status.status,
newStatus))

if newStatus == Status.SUBMITTED:
self.status = StatusData(self.node.name, self.node.nodeType, self.node.packageName, self.node.packageVersion)
self._status = StatusData(self.node.name, self.node.nodeType, self.node.packageName, self.node.packageVersion)
if execMode is not None:
self.status.execMode = execMode
self._status.execMode = execMode
self.execModeNameChanged.emit()
self.status.status = newStatus
self._status.status = newStatus
self.saveStatusFile()
self.statusChanged.emit()

Expand Down Expand Up @@ -360,41 +369,41 @@ def saveStatistics(self):
renameWritingToFinalPath(statisticsFilepathWriting, statisticsFilepath)

def isAlreadySubmitted(self):
return self.status.status in (Status.SUBMITTED, Status.RUNNING)
return self._status.status in (Status.SUBMITTED, Status.RUNNING)

def isAlreadySubmittedOrFinished(self):
return self.status.status in (Status.SUBMITTED, Status.RUNNING, Status.SUCCESS)
return self._status.status in (Status.SUBMITTED, Status.RUNNING, Status.SUCCESS)

def isFinishedOrRunning(self):
return self.status.status in (Status.SUCCESS, Status.RUNNING)
return self._status.status in (Status.SUCCESS, Status.RUNNING)

def isStopped(self):
return self.status.status == Status.STOPPED
return self._status.status == Status.STOPPED

def process(self, forceCompute=False):
if not forceCompute and self.status.status == Status.SUCCESS:
print("Node chunk already computed:", self.name)
if not forceCompute and self._status.status == Status.SUCCESS:
logging.info("Node chunk already computed: {}".format(self.name))
return
global runningProcesses
runningProcesses[self.name] = self
self.status.initStartCompute()
self._status.initStartCompute()
startTime = time.time()
self.upgradeStatusTo(Status.RUNNING)
self.statThread = stats.StatisticsThread(self)
self.statThread.start()
try:
self.node.nodeDesc.processChunk(self)
except Exception as e:
if self.status.status != Status.STOPPED:
if self._status.status != Status.STOPPED:
self.upgradeStatusTo(Status.ERROR)
raise
except (KeyboardInterrupt, SystemError, GeneratorExit) as e:
self.upgradeStatusTo(Status.STOPPED)
raise
finally:
self.status.initEndCompute()
self.status.elapsedTime = time.time() - startTime
print(' - elapsed time:', self.status.elapsedTimeStr)
self._status.initEndCompute()
self._status.elapsedTime = time.time() - startTime
logging.info(' - elapsed time: {}'.format(self._status.elapsedTimeStr))
# ask and wait for the stats thread to stop
self.statThread.stopRequest()
self.statThread.join()
Expand All @@ -408,9 +417,10 @@ def stopProcess(self):
self.node.nodeDesc.stopProcess(self)

def isExtern(self):
return self.status.execMode == ExecMode.EXTERN
return self._status.execMode == ExecMode.EXTERN

statusChanged = Signal()
status = Property(Variant, lambda self: self._status, notify=statusChanged)
statusName = Property(str, statusName.fget, notify=statusChanged)
execModeNameChanged = Signal()
execModeName = Property(str, execModeName.fget, notify=execModeNameChanged)
Expand All @@ -422,7 +432,7 @@ def isExtern(self):
statisticsFile = Property(str, statisticsFile.fget, notify=nodeFolderChanged)

nodeName = Property(str, lambda self: self.node.name, constant=True)
statusNodeName = Property(str, lambda self: self.status.nodeName, constant=True)
statusNodeName = Property(str, lambda self: self._status.nodeName, constant=True)


# simple structure for storing node position
Expand Down Expand Up @@ -837,6 +847,24 @@ def getGlobalStatus(self):

return Status.NONE

@Slot(result=StatusData)
def getFusedStatus(self):
fusedStatus = StatusData()
if self._chunks:
fusedStatus.fromDict(self._chunks[0].status.toDict())
for chunk in self._chunks[1:]:
fusedStatus.merge(chunk.status)
fusedStatus.status = self.getGlobalStatus()
return fusedStatus

@Slot(result=StatusData)
def getRecursiveFusedStatus(self):
fusedStatus = self.getFusedStatus()
nodes = self.getInputNodes(recursive=True, dependenciesOnly=True)
for node in nodes:
fusedStatus.merge(node.fusedStatus)
return fusedStatus

@property
def globalExecMode(self):
return self._chunks.at(0).execModeName
Expand Down Expand Up @@ -1000,6 +1028,10 @@ def canBeCanceled(self):
size = Property(int, getSize, notify=sizeChanged)
globalStatusChanged = Signal()
globalStatus = Property(str, lambda self: self.getGlobalStatus().name, notify=globalStatusChanged)
fusedStatus = Property(StatusData, getFusedStatus, notify=globalStatusChanged)
elapsedTime = Property(float, lambda self: self.getFusedStatus().elapsedTime, notify=globalStatusChanged)
recursiveElapsedTime = Property(float, lambda self: self.getRecursiveFusedStatus().elapsedTime, notify=globalStatusChanged)

globalExecModeChanged = Signal()
globalExecMode = Property(str, globalExecMode.fget, notify=globalExecModeChanged)
isComputed = Property(bool, _isComputed, notify=globalStatusChanged)
Expand Down
52 changes: 52 additions & 0 deletions meshroom/ui/qml/Controls/KeyValue.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import MaterialIcons 2.2

/**
* KeyValue allows to create a list of key/value, like a table.
*/
Rectangle {
property alias key: keyLabel.text
property alias value: valueText.text

color: activePalette.window

width: parent.width
height: childrenRect.height

RowLayout {
width: parent.width
Rectangle {
anchors.margins: 2
color: Qt.darker(activePalette.window, 1.1)
// Layout.preferredWidth: sizeHandle.x
Layout.minimumWidth: 10.0 * Qt.application.font.pixelSize
Layout.maximumWidth: 15.0 * Qt.application.font.pixelSize
Layout.fillWidth: false
Layout.fillHeight: true
Label {
id: keyLabel
text: "test"
anchors.fill: parent
anchors.top: parent.top
topPadding: 4
leftPadding: 6
verticalAlignment: TextEdit.AlignTop
elide: Text.ElideRight
}
}
TextArea {
id: valueText
text: ""
anchors.margins: 2
Layout.fillWidth: true
wrapMode: Label.WrapAtWordBoundaryOrAnywhere
textFormat: TextEdit.PlainText

readOnly: true
selectByMouse: true
background: Rectangle { anchors.fill: parent; color: Qt.darker(activePalette.window, 1.05) }
}
}
}
1 change: 1 addition & 0 deletions meshroom/ui/qml/Controls/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Controls
ColorChart 1.0 ColorChart.qml
FloatingPane 1.0 FloatingPane.qml
Group 1.0 Group.qml
KeyValue 1.0 KeyValue.qml
MessageDialog 1.0 MessageDialog.qml
Panel 1.0 Panel.qml
SearchBar 1.0 SearchBar.qml
Expand Down
Loading

0 comments on commit 0ef9931

Please sign in to comment.