• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Calculate average memory usage of each instance using vba

alex gomes

New Member
I want to calculate average memory usage by each instance using vba.
Suppose i want to calculate average memory used by each instance of chrome.
Please go through the attachment .
And i want to copy the data in excel sheet named "Average_Memory"
 

Attachments

  • AvaerageMemory_usage_by_each instance.png
    AvaerageMemory_usage_by_each instance.png
    49.9 KB · Views: 13
Thanks For the reply!!
But it is not calculating the average memory being used by each processor.

Plz provide me vba code ,As i am new to vba
Thanks!
 
Alex

What you highlighted had nothing to do with individual processors, it highlighted several instances of Chrome Running and the memory usage. They may all be on one or two processors

This is all way beyond my skill level

I'd go and look/ask at some Microsoft VBA Forums or http://stackoverflow.com/
 
Task Manager doesn't show an average, so how do you plan to track the average per process?
 
That's fairly simple with WMI:

Code:
Sub ListChromeMemory()
    ListMemoryUsage "chrome", Range("A1")
End Sub
Sub ListMemoryUsage(strProcess As String, rgOut As Range)
    Dim objWMI As Object
    Dim colObjects As Object
    Dim item As Object
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set colObjects = objWMI.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process Where Name Like '" & strProcess & "%'")
  
    For Each item In colObjects
        rgOut.Resize(1, 2).Value2 = Array(item.Name, Format$(item.WorkingSetPrivate / 1024, "#,##0 K"))
        Set rgOut = rgOut.offset(1)
    Next
End Sub
 
Debaser

Does that need any References added to VBA as it doesn't work for me ?
 
It is working fine..I want to count no of process also,so that I can average it,,,and copy the data in specific sheet called "Memory"
And i want the memory usage in MB
 
Debaser

Does that need any References added to VBA as it doesn't work for me ?

No, no references required. I assume you have chrome running? (;)) Have you debugged?

Are you getting an error, wrong output, or no output?
 
It is working fine..I want to count no of process also,so that I can average it,,,and copy the data in specific sheet called "Memory"
And i want the memory usage in MB

I think the word you're looking for is "please". ;)

For MB you just change this:
Code:
Format$(item.WorkingSetPrivate / 1024, "#,##0 K")
to this:
Code:
Format$(item.WorkingSetPrivate / 1024 / 1024, "#,##0 MB")

You can supply any output range on any sheet you want in the calling routine. I'm pretty sure you can manage that change.
 
Thanks for your reply!!!
Please provide the code for How I can get the total process no of "chrome"
After that we can Add all the memory usage by all "chrome" process and divide it by total count
 
Yes.The average

Then alter the second routine to:
Code:
Sub ListMemoryUsage(strProcess As String, rgOut As Range)
    Dim objWMI As Object
    Dim colObjects As Object
    Dim item As Object
    Dim lCounter As Long
    Dim dMemUsage As Double
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set colObjects = objWMI.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process Where Name Like '" & strProcess & "%'")
   
    For Each item In colObjects
        dMemUsage = dMemUsage + item.WorkingSetPrivate
        lCounter = lCounter + 1
    Next
    If lCounter > 0 Then rgOut.Resize(1, 2).Value2 = Array(strProcess, Format$((dMemUsage / lCounter) / 1024 / 1024, "#,##0 MB"))
End Sub
 
Is that all you actually want as the output - the average across all the processes?
yes
Then alter the second routine to:
Code:
Sub ListMemoryUsage(strProcess As String, rgOut As Range)
    Dim objWMI As Object
    Dim colObjects As Object
    Dim item As Object
    Dim lCounter As Long
    Dim dMemUsage As Double
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set colObjects = objWMI.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process Where Name Like '" & strProcess & "%'")
  
    For Each item In colObjects
        dMemUsage = dMemUsage + item.WorkingSetPrivate
        lCounter = lCounter + 1
    Next
    If lCounter > 0 Then rgOut.Resize(1, 2).Value2 = Array(strProcess, Format$((dMemUsage / lCounter) / 1024 / 1024, "#,##0 MB"))
End Sub


If i put the processor name as "Agilent.Sa.Vsa.Vector.Exe" ..It is not working
Please help
 
Thanks for the reply..it is working fine for "chrome"
I want it to work for "Agilent.Sa.Vsa.Vector"
Please look into it.I am very new to vba
 
Back
Top