Display active threads that the app uses

8 Ansichten (letzte 30 Tage)
Harish Ananthakrishnan
Harish Ananthakrishnan am 20 Jun. 2024
Beantwortet: Dheeraj am 24 Jun. 2024
I have a simple MLApp UI and a function that it runs in a background pool. Is there a way in the profiler or some other method to monitor the number of threads that are created and and used as the app runs? In the below example I expect to see atleast two threads, one the UI thread and one BG thread.
I used the provided profiler and I do not see any information on threads/thread id/ tasks etc. I tried using the system task manager and I coudnt be sure that threads were created and destroyed.
Here is the basic MLApp code
function StartButtonPushed(app, event)
disp('Start button clicked');
app.callback = afterEach(app.q, @(data) myDisp(app, data));
app.future = parfeval(backgroundPool,@countUp,0,app.q);
disp('Start button cb complete');
end
and the method it runs in the background
function countUp(q)
%countUp Counts up 1 every second
for i = 1:5
disp(i);
pause(1);
send(q, i);
end
end

Antworten (1)

Dheeraj
Dheeraj am 24 Jun. 2024
Hi Harish Ananthakrishnan,
I understand you want to monitor the number of active threads used by your MATLAB App.
Unfortunately, In MATLAB, monitoring threads explicitly within the MATLAB environment is not possible as MATLAB itself manages the thread pools and low level thread management is not exposed.
Though you cannot directly monitor the threads created and used by MATLAB when you run your application you can use system-level tools for this purpose.
You can follow the below steps to get a rough estimation on the number of threads being used for an active process.
  • Close any active MATLAB sessions on your machine and execute this command to get a base line measure level of threads active in system.
ps -eLf | wc -l
  • Open a single copy of MATLAB and repeat the following command to get the measurement. The difference in the count between step 2 and step 1 is the number of active threads of a single MATLAB client.
ps -eLf | wc -l
  • Add the below line to the function of the MATLAB App to get the process ID.
feature('getpid')
  • In the system terminal execute the below command to know the number of MATLAB App UI thread count.
ps h -o nlwp $pid % with the process ID from previous step
  • Once parpool is open repeat the following command to get the measurement.
ps -eLf | wc –l
  • Add the below line to the parallel worker function.
feature('getpid')
  • Choosing one of the process IDs displayed by the parallel workers after executing the function run the following command to get a measurement. Perform this step for all the pool workers
ps h -o nlwp % with the process ID of worker from previous step
The output after executing the command in step 4 is the active thread count for MATLAB App and the combined sum of outputs after step 7 is the MATLAB worker thread count.
Thank You.

Kategorien

Mehr zu Install Products finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by