[Sugar-devel] SoaS on XO bootcharts
    pgf at laptop.org 
    pgf at laptop.org
       
    Wed Mar  4 11:04:52 EST 2009
    
    
  
wade wrote:
 > These charts are really interesting (and nice looking!).  The whole thing
 > probably requires a lot of analysis to make real gains though.  I wonder
 > what all those calls to 'cat' are in the first chart.  I also wonder if it
i did some looking, and while i don't think i've found the
real culprit, i have found a _lot_ of usage of this idiom in the
scripts:
    [A]
	cmdline=$(cat /proc/cmdline)
or
    [B]
	if [ `cat /proc/sys/net/ipv4/ip_forward` != 0 ]; then
	    action $"Disabling IPv4 packet forwarding: " sysctl -w >
	fi
or
    [C]
	mfgtag () {
		cat $MFG_DATA/$1 | tr -d '\000' 2>/dev/null
	}
in every case, the "cat" process is completely unnecessary.
if i thought bash was a good idea, i'd point out:
    $(< file)
which returns the contents of "file".  but even without
bash (which is probably appropriate if you're looking for
efficiency), you can do:
    [A]
	read cmdline < /proc/cmdline
and this, which preserves the look of the code a bit more:
    [B]
	firstline()
	{
	    read __line < $1;  echo "$__line"
	}
	if [ `firstline /proc/sys/net/ipv4/ip_forward` != 0 ]; then
	    action $"Disabling IPv4 packet forwarding: " sysctl -w >
	fi
and finally this:
    [C]
	mfgtag () {
		tr -d '\000' < $MFG_DATA/$1  2>/dev/null
	}
or even:
    [C]
	mfgtag () {
		tr -d '\000' $MFG_DATA/$1  2>/dev/null
	}
the shell is really pretty fast, if you can keep the number for
spawned processes to a minimum.
paul
=---------------------
 paul fox, pgf at laptop.org
    
    
More information about the Sugar-devel
mailing list