# Setup script for Gracker/Android-App-Memory-Analysis on Windows (PowerShell), from https://gitmanual.com/Gracker/Android-App-Memory-Analysis # Read it before you run it: the commands come from the repo's own README and files. # Run: powershell -ExecutionPolicy Bypass -File .\setup.ps1 $ErrorActionPreference = "Stop" function Write-Step($t) { Write-Host "`n==> $t" -ForegroundColor Cyan } # Windows ships a python that only opens the Microsoft Store; it doesn't count. function Have($c) { $cmd = Get-Command $c -ErrorAction SilentlyContinue; [bool]$cmd -and $cmd.Source -notlike '*\WindowsApps\*' } # New installs change PATH; pick it up without opening a new window. function Update-Path { $env:Path = [Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [Environment]::GetEnvironmentVariable("Path", "User") } # Stop when a program fails, like bash's set -e. Dot-sourced, so cd and venv activation carry on to the next step. function Invoke-Step([scriptblock]$Block) { $global:LASTEXITCODE = 0; . $Block; if ($LASTEXITCODE) { throw "Failed with exit code $LASTEXITCODE" } } # winget's "already installed" and "no newer version" (0x8A150061, 0x8A15002B) aren't failures. function Skip-Installed { if ($LASTEXITCODE -in -1978335135, -1978335189) { $global:LASTEXITCODE = 0 } } Write-Step '1/3 Clone the repository' if (-not (Test-Path 'Android-App-Memory-Analysis')) { Invoke-Step { git clone https://github.com/Gracker/Android-App-Memory-Analysis.git } } Set-Location 'Android-App-Memory-Analysis' Write-Step '2/3 Install the required tools' # Python 3 if (-not (Have 'python')) { Invoke-Step { winget install Python.Python.3.12 -e --accept-source-agreements --accept-package-agreements; Skip-Installed }; Update-Path } if (-not (Have 'python') -and (Have 'py')) { function python { py @args } } Write-Step '3/3 Follow the README: Quick Start' # In the maintainers' order. Do the README instructions above first — they cover steps outside the terminal. Invoke-Step { python3 analyze.py live --list } Invoke-Step { python3 analyze.py live --package com.example.app } Invoke-Step { python3 analyze.py live --package com.example.app --skip-hprof } Invoke-Step { python3 analyze.py live --package com.example.app --dump-only -o ./dumps } Invoke-Step { python3 analyze.py panorama -d ./dumps/com.example.app_20231225_120000 } Invoke-Step { python3 analyze.py panorama -m meminfo.txt -g gfxinfo.txt -H app.hprof -S smaps.txt } Invoke-Step { python3 analyze.py panorama -S smaps.txt --json -o smaps_panorama.json } Invoke-Step { python3 analyze.py hprof demo/hprof_sample/heapdump_latest.hprof.gz } Invoke-Step { python3 analyze.py smaps demo/smaps_sample/smaps } Invoke-Step { python3 analyze.py meminfo dump/meminfo.txt } Invoke-Step { python3 analyze.py gfxinfo dump/gfxinfo.txt } Invoke-Step { python3 analyze.py combined -H demo/hprof_sample/heapdump_latest.hprof.gz -S demo/smaps_sample/smaps } Invoke-Step { python3 analyze.py combined --modern --hprof demo/hprof_sample/heapdump_latest.hprof.gz --smaps demo/smaps_sample/smaps --meminfo demo/smaps_sample/meminfo.txt --json-output report.json } Invoke-Step { python3 analyze.py combined --demo --json-output demo_report.json } Write-Host 'Set up Gracker/Android-App-Memory-Analysis.' Write-Host 'Manual: https://gitmanual.com/Gracker/Android-App-Memory-Analysis'