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
This commit is contained in:
94
README.md
94
README.md
@@ -4,16 +4,22 @@ A comprehensive tool suite for optimizing Linux laptop battery life using TLP an
|
||||
|
||||
## 🔋 Overview
|
||||
|
||||
This repository provides scripts, configurations, and tools to maximize your Linux laptop's battery life through advanced power management. The toolkit includes automated installation scripts, optimized configuration files, and monitoring tools.
|
||||
This repository provides scripts, configurations, and tools to maximize your Linux laptop's battery life through advanced power management. The toolkit includes automated installation scripts, optimized configuration files, CPU power management tools, and real-time monitoring utilities.
|
||||
|
||||
**Key Achievement**: Dynamic CPU frequency scaling from 400 MHz (idle) to 4.2 GHz (turbo) on AC power, and 400 MHz to 2.2 GHz on battery for optimal battery life while maintaining responsiveness.
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- **Dynamic CPU Frequency Scaling**: 400 MHz to 4.2 GHz on AC, 400 MHz to 2.2 GHz on battery
|
||||
- **CPU Power Management**: Intel RAPL power limits with preset profiles
|
||||
- **Real-time Monitoring**: CPU frequency, power consumption, and battery drain analysis
|
||||
- **Automated Installation**: One-command setup for TLP and PowerTOP
|
||||
- **Optimized Configurations**: Pre-tuned settings for maximum battery life
|
||||
- **Monitoring Tools**: Real-time battery and power consumption monitoring
|
||||
- **Power Analysis**: Detailed PowerTOP reports and recommendations
|
||||
- **Profile Management**: Easy switching between power profiles
|
||||
- **Safety First**: Backup and rollback capabilities
|
||||
- **BIOS Configuration Guide**: Documentation for optimal firmware settings
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
@@ -60,21 +66,51 @@ cd battery_life
|
||||
./scripts/tlp-manager.sh --profile powersave
|
||||
```
|
||||
|
||||
### 5. CPU Power Management
|
||||
|
||||
```bash
|
||||
# Show current CPU power status
|
||||
./scripts/cpu-power-control.sh status
|
||||
|
||||
# Apply power presets
|
||||
./scripts/cpu-power-control.sh preset dynamic # 400MHz-4.2GHz (recommended)
|
||||
./scripts/cpu-power-control.sh preset balanced # 400MHz-2.2GHz (battery)
|
||||
./scripts/cpu-power-control.sh preset max-performance # 1.6GHz-4.2GHz
|
||||
|
||||
# Set custom power limit
|
||||
./scripts/cpu-power-control.sh set 25 # Set 25W power limit
|
||||
|
||||
# Monitor CPU frequencies in real-time
|
||||
sudo ./scripts/monitor-cpu-freq.sh
|
||||
```
|
||||
|
||||
### 6. Battery Drain Analysis
|
||||
|
||||
```bash
|
||||
# Analyze what's draining your battery
|
||||
./scripts/battery-drain-analysis.sh
|
||||
```
|
||||
|
||||
## 📁 Directory Structure
|
||||
|
||||
```
|
||||
battery_life/
|
||||
├── scripts/
|
||||
│ ├── install.sh # Installation script
|
||||
│ ├── uninstall.sh # Uninstallation script
|
||||
│ ├── battery-monitor.sh # Battery status monitor
|
||||
│ ├── powertop-analyze.sh # PowerTOP analysis tool
|
||||
│ └── tlp-manager.sh # TLP configuration manager
|
||||
│ ├── install.sh # Installation script
|
||||
│ ├── uninstall.sh # Uninstallation script
|
||||
│ ├── battery-monitor.sh # Battery status monitor
|
||||
│ ├── battery-drain-analysis.sh # Identify battery draining processes
|
||||
│ ├── cpu-power-control.sh # CPU power management tool
|
||||
│ ├── monitor-cpu-freq.sh # Real-time CPU frequency monitor
|
||||
│ ├── powertop-analyze.sh # PowerTOP analysis tool
|
||||
│ └── tlp-manager.sh # TLP configuration manager
|
||||
├── config/
|
||||
│ ├── tlp.conf # Optimized TLP configuration
|
||||
│ └── powertop.service # PowerTOP systemd service
|
||||
│ ├── tlp.conf # Optimized TLP configuration
|
||||
│ └── powertop.service # PowerTOP systemd service
|
||||
├── docs/
|
||||
│ └── [Documentation files]
|
||||
│ ├── BIOS-FIX.md # BIOS configuration guide
|
||||
│ ├── powertop-guide.md # PowerTOP usage guide
|
||||
│ └── tlp-configuration.md # TLP configuration details
|
||||
└── README.md
|
||||
```
|
||||
|
||||
@@ -219,6 +255,46 @@ Results vary based on:
|
||||
- Existing system settings
|
||||
- Battery age and health
|
||||
|
||||
## 💡 Additional Battery Saving Tips
|
||||
|
||||
### Browser Optimization
|
||||
Browser tabs are often the biggest battery drain. **Recommended actions**:
|
||||
|
||||
1. **Install a tab suspender extension** (e.g., Suspender MV3, The Great Suspender)
|
||||
- Automatically suspends inactive tabs
|
||||
- Can save 50-70% of browser CPU usage
|
||||
- Dramatically improves battery life
|
||||
|
||||
2. **Use Brave's Task Manager** (`Shift+Esc`)
|
||||
- Identify and close CPU-intensive tabs
|
||||
- Look for tabs using >20% CPU
|
||||
|
||||
3. **Close unused tabs regularly**
|
||||
- Each tab consumes memory and CPU
|
||||
- Aim for <20 active tabs
|
||||
|
||||
4. **Disable unnecessary extensions**
|
||||
- Some extensions run constantly in background
|
||||
- Check `chrome://extensions` regularly
|
||||
|
||||
### Application Management
|
||||
|
||||
1. **Close Element/Slack/Discord when not in use**
|
||||
- Chat applications can use 15-30% CPU in background
|
||||
- Use web versions when occasional access is needed
|
||||
|
||||
2. **Pause file sync services** (Nextcloud, Syncthing, Dropbox)
|
||||
- Manually trigger sync when needed
|
||||
- Prevents constant disk and network activity
|
||||
|
||||
3. **Reduce screen brightness**
|
||||
- Screen is often 30-50% of power consumption
|
||||
- Every 10% reduction saves significant battery
|
||||
|
||||
4. **Close VS Code/IDEs when not coding**
|
||||
- Language servers and extensions consume CPU
|
||||
- Properly exit rather than minimize
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
97
scripts/battery-drain-analysis.sh
Executable file
97
scripts/battery-drain-analysis.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/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 ""
|
||||
Reference in New Issue
Block a user