0

I'm trying to log the memory usage of browsers for exemple for Chrome / Firefox etc.

For Firefox I can simply use this little command line:

tasklist /fo csv /fi "imagename eq firefox.exe" > DumpResults.csv

And this will nicely result with one proces and its usage. But when applying this train of thoughts to Chrome you'll get around 4 processes even when you did a clean launch of Chrome. Is there any way to sum the results?

Sorry for the stupid question but it's my first attempt to create a bat file.

2 Answers 2

3

An alternative…

@Echo Off
Set "sum=0"
For /F "Tokens=6-7 Delims=., " %%a In (
    'TaskList /NH /FI "ImageName Eq chrome.exe"') Do Set/A sum+=%%a%%b
Set sum
Pause

…prevents using two loops

Sign up to request clarification or add additional context in comments.

1 Comment

Clean solution :) Thank you!
1
@echo off
set sum=0
for /f "tokens=5 delims=," %%x in ('tasklist /fo csv /nh /fi "imagename eq chrome.exe"') do (
  for /f "tokens=1-4 delims=.K " %%a in (%%x) do set /a sum+=%%a%%b%%c%%d
)
echo Sum Chrome = %sum%

Maybe you have to adapt the delimiters to your local settings. Output on my computer is like:

C:\Users> tasklist /fo csv /nh /fi "imagename eq chrome.exe"
"chrome.exe","7744","Console","1","86.388 K"
"chrome.exe","7784","Console","1","1.312 K"
"chrome.exe","7920","Console","1","50.188 K"
...

4 Comments

I've got the same output but the script returns || The system cannot find the file 92. || Sum Chrome = 0 || The cannot find happens around 6 times so that's as many as chrome processes there are running atm but can't find a way to put this in code... sorry
just copy-pasted my code from above to a fresh batfile. Works fine for me. Did you change anything? Try ... %%a in ("%%~x") ...
That fixed it for me altho I don't really understand it, thanks alot! I'm gonna try to learn bit by bit what you gave me! :)
Removed my question, I just had to put in "," in the echo between the values I wanted to seperate, sorry for bothering you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.