Search This Blog

Monday, January 24, 2011

How to Find out which java thread takes the maximum cpu time in windows

On Error Resume Next
Const adVarChar = 200
Const MaxCharacters = 255
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ProcessID", adVarChar, MaxCharacters
DataList.Fields.Append "ThreadID", adVarChar, MaxCharacters
DataList.Fields.Append "PercentUserTime", adVarChar, MaxCharacters
DataList.Fields.Append "PercentProcessorTime", adVarChar, MaxCharacters
DataList.Open
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Thread where IDProcess ="&WScript.Arguments.Item(0),,48)
For Each objItem in colItems
DataList.AddNew
DataList("ProcessID") = objItem.IDProcess
DataList("ThreadID") = objItem.IDThread
DataList("PercentUserTime") = objItem.PercentUserTime
DataList("PercentProcessorTime") = objItem.PercentProcessorTime
DataList.Update
Next
DataList.Sort = "PercentUserTime"
DataList.Reverse()
DataList.Reverse()
DataList.MoveFirst
Do Until DataList.EOF
Wscript.Echo DataList.Fields.Item("ProcessID") _
& vbTab & DataList.Fields.Item("ThreadID")_
& vbTab & Hex(DataList.Fields.Item("ThreadID"))_
& vbTab & DataList.Fields.Item("PercentUserTime")_
& vbTab & DataList.Fields.Item("PercentProcessorTime")
DataList.MoveNext
Loop
' Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "cmd /c C:\Oracle\Middleware\jdk160_18\bin\jstack.exe " &WScript.Arguments.Item(0)

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c C:\Oracle\Middleware\jdk160_18\bin\jstack.exe " &WScript.Arguments.Item(0))
Do While Not objExecObject.StdOut.AtEndOfStream
    strText = objExecObject.StdOut.ReadLine()
    Wscript.Echo strText
Loop

Find out the java process , but running the command , jps and run the vbscript using the command “cscript test1.vbs”

No comments: