Merge pull request #1764 from alicevision/dev/displayComputeTime

[ui] Display computation time for "running" or "finished" nodes
This commit is contained in:
Fabien Castan 2022-09-10 00:27:34 +02:00 committed by GitHub
commit ee20136f82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 0 deletions

View file

@ -387,6 +387,9 @@ class NodeChunk(BaseObject):
def isFinishedOrRunning(self): def isFinishedOrRunning(self):
return self._status.status in (Status.SUCCESS, Status.RUNNING) return self._status.status in (Status.SUCCESS, Status.RUNNING)
def isRunning(self):
return self._status.status == Status.RUNNING
def isStopped(self): def isStopped(self):
return self._status.status == Status.STOPPED return self._status.status == Status.STOPPED
@ -444,6 +447,8 @@ class NodeChunk(BaseObject):
nodeName = Property(str, lambda self: self.node.name, constant=True) 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)
elapsedTime = Property(float, lambda self: self._status.elapsedTime, notify=statusChanged)
# simple structure for storing node position # simple structure for storing node position
Position = namedtuple("Position", ["x", "y"]) Position = namedtuple("Position", ["x", "y"])
@ -732,6 +737,17 @@ class BaseNode(BaseObject):
return False return False
return True return True
@Slot(result=bool)
def isSubmittedOrRunning(self):
""" Return True if all chunks are at least submitted and there is one running chunk, False otherwise. """
if not self.isAlreadySubmittedOrFinished():
return False
for chunk in self._chunks:
if chunk.isRunning():
return True
return False
@Slot(result=bool)
def isFinishedOrRunning(self): def isFinishedOrRunning(self):
""" Return True if all chunks of this Node is either finished or running, False otherwise. """ """ Return True if all chunks of this Node is either finished or running, False otherwise. """
return all(chunk.isFinishedOrRunning() for chunk in self._chunks) return all(chunk.isFinishedOrRunning() for chunk in self._chunks)

View file

@ -24,6 +24,96 @@ Panel {
icon: MaterialLabel { text: MaterialIcons.tune } icon: MaterialLabel { text: MaterialIcons.tune }
headerBar: RowLayout { headerBar: RowLayout {
Label {
text: {
if (node !== null && node.isSubmittedOrRunning()) {
// Some chunks might be submitted but they'll all run eventually
if (node.elapsedTime > 0) { // At least a chunk is done running
return "Running for: " + getTimeStr(node.elapsedTime)
} else {
return (node.chunks.count > 1) ? "First chunk running" : "Node running"
}
} else if (node !== null && node.isFinishedOrRunning()) {
/* Either all chunks finished running or the last one is running
* Placed inside an "else if" instead of "else" to avoid entering the functions
* when there is no real use */
return getTimeStr(node.elapsedTime)
} else {
return ""
}
}
padding: 2
font.italic: true
visible: {
if (node !== null) {
if ((node.isFinishedOrRunning() || node.isSubmittedOrRunning())) {
return true
}
}
return false
}
ToolTip.text: {
if (node !== null && (node.isFinishedOrRunning() || (node.isSubmittedOrRunning() && node.elapsedTime > 0))) {
var longestChunkTime = getLongestChunkTime(node.chunks)
if (longestChunkTime > 0)
return "Longest chunk: " + getTimeStr(longestChunkTime) + " (" + node.chunks.count + " chunks)"
else
return ""
} else {
return ""
}
}
ToolTip.visible: ToolTip.text ? runningTimeMa.containsMouse : false
MouseArea {
id: runningTimeMa
anchors.fill: parent
hoverEnabled: true
}
function getTimeStr(elapsed)
{
if (elapsed <= 0)
return ""
var hours = 0
var min = 0
var finalTime = ""
if (elapsed > 3600) {
hours = Math.floor(elapsed / 3600)
elapsed = elapsed - (hours * 3600)
finalTime += hours + "h"
}
if (elapsed > 60) {
min = Math.floor(elapsed / 60)
elapsed = elapsed - (min * 60)
finalTime += min + "m"
}
if (hours == 0 && min == 0) {
// Millisecond precision for execution times below 1 min
finalTime += Number(elapsed.toLocaleString(Qt.locale('en-US'))) + "s"
} else {
finalTime += Math.round(elapsed) + "s"
}
return finalTime
}
function getLongestChunkTime(chunks)
{
if (chunks.count <= 1)
return 0
var longestChunkTime = 0
for (var i = 0; i < chunks.count; i++) {
var elapsedTime = chunks.at(i).elapsedTime
longestChunkTime = elapsedTime > longestChunkTime ? elapsedTime : longestChunkTime
}
return longestChunkTime
}
}
MaterialToolButton { MaterialToolButton {
text: MaterialIcons.more_vert text: MaterialIcons.more_vert
font.pointSize: 11 font.pointSize: 11