From bedda0c5b670c363d4df0bce4dd14a80d2da44c9 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Tue, 6 Aug 2019 10:22:40 +0200 Subject: [PATCH] [ui] simplify loading of statistics file * NodeLog: remove intermediate property for Loader * StatViewer * keep only one function to load source file * only send request only after the previous one fully completed * update deltaTime before initializing charts * reset "sourceModified" property when source changes --- meshroom/ui/qml/GraphEditor/NodeLog.qml | 8 +-- meshroom/ui/qml/GraphEditor/StatViewer.qml | 59 ++++++++++------------ 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/meshroom/ui/qml/GraphEditor/NodeLog.qml b/meshroom/ui/qml/GraphEditor/NodeLog.qml index 8254a08b..3d5923e6 100644 --- a/meshroom/ui/qml/GraphEditor/NodeLog.qml +++ b/meshroom/ui/qml/GraphEditor/NodeLog.qml @@ -93,11 +93,6 @@ FocusScope { if(!chunksLV.count || chunksLV.currentChunk) logComponentLoader.source = Filepath.stringToUrl(currentFile); - if(currentItem.fileProperty === "statisticsFile") { - logComponentLoader.componentNb = 1 - } else { - logComponentLoader.componentNb = 0 - } } TabButton { @@ -123,9 +118,8 @@ FocusScope { clip: true Layout.fillWidth: true Layout.fillHeight: true - property int componentNb: 0 property url source - sourceComponent: componentNb === 0 ? textFileViewerComponent : statViewerComponent + sourceComponent: fileSelector.currentItem.fileProperty === "statisticsFile" ? statViewerComponent : textFileViewerComponent } Component { diff --git a/meshroom/ui/qml/GraphEditor/StatViewer.qml b/meshroom/ui/qml/GraphEditor/StatViewer.qml index 5db15c92..5cc1a09b 100644 --- a/meshroom/ui/qml/GraphEditor/StatViewer.qml +++ b/meshroom/ui/qml/GraphEditor/StatViewer.qml @@ -15,7 +15,7 @@ Item { property var sourceModified: undefined property var jsonObject property int nbReads: 1 - property var deltaTime: 1 + property real deltaTime: 1 property var cpuLineSeries: [] property int nbCores: 0 @@ -64,47 +64,47 @@ Item { "#BF360C" ] - onSourceChanged: function() { + onSourceChanged: { + sourceModified = undefined; resetCharts() readSourceFile() } Timer { - interval: root.deltaTime * 60000; running: true; repeat: true - onTriggered: function() { - var xhr = new XMLHttpRequest; - xhr.open("GET", source); + id: reloadTimer + interval: root.deltaTime * 60000; running: true; repeat: false + onTriggered: readSourceFile() - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE) { - - if(sourceModified === undefined || sourceModified < xhr.getResponseHeader('Last-Modified')) { - var jsonString = xhr.responseText; - - jsonObject= JSON.parse(jsonString); - root.jsonObject = jsonObject; - resetCharts() - sourceModified = xhr.getResponseHeader('Last-Modified') - root.createCharts() - } - } - }; - xhr.send(); - } } function readSourceFile() { + if(!Filepath.urlToString(source).endsWith("statistics")) + return; + var xhr = new XMLHttpRequest; xhr.open("GET", source); xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE) { - var jsonString = xhr.responseText; + if (xhr.readyState === XMLHttpRequest.DONE && xhr.status == 200) { - jsonObject= JSON.parse(jsonString); - root.jsonObject = jsonObject; + if(sourceModified === undefined || sourceModified < xhr.getResponseHeader('Last-Modified')) { + var jsonObject; - root.createCharts() + try { + jsonObject = JSON.parse(xhr.responseText); + } + catch(exc) + { + console.warning("Failed to parse statistics file: " + source) + root.jsonObject = {}; + return; + } + root.jsonObject = jsonObject; + resetCharts(); + sourceModified = xhr.getResponseHeader('Last-Modified') + root.createCharts(); + reloadTimer.restart(); + } } }; xhr.send(); @@ -119,16 +119,13 @@ Item { } function createCharts() { + root.deltaTime = jsonObject.interval / 60.0; initCpuChart() initRamChart() initGpuChart() - - root.deltaTime = jsonObject.interval /60 } - - /************************** *** CPU *** **************************/