2000 年以后制造的所有 PC 都应当能够提供降低功耗的硬件和软件。您需要一个新 Linux 内核,并且它将有助于获得内置有许多节能工具的 Linux 发行版。不过,关闭屏幕或者触发自动关机就可以提供显著的节能优点。如果您拥有的硬件较旧或者不具有 ACPI 功能,应当仍然会发现本文提供的代码十分有用。
#!/usr/bin/perl -w # focusTracker.pl - collect focus data for usage visualizations use strict; use X11::GUITest qw( :ALL ); # find application focus use threads; # non blocking reads from xev use Thread::Queue; # non blocking reads from xev $SIG{INT} = /&printHeader; # print header file to stderr on exit
$|=1; # non-buffered output my %log = (); # focus tracking data structure my $lastId = ""; # last focused window id my $pipe = ""; # non blocking event reads via xev my _cnnew1_cnnew1@win = (); # binary activity data for maxWindows applications my $cpu = ""; # cpu usage from iostat my $mbread_s = ""; # disk read mb/s from iostat my $totalWindow = 0; # total used windows my $maxWindows = 50; # total tracked windows
while(my $line = <STDIN> ) { for my $c (0..$maxWindows){ $win[$c] = 0 } #initialize all data positions
next if( $line =~ /Linux/ || length($line) < 10 ); # header line, empty line
my $windowId = GetInputFocus(); my $windowName = GetWindowName( $windowId ) || "NoWindowName";
if( ! exists($log{$windowId}) ) { # if this is a new window, assign it to the next position in the data set $log{ $windowId }{ order } = $totalWindow; $log{ $windowId }{ name } = $windowName; $totalWindow++ if( $totalWindow < $maxWindows );