4

Is it possible to measure when QGIS starts and stops loading/rendering a layer?

I used something similar in OpenLayers before (loadstart and loadend event, http://dev.openlayers.org/examples/layerLoadMonitoring.html ) but haven't figured out yet how to do that in QGIS with pyQGIS.

I want to use it in order to measure which layers take long to load (geometry and attributes!).

I know that there is something that can be used outside of QGIS to benchmark loading times ( https://github.com/DMS-Aus/qgis2img ) but

a: the loading times of layers in QGIS were way longer than the values measured by the tool. I guess that tool doesn't read the attributes.

and

b: I would like to measure the loading times inside QGIS

I think that that there has to be something that already listenes to something like a loadstart and loadend signal as in the statusbar there is an indicator that is shown until the layer is loaded completely:

enter image description here

  • Have you seen Settings > Options > Rendering > Debugging > Map canvas refresh? It measures the canvas refresh time which could also be an indirect method to measuring layer rendering. – Joseph Jun 13 '18 at 13:02
  • @Joseph: but this does not give me the ability to check the loading time for each layer seperately, does it? – markgraeflerland Jun 13 '18 at 13:13
  • Maybe if you have such a small project with small-size files, the timing might be close otherwise nope :). Perhaps you can set a timer for the QgsMapLayerRenderer class. – Joseph Jun 13 '18 at 13:22
  • I'm not sure why would you need this, but in QGIS the speed of your layer's load would depend on the speed of your hard drive, so measuring the speed of load is pretty much a measure of your hard-drive speed and not how long the QGIS takes to process it. I have noticed it when I moved all the content from Network Drive to a local SSD, and now all the layers that had noticeable load times (2-5 seconds+) started loading in <0.1 second. – Ruslan Jun 13 '18 at 22:02
  • @Joseph: The QGIS-projects for which i want to find the bottlenegs have between 100 and 150 layers each – markgraeflerland Jun 14 '18 at 5:14
5
+100

Go to settings > options > rendering, enable debug map canvas refresh, have a look at the message log. Done.

enter image description here

enter image description here

  • But this gives me very 'fragmented' measurings. Following Screenshot shows a part of the log from when I opened a project. The same layer occurs nearly 20 times with different partial loading times of the overall loading time: i.stack.imgur.com/SgVTR.png . Havin projects with more than 100 layers I think this way I couldn't figure out the bottleneg. Is there any chance to measure the total loading times for each layer with pyqgis or if not would this be hard to implement? – markgraeflerland Jun 18 '18 at 5:34
  • 1
    The times are a complex construct anyway, local caches may deliver results on subsequent loads, do incremental rendering of tiles (e.g. WMTS, YXZ), network load, cpu availability, disk access, indexes, ... have a strong influence. You might be able to trigger your own rendering job and watch for signals for individual layers. But I think it's easier to just parse these lines, which are written based on renderingTime. – Matthias Kuhn Jun 18 '18 at 13:41
3

What about this:

def start_signal(): print "started: {0}".format(datetime.datetime.now())
def stop_signal():  print "finished: {0}".format(datetime.datetime.now())

iface.mapCanvas().renderStarting.connect(start_signal)
iface.mapCanvas().renderComplete.connect(stop_signal)

layer = QgsRasterLayer('A:\Temp\dop_test.tif', 'test_layer')
QgsMapLayerRegistry.instance().addMapLayer(layer)

<qgis._core.QgsRasterLayer object at 0x0000000023B49950>
started: 2018-06-15 10:37:44.438000
finished: 2018-06-15 10:37:44.553000

Unfortunately its less like a monitor - because, its necessary to load the layers via Python. Its not working if you are loading a project, because there is no information about the "current layer" in the connected signals.

  • Good to know how to measure single layers but I need to check the loading times for whole projects and for different Zoomlevels/extents – markgraeflerland Jun 15 '18 at 12:45
  • Actually it also works for a project if you add the signal&slot connection into the python console. And it also works for zoomlevels. – aleho Jun 15 '18 at 12:59
  • but it measures the total rendering time for all layers. So it doesn't determine which layer takes longest to load – markgraeflerland Jun 16 '18 at 4:29
  • No, you would need to add every layer into a python script for that. Then it would print after every layer. – aleho Jun 18 '18 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.