フィルターのクリア

How can I profile the memory usage in MATLAB when I use Linux and Mac OS?

66 ビュー (過去 30 日間)
hao
hao 2014 年 8 月 21 日
コメント済み: Runcong Kuang 2022 年 9 月 1 日
How can I profile the memory usage in MATLAB when I use Linux and Mac OS?
the memory function is only available to Windows, right?

回答 (2 件)

Zander Labuschagne
Zander Labuschagne 2019 年 10 月 31 日
編集済み: Zander Labuschagne 2019 年 10 月 31 日
Hello,
I know it's a bit late, but I just used the following on Linux:
[tmp pid] = system('pgrep MATLAB');
[tmp mem_usage] = system(['cat /proc/' strtrim(pid) '/status | grep VmSize']);
fprintf("%i MB\n", round(str2num(strtrim(extractAfter(extractBefore(mem_usage, ' kB'), ':'))) / 1000));
The system command executes a shell command where I first get the process ID and used the ID to get the memory usage using cat to read the process status file, then I format it and output it in MB. You can probably retrieve the PID inside the same bash command then you call the system function only once.
  3 件のコメント
Runcong Kuang
Runcong Kuang 2022 年 9 月 1 日
Hi, is this code a bash command?
I create the .sh file with these lines of code and run it in the terminal while I am running matlab in the linux.
But this gives me the syntax error "near unexpected token '('
Runcong Kuang
Runcong Kuang 2022 年 9 月 1 日
I make it into a .m file and run 'matlab -batch [thisfile] while I am running main matlab file.
I also try adding these lines in my main running matlab file.
Both of these methods only return " MB".

サインインしてコメントする。


Carlos Rondon
Carlos Rondon 2021 年 11 月 22 日
I'm using a MAC with Catalina OS. Normally I use this command:
profile -memory on
you can view the results after your code executes using
profview

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by