Skip to content

Instantly share code, notes, and snippets.

@kant2002
Created November 24, 2014 07:05
Show Gist options
  • Save kant2002/da9c4500413004aea665 to your computer and use it in GitHub Desktop.
Save kant2002/da9c4500413004aea665 to your computer and use it in GitHub Desktop.
ADB PowerShell tools

Display threads usage which take more then 10 seconds.

AdbThreadProc 11324 | where 'UserTime' -gt 10  | foreach { $_.ThreadName + "," + $_.UserTime }
# Display process threads information
function AdbProcessInfo($processId) {
adb shell cat /proc/$processId/task/*/stat
}
# Displays user time for the threads in the specific Android process
function AdbThreadProc($processId)
{
AdbProcessInfo($processId) | Where-Object { $_ -match '(\d+)\s'} | foreach {
$data = $_.ToString() -replace '(\d+)\s\(([^)]*?)\)\s\w\s([0-9\-]*\s){10}(\d+).*', '${1},${2},${4}'
$data = $data.Split(",")
$info = @{}
$info.PID= [int]$data[0]
$info.ThreadName=$data[1]
$info.UserTime= [int]$data[2]
$object = New-Object –TypeName PSObject –Prop $info
Write-Output $object
} | Sort-object UserTime -desc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment