File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std:: process:: Command ;
2+ use serde_json:: json;
3+
4+ fn adb ( cmd : & str ) -> String {
5+ let output = Command :: new ( "adb" )
6+ . args ( & [ "shell" , cmd] )
7+ . output ( )
8+ . expect ( "Failed to run adb" ) ;
9+ String :: from_utf8_lossy ( & output. stdout ) . to_string ( )
10+ }
11+
12+ fn main ( ) {
13+ println ! ( "
14+ 🚀 Android Performance Analyzer
15+ " ) ;
16+
17+ // CPU
18+ println ! ( "CPU Info:" ) ;
19+ let cpuinfo = adb ( "cat /proc/cpuinfo | grep processor | wc -l" ) ;
20+ let cores = cpuinfo. trim ( ) ;
21+ println ! ( " Cores: {}" , cores) ;
22+
23+ let freq = adb ( "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ) ;
24+ if !freq. is_empty ( ) {
25+ let mhz = freq. trim ( ) . parse :: < u64 > ( ) . unwrap_or ( 0 ) / 1000 ;
26+ println ! ( " Current Freq: {} MHz" , mhz) ;
27+ }
28+
29+ // Memory
30+ println ! ( "
31+ Memory:" ) ;
32+ let meminfo = adb ( "free -h | grep Mem" ) ;
33+ for line in meminfo. lines ( ) {
34+ if !line. is_empty ( ) {
35+ println ! ( " {}" , line) ;
36+ }
37+ }
38+
39+ // Top processes by CPU
40+ println ! ( "
41+ Top CPU consumers:" ) ;
42+ let top = adb ( "top -n 1 -o %CPU | head -10" ) ;
43+ for ( i, line) in top. lines ( ) . take ( 5 ) . enumerate ( ) {
44+ if i > 0 {
45+ println ! ( " {}" , line) ;
46+ }
47+ }
48+
49+ // Battery
50+ println ! ( "
51+ Battery:" ) ;
52+ let level = adb ( "dumpsys battery | grep level" ) ;
53+ let temp = adb ( "dumpsys battery | grep temperature" ) ;
54+ println ! ( " {}" , level. trim( ) ) ;
55+ println ! ( " {}" , temp. trim( ) ) ;
56+
57+ println ! ( "
58+ ✅ Analysis complete
59+ " ) ;
60+ }
You can’t perform that action at this time.
0 commit comments