User:Lieven Van Speybroeck/Prototyping/2-CPUtter: Difference between revisions
Line 9: | Line 9: | ||
'''Structure''' | '''Structure''' | ||
*Check user cpu usage for an amount of time and log it in a file. | * Check user cpu usage for an amount of time and log it in a file. | ||
*Filter the logfile so the result is a list of numbers that represent the cpu-usage over time. | * Filter the logfile so the result is a list of numbers that represent the cpu-usage over time. | ||
*Create a scale from "low usage" to "high usage", compare each line of the file to that scale and convert it into a tone with pitch value. | * Create a scale from "low usage" to "high usage", compare each line of the file to that scale and convert it into a tone with pitch value. | ||
*Use bending to create an ongoing sequence between the tones and pitch values. | * Use bending to create an ongoing sequence between the tones and pitch values. | ||
* Let it sing! | |||
Line 62: | Line 63: | ||
'''Code''' | '''Code''' | ||
With sed regular expressions i get rid of all the info that is useless. | |||
[filter.sed] | [filter.sed] | ||
Line 83: | Line 84: | ||
</source> | </source> | ||
[ | [CPUsage.sh] | ||
<source lang="bash"> | <source lang="bash"> | ||
cat <<END | cat <<END | ||
@head { | @head { | ||
\$time_sig 4/4 | |||
\$tempo 520 | |||
} | } | ||
@body { | @body { | ||
@channel 1 { | |||
\$patch 53 | |||
\$length 60 | |||
\$octave 5 | |||
%bend f { | |||
END | END | ||
cat log | sed -f filter.sed > score.txt | |||
smallest=400 | |||
smaller=1200 | |||
normal=2400 | |||
big=4000 | |||
biggest=6000 | |||
while read line; | |||
do | |||
if [ "$line" -lt "$smallest" ]; | |||
then echo "4-2" | |||
elif [ "$line" -lt "$smaller" ]; | |||
then echo "4-1" | |||
elif [ "$line" -lt "$normal" ]; | |||
then echo "4+0" | |||
elif [ "$line" -lt "$big" ]; | |||
then echo "4+1" | |||
elif [ "$line" -lt "$biggest" ]; | |||
then echo "4+2" | |||
fi | |||
done < score.txt | |||
cat <<END | cat <<END | ||
} | |||
} | } | ||
} | } | ||
END | END | ||
</source> | </source> |
Revision as of 01:59, 21 October 2010
CPUtter
Description
The CPU... the brain of our computer systems. And yet, it's so quiet while making it's calculations. Not like those fans, hard disks and DVD-drives that tend to manifest themselves with all sorts of bleeps and buzzes. Therefore, i thought about making a voice for the processor. An intuitive representation of all it's hard work in the background. This is my attempt.
Structure
- Check user cpu usage for an amount of time and log it in a file.
- Filter the logfile so the result is a list of numbers that represent the cpu-usage over time.
- Create a scale from "low usage" to "high usage", compare each line of the file to that scale and convert it into a tone with pitch value.
- Use bending to create an ongoing sequence between the tones and pitch values.
- Let it sing!
Source
For making a log-file of the cpu-usage, i used "iostat", which does pretty much the same as "top" does, but you can filter a bit more:
iostat -c 1 250 > log
This will put 250 cpu-usage (-c) reports at 1 second intervals in "log". You can change the speed and amount of lines (amount of statistics) by changing these numbers. This way you could run it as long as you want to get better results. The output looks a bit like this:
Linux 2.6.32-25-generic (Lieven) 10/21/2010 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
1.52 0.10 0.69 0.28 0.00 97.42
avg-cpu: %user %nice %system %iowait %steal %idle
2.55 0.00 0.00 0.51 0.00 96.94
avg-cpu: %user %nice %system %iowait %steal %idle
3.98 0.00 0.00 0.00 0.00 96.02
avg-cpu: %user %nice %system %iowait %steal %idle
4.10 0.00 2.05 0.00 0.00 93.85
avg-cpu: %user %nice %system %iowait %steal %idle
7.61 0.00 1.52 0.00 0.00 90.86
avg-cpu: %user %nice %system %iowait %steal %idle
4.02 0.00 1.01 0.00 0.00 94.97
avg-cpu: %user %nice %system %iowait %steal %idle
2.01 0.00 2.01 0.00 0.00 95.98
avg-cpu: %user %nice %system %iowait %steal %idle
1.05 0.00 0.00 0.00 0.00 98.95
avg-cpu: %user %nice %system %iowait %steal %idle
5.42 0.00 1.48 0.00 0.00 93.10
... and so on
Code
With sed regular expressions i get rid of all the info that is useless.
[filter.sed]
1d
s/[a-z]//g
s/%//g
s/^[ ]*//g
s/[-:]//g
s/\.//g
s/ /r/g
s/rrrr//g
s/r /r/g
/^$/d
s/r.*//
s/^0\(.*\)/\1/
s/^0\(.\)/\1/
[CPUsage.sh]
cat <<END
@head {
\$time_sig 4/4
\$tempo 520
}
@body {
@channel 1 {
\$patch 53
\$length 60
\$octave 5
%bend f {
END
cat log | sed -f filter.sed > score.txt
smallest=400
smaller=1200
normal=2400
big=4000
biggest=6000
while read line;
do
if [ "$line" -lt "$smallest" ];
then echo "4-2"
elif [ "$line" -lt "$smaller" ];
then echo "4-1"
elif [ "$line" -lt "$normal" ];
then echo "4+0"
elif [ "$line" -lt "$big" ];
then echo "4+1"
elif [ "$line" -lt "$biggest" ];
then echo "4+2"
fi
done < score.txt
cat <<END
}
}
}
END
This is the line that's launching the whole thing.
sudo iwlist eth1 scan | sed -f convertAdress.sed | bash dispatchNotes.sh
Output is
Evolution
For now I can only convert adresses that are eventually merged into a precise channel in midge, but the full idea is to separate every data from each connexion, so that each user revolving around would have is own channel. So each time a new user would connect, a new channel would be added. And the name, quality of signal and adresse would be taken into account as a data for the sound channel.