Files
battery_life/scripts/battery-drain-analysis.sh
rwiegand 6b4b9e0b50 Add battery drain analysis tool and update documentation
- Add battery-drain-analysis.sh: Comprehensive tool to identify battery draining processes
  - Shows top CPU and memory consumers
  - Identifies network-intensive applications
  - Analyzes browser tab usage (counts renderers)
  - Provides actionable recommendations
  - Checks WiFi power management status

- Update README.md with new features:
  - Document CPU power management capabilities (400MHz-4.2GHz dynamic scaling)
  - Add browser optimization tips (tab suspenders, task manager usage)
  - Add application management best practices
  - Document new scripts: cpu-power-control.sh, monitor-cpu-freq.sh, battery-drain-analysis.sh
  - Add BIOS configuration guide reference

- Improve battery life tips:
  - Close heavy browser tabs (can use 77%+ CPU per tab)
  - Install tab suspender extensions (saves 50-70% browser CPU)
  - Manage chat applications (Element/Slack/Discord)
  - Pause file sync services when on battery
  - Screen brightness recommendations

Identified issue: Single browser tab was using 77% CPU, reducing overall browser usage from 268% to 96% CPU
2025-10-06 22:50:32 +02:00

97 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
# Battery Drain Analysis Script
# Identifies processes and settings consuming battery power
echo "=== Battery Drain Analysis ==="
echo ""
# Check if on battery
if [ -f /sys/class/power_supply/AC/online ]; then
AC_STATUS=$(cat /sys/class/power_supply/AC/online)
if [ "$AC_STATUS" -eq 1 ]; then
echo "⚡ System is on AC power"
else
echo "🔋 System is on battery power"
fi
fi
echo ""
echo "=== Top 10 CPU Consumers ==="
ps aux --sort=-%cpu | head -11 | awk '{printf "%-12s %6s %6s %s\n", $1, $2, $3, $11}' | head -11
echo ""
echo "=== Top 10 Memory Consumers ==="
ps aux --sort=-%mem | head -11 | awk '{printf "%-12s %6s %6s %s\n", $1, $2, $4, $11}' | head -11
echo ""
echo "=== Network Activity ==="
if command -v ss >/dev/null 2>&1; then
CONNECTIONS=$(ss -tunap 2>/dev/null | grep ESTAB | wc -l)
echo "Active network connections: $CONNECTIONS"
echo ""
echo "Top network users:"
ss -tunap 2>/dev/null | grep ESTAB | grep -oP 'users:\(\(".*?",pid=\d+' | sort | uniq -c | sort -rn | head -5
fi
echo ""
echo "=== WiFi Power Management ==="
iwconfig 2>&1 | grep -E "wlp|Power Management" | grep -v "no wireless"
echo ""
echo "=== Wakeup Analysis ==="
if command -v powertop >/dev/null 2>&1; then
echo "Running powertop analysis (3 seconds)..."
sudo powertop --time=3 2>&1 | grep -A 20 "Top 10 Power" | head -22
else
echo "Install powertop for detailed wakeup analysis: sudo apt install powertop"
fi
echo ""
echo "=== Browser Tabs Analysis ==="
# Count Brave renderer processes (each is roughly a tab)
BRAVE_RENDERERS=$(ps aux | grep "brave --type=renderer" | grep -v grep | wc -l)
echo "Brave renderer processes: $BRAVE_RENDERERS (≈ number of tabs)"
# Find most CPU-intensive Brave processes
echo ""
echo "Most CPU-intensive Brave tabs:"
ps aux | grep "brave --type=renderer" | grep -v grep | sort -k3 -rn | head -3 | awk '{printf " PID: %6s CPU: %5s%% MEM: %5s%%\n", $2, $3, $4}'
echo ""
echo "=== Recommendations ==="
echo ""
# Check for high CPU usage
HIGH_CPU=$(ps aux --sort=-%cpu | head -2 | tail -1 | awk '{print $3}' | cut -d. -f1)
if [ "$HIGH_CPU" -gt 50 ]; then
TOP_PROCESS=$(ps aux --sort=-%cpu | head -2 | tail -1 | awk '{print $11}')
echo "⚠️ High CPU usage detected: $TOP_PROCESS using $HIGH_CPU%"
echo " Consider closing or suspending this application"
echo ""
fi
# Check for many browser tabs
if [ "$BRAVE_RENDERERS" -gt 20 ]; then
echo "⚠️ Many browser tabs open ($BRAVE_RENDERERS processes)"
echo " Consider using tab suspension extension or closing unused tabs"
echo ""
fi
# Check for Element
if pgrep -x "element-desktop" > /dev/null; then
ELEMENT_CPU=$(ps aux | grep element-desktop | grep -v grep | head -1 | awk '{print $3}' | cut -d. -f1)
if [ "$ELEMENT_CPU" -gt 10 ]; then
echo "⚠️ Element Desktop is using ${ELEMENT_CPU}% CPU"
echo " Consider closing when not actively using Matrix"
echo ""
fi
fi
echo "💡 Quick fixes:"
echo " • Close unused browser tabs"
echo " • Suspend browser tabs with 'The Great Suspender' extension"
echo " • Close Element Desktop if not needed: killall element-desktop"
echo " • Reduce screen brightness"
echo " • Check: ./scripts/cpu-power-control.sh preset balanced"
echo ""