How to get correct user and sys times of programs called by system()?

1 view (last 30 days)
Hello,
I have a Matlab compiled code that contains calls to an external executable using the system() function. It works fine, but somehow, when I want to monitor the time the Matlab code took with the time command in Unix, the "user" and "sys" times taken by the executable are not taken into account. In my case, I need to have the correct user and sys times to know the overall efficiency of CPU usage of my code, especially since the external executable I'm using takes more than half of the overall time.
I have managed to reproduce that issue with Matlab in command line (no compiled code) and with an other external program such as zip to compress a random big file :
time matlab -nodisplay -nodesktop -r "system('time zip big_file.zip big_file','-echo');exit"
It produces the following outputs :
real 0m31.901s
user 0m6.874s
sys 0m6.753s
real 0m43.194s
user 0m6.421s
sys 0m0.670s
The first time output is the one of the zip from inside the system function() and the second one is over the whole Matlab execution. The user and sys times of the zip command are not included in the overall stats (it should be something like user = 13.295s and sys = 7.423s in the two last lines).
Is there a way to fix this? Or is there an other way to execute external commands in Matlab that would show the correct time results? Note : I have tried ! and unix() without success.
Thanks in advance

Answers (1)

Iñigo Escanciano
Iñigo Escanciano on 1 Jul 2021
Is there any reason you can´t use tic, toc or cputime commands to measure the time?
It may be easier to take that parameter and pass it to the program as the matlab time. It is hard to imagine as I can´t figure how your program is structured.
As what I see, it is more about your user and sys times beeing reset for each call so, would it be just about adding the past time to the new?

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!