icub-tech-iit / ergocub-software

Main collector of ergoCub specific SW
https://icub-tech-iit.github.io/ergocub-software/
BSD 3-Clause "New" or "Revised" License
13 stars 18 forks source link

ergoCubEmotions uses more than 100% of the cpu on ergocub-head #213

Closed GiulioRomualdi closed 8 months ago

GiulioRomualdi commented 9 months ago

I noticed that ergoCubEmotions uses a really high amount of CPU on the ergocub-head.

In the following screenshot you can check the amount of used CPU (181%) only ergoCubEmotions was running on the ergocub-head image

I was wondering if it is normal

cc @martinaxgloria

traversaro commented 9 months ago

If I remember correctly once we checked that, one problem may be that at every module update, the file are re-read (see https://github.com/icub-tech-iit/ergocub-software/blob/eaacbf120b355edd931d2ae272e568b507740d2e/src/modules/ergoCubEmotions/ergoCubEmotions.cpp#L119). Perhaps we could read the images only once in the configure, and save them as cv::Mat attributes that can be used in the updateModule?

martinaxgloria commented 9 months ago

Hi @traversaro,

thank you for your suggestion. Actually, we are reading videos and not images (the static part is a 2 sec looped video and the transitions from one expression to another too). If I remember well, opencv shows videos one frame at the time after they are opened. I don't know if it's possible to save cv::VideoCapture elements as per cv::Mat ones.

Today I tried to use the configuration image -> transition -> image and I saw from jtop that the usage is reduced to ~30% but there's a spike when the transition is called.

Moreover, the % showed by jtop should correspond to the sum of the cpu usage for each core: in fact running top with IRIX mode set to OFF, this is the cpu consumption divided by the number of cores:

image

This means that the cores should not be saturated, I don't know if you see some delays. I'm going to understand if it's possible to prevent the videos from being reopened at each update

cc @Nicogene @GiulioRomualdi

martinaxgloria commented 9 months ago

Sorry, I closed it by mistake.

martinaxgloria commented 9 months ago

I opened a draft PR with the suggestions of @traversaro.

It's in draft since I have to test it on ergocub-head

cc @Nicogene @GiulioRomualdi

Nicogene commented 8 months ago

The @martinaxgloria fix improves significantly the performance, @GiulioRomualdi in case not sufficient feel free to reopen it.