Search code examples
linuxperformancematlabmulticore

report memory and cpu usage - matlab - on multicore linux server


we would need to know how much memory and cpu time a matlab process had used with all of it's spawned threads. If I understand it correctly, all the threads will pop up as new processes with new process-ids but the CMD name will remain the same.

so I thought about creating a demon which append the usage in every n sec:

ps -o %cpu,%mem,cmd -C MATLAB | grep "[0-9]+" >> matlab_log

and later counting and summing up the ratios multiplied by the demon tick time.

I wonder if there is an easier way, or I missing something, or simply just exist some tool more handy for this job?

Cheers


Solution

  • If you install the BSD Process Accounting utilities (package acct on Debian and Ubuntu) you can use the sa(8) utility to summarize executions or give you semi-detailed execution logs:

    $ lastcomm
    ...
    man               F  X sarnold  pts/3      0.00 secs Fri May  4 16:21
    man               F  X sarnold  pts/3      0.00 secs Fri May  4 16:21
    vim                    sarnold  pts/3      0.05 secs Fri May  4 16:20
    sa                     sarnold  pts/3      0.00 secs Fri May  4 16:20
    sa                     sarnold  pts/3      0.00 secs Fri May  4 16:20
    bzr                    sarnold  pts/3      0.99 secs Fri May  4 16:19
    apt-get          S     root     pts/1      0.44 secs Fri May  4 16:18
    dpkg                   root     pts/1      0.00 secs Fri May  4 16:19
    dpkg                   root     pts/1      0.00 secs Fri May  4 16:19
    dpkg                   root     pts/1      0.00 secs Fri May  4 16:19
    apt-get           F    root     pts/1      0.00 secs Fri May  4 16:19
    ...
    
    $ sa
         633      15.22re       0.09cp         0avio      6576k
          24       8.51re       0.03cp         0avio      6531k   ***other*
           2       0.31re       0.02cp         0avio     10347k   apt-get
           3       0.02re       0.02cp         0avio      9667k   python2.7
          18       0.04re       0.01cp         0avio      5444k   dpkg
           2       0.01re       0.01cp         0avio     13659k   debsums
    ...
    

    The format of the acct file is documented in acct(5), so you could write your own programs to parse the files if none of the standard tools lets you express the queries you want.

    Probably the largest downside to the BSD process accounting utilities is that the kernel will only update the process accounting log when processes exit, because many of the summary numbers are only available once another process wait(2)s for it -- so currently running processes are completely overlooked by the utilities.

    These utilities may be sufficient though; these utilities is how compute centers billed their clients, back when compute centers were popular...