User:Lieven Van Speybroeck/Prototyping/2-CPUtter: Difference between revisions

From XPUB & Lens-Based wiki
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:prototyping]]
[[Category:2011_P1.01]]
== CPUtter ==
== CPUtter ==


Line 12: Line 16:
* 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 their different pitch values.
* Let it sing!
* Let it sing!


Line 23: Line 27:
</source>
</source>


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:
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:''
 
[log]


<source lang="text">
<source lang="text">
Line 63: Line 71:
'''Code'''
'''Code'''


With sed regular expressions i get rid of all the info that is useless.
''With sed regular expressions i get rid of all the info that is useless.''


[filter.sed]  
[filter.sed]  
Line 84: Line 92:
</source>
</source>


[CPUsage.sh]
''Piping the log to this sed regexp file would give something like this:''
 
[score.txt]
 
<source lang="text">
196
100
50
100
650
503
50
2297
1050
305
197
564
151
2000
1478
761
98
50
1408
597
200
243
882
1055
0
448
202
200
151
49
0
0
0
0
0
0
0
0
0
50
50
50
0
0
50
0
299
0
0
50
49
0
0
0
0
50
100
0
0
50
147
49
149
50
0
50
49
739
490
201
553
341
398
0
103
152
302
201
51
427
603
103
149
99
0
98
50
0
50
0
148
99
155
50
50
0
0
0
0
0
100
457
863
469
51
306
472
406
50
50
293
100
196
50
50
300
253
101
1330
49
50
50
49
50
0
0
199
0
1449
97
150
147
50
50
0
191
149
0
50
0
243
50
343
152
2124
1542
878
1435
248
50
 
... and so on
 
</source>
 
 
 
''Use bash to prepare everything for midge:''
 
[cputter.sh]


<source lang="bash">
<source lang="bash">
Line 90: Line 262:
@head {
@head {
\$time_sig 4/4
\$time_sig 4/4
\$tempo 520
\$tempo 250
}
}
@body {
@body {
Line 97: Line 269:
\$length 60
\$length 60
\$octave 5
\$octave 5
END
\$strum 8
# use bend to create the sequential sound with different pitches
%bend e {
cat <<END
 
%bend f {
END
END


Line 111: Line 282:
normal=2400
normal=2400
heigh=4000
heigh=4000
heighest=6000


# go through every line, compare it to the scale and convert it to a tone + pitch value
 
# go through every line, compare it to the scale and convert it to a tone + pitch (the heigher the tone, the heigher the CPU-usage)


while read line;
while read line;
Line 125: Line 296:
elif [ "$line" -lt "$heigh" ];
elif [ "$line" -lt "$heigh" ];
then echo "4+1"
then echo "4+1"
elif [ "$line" -lt "$heighest" ];  
elif [ "$line" -gt "$heigh" ];  
then echo "4+2"
then echo "4+2"
fi
fi
Line 137: Line 308:
</source>
</source>


''This is the line that's launching the whole thing.''
 
''Start recording your processor activity. Browse, code, watch some (flash) movies, read some mails and get a drink. Do some 3D rendering if you wish! (set the last iostat value high enough then though):''
 
<source lang="bash">
iostat -c 1 250 > log
</source>
 
''When that's done:''
<source lang="bash">
bash cputter.sh | midge -o cputter.mid
timidity cputter.mid
</source>
 
''enjoy!''
 
 
''' ADJUSTMENTS & CORRECTIONS (IMPORTANT)'''
 
I found out there were some problems with my script. Mostly the bending wasn't handled in a right way and it caused trouble for different logfiles. I searched for a way where the bending was handled properly and creates an exact 'image' of the cpu process. Also, i wanted to create a second channel that reflects the idle-percentage of the cpu, and make both channels work a bit like communicating barrels. It was a bit of a struggle, but eventually i came up with this:
 
''First, i had to make a sed file with regexp that would give me the idle-percentages, not the active.''
 
[filter2.sed]
 
<source lang="bash">
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/
</source>
 
''Piping the log into this filter would give something like this:''
 
[score2.txt]
 
<source lang="text">
9550
9801
8693
200
4300
4573
9750
7608
8800
9645
9704
9231
9598
7500
8374
9188
9755
9900
8310
9403
9700
9709
8971
8794
9897
9502
9646
9800
9698
9901
9950
10000
9951
10000
9950
9948
9950
9950
9950
9950
 
... and so on
 
</source>
 
''Then i had to rewrite the bashfile quite drastically''


<source lang="bash">
<source lang="bash">
sudo iwlist eth1 scan | sed -f convertAdress.sed | bash dispatchNotes.sh
cat <<END
@head {
\$time_sig 4/4
\$tempo 80
}
@body {
@channel 1 {
\$patch 53
\$length 12
\$octave 5
\$reverb 100
\$volume 60
 
END
# Use %bend to create a sequential sound that mimics an ongoing and changing process.
# The higher the tone gets, the higher the CPU usage
cat <<END
 
%bend g {
END
 
# Pipe the log file to the filter with the regexp and store the output in a textfile
 
cat log | sed -f filter.sed > score.txt
 
# Define the scale of 'low usage' to 'high usage'.
 
lowest=400
low=1200
normal=2400
high=4000
max=10000
 
# Create variables to define on what pitch level the tones are
 
minpitch=inactive
lowpitch=inactive
normpitch=active
highpitch=inactive
maxpitch=inactive
 
# This is where most corrections/additions take place:
# Go through every line of the score.txt file
# Compare it to the scale
# Check which pitch is active
# Echo a tone with the right bend value relative to the pitch that is active
# Put the current pitch value on active and deactivate the previous one
 
while read line;
do
 
# All checks are necessary to get the bending handled properly and get a correct 'image' of the cpu usage
 
# MINIMAL PITCH LEVEL
# -------------------
if [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$lowpitch" == "active" ]]
then
minpitch=active
lowpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$normpitch" == "active" ]]
then
minpitch=active
normpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$highpitch" == "active" ]]
then
minpitch=active
highpitch=inactive
echo "4-30"
elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$maxpitch" == "active" ]]
then
minpitch=active
maxpitch=inactive
echo "4-40"
elif [[ "$line" -lt "$lowest" && "$minpitch" == "active" ]]
then echo "4+0"
 
# LOW PITCH LEVEL
# ---------------
 
elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
lowpitch=active
echo "4+10"
elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$normpitch" == "active" ]]
then
lowpitch=active
normpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$highpitch" == "active" ]]
then
lowpitch=active
highpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$maxpitch" == "active" ]]
then
lowpitch=active
maxpitch=inactive
echo  "4-30"
elif [[ "$line" -lt "$low" && "$lowpitch" == "active" ]]
then echo "4+0"
# NORMAL PITCH LEVEL
# ------------------
 
elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
normpitch=active
echo "4+20"
elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
normpitch=active
echo "4+10"
elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$highpitch" == "active" ]]
then
normpitch=active
highpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$maxpitch" == "active" ]]
then
normpitch=active
maxpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$normal" && "$normpitch" == "active" ]]
then echo "4+0"
 
# HIGH PITCH LEVEL
# ----------------
 
elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
highpitch=active
echo "4+30"
elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
highpitch=active
echo "4+20"
elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$normpitch" == "active" ]]
then
normpitch=inactive
highpitch=active
echo "4+10"
elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$maxpitch" == "active" ]]
then
highpitch=active
maxpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$high" && "$highpitch" == "active" ]]
then echo "4+0"
 
# MAXIMUM PITCH LEVEL
# -------------------
 
elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
maxpitch=active
echo "4+40"
elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
maxpitch=active
echo "4+30"
elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$normpitch" == "active" ]]
then
normpitch=inactive
maxpitch=active
echo "4+20"
elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$highpitch" == "active" ]]
then
highpitch=inactive
maxpitch=active
echo "4+10"
elif [[ "$line" -gt "$high" && "$maxpitch" == "active" ]]
then echo "4+0"
fi
done < score.txt
 
cat <<END
}
}
 
END
# This second channel will map the idle-percentage of the cpu
# Since idle percentage goes down when active percentage goes up, these 2 channels are a bit like communicating barrels
# I thought it might be nice to turn that into sound.
# The idle percentage are the male voices (bass, in the background, lower volume), they go down when the active voices (females, foreground, higher volume) go up and vice versa
 
cat <<END
 
@channel 2 {
\$patch 53
\$length 12
\$octave 4
\$reverb 100
\$volume 35
%bend f {
 
END
 
# create a new scale for the idle statistics
 
idlemin=400
idlelow=2000
idlenorm=5000
idlehigh=8000
idlemax=10000
 
minpitch=inactive
lowpitch=inactive
normpitch=active
highpitch=inactive
maxpitch=inactive
 
cat log | sed -f filter2.sed > score2.txt
while read line;
do
 
# MINIMAL PITCH LEVEL
# -------------------
if [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$lowpitch" == "active" ]]
then
minpitch=active
lowpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$normpitch" == "active" ]]
then
minpitch=active
normpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$highpitch" == "active" ]]
then
minpitch=active
highpitch=inactive
echo "4-30"
elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$maxpitch" == "active" ]]
then
minpitch=active
maxpitch=inactive
echo "4-40"
elif [[ "$line" -lt "$idlemin" && "$minpitch" == "active" ]]
then echo "4+0"
 
# LOW PITCH LEVEL
# ---------------
 
elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
lowpitch=active
echo "4+10"
elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$normpitch" == "active" ]]
then
lowpitch=active
normpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$highpitch" == "active" ]]
then
lowpitch=active
highpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$maxpitch" == "active" ]]
then
lowpitch=active
maxpitch=inactive
echo  "4-30"
elif [[ "$line" -lt "$idlelow" && "$lowpitch" == "active" ]]
then echo "4+0"
# NORMAL PITCH LEVEL
# ------------------
 
elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
normpitch=active
echo "4+20"
elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
normpitch=active
echo "4+10"
elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$highpitch" == "active" ]]
then
normpitch=active
highpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$maxpitch" == "active" ]]
then
normpitch=active
maxpitch=inactive
echo "4-20"
elif [[ "$line" -lt "$idlenorm" && "$normpitch" == "active" ]]
then echo "4+0"
 
# HIGH PITCH LEVEL
# ----------------
 
elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
highpitch=active
echo "4+30"
elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
highpitch=active
echo "4+20"
elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$normpitch" == "active" ]]
then
normpitch=inactive
highpitch=active
echo "4+10"
elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$maxpitch" == "active" ]]
then
highpitch=active
maxpitch=inactive
echo "4-10"
elif [[ "$line" -lt "$idlehigh" && "$highpitch" == "active" ]]
then echo "4+0"
 
# MAXIMUM PITCH LEVEL
# -------------------
 
elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$minpitch" == "active" ]]
then
minpitch=inactive
maxpitch=active
echo "4+40"
elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$lowpitch" == "active" ]]
then
lowpitch=inactive
maxpitch=active
echo "4+30"
elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$normpitch" == "active" ]]
then
normpitch=inactive
maxpitch=active
echo "4+20"
elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$highpitch" == "active" ]]
then
highpitch=inactive
maxpitch=active
echo "4+10"
elif [[ "$line" -gt "$idlehigh" && "$maxpitch" == "active" ]]
then echo "4+0"
fi
done < score2.txt
 
cat <<END
}
}
}
END
</source>
</source>




'''Output is'''
'''Possible midge file'''
 
<source lang="text">
@head {
$time_sig 4/4
$tempo 80
}
@body {
 
@channel 1 {
$patch 53
$length 12
$octave 5
$reverb 100
$volume 60
 


[[File:sortieDJ.ogg]]
%bend g {
4+0
4+0
4+0
4+0
4+10
4+0
4-10
4+20
4-10
4-10
4+0
4+10
4-10
4+20
4+0
4-10
4-10
4+0
4+20
4-10
4-10
4+0
4+10
4+0
4-10
4+10
4-10
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4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0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4-10
4-10
4+10
4+10
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4-10
4+10
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4-10
4-10
4+10
4+10
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
4+0
}
}
}
</source>
 


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.
'''Output file'''
[[File:proto1_cputter.ogg]]

Latest revision as of 21:40, 27 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 their different 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:

[log]

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/

Piping the log to this sed regexp file would give something like this:

[score.txt]

196
100
50
100
650
503
50
2297
1050
305
197
564
151
2000
1478
761
98
50
1408
597
200
243
882
1055
0
448
202
200
151
49
0
0
0
0
0
0
0
0
0
50
50
50
0
0
50
0
299
0
0
50
49
0
0
0
0
50
100
0
0
50
147
49
149
50
0
50
49
739
490
201
553
341
398
0
103
152
302
201
51
427
603
103
149
99
0
98
50
0
50
0
148
99
155
50
50
0
0
0
0
0
100
457
863
469
51
306
472
406
50
50
293
100
196
50
50
300
253
101
1330
49
50
50
49
50
0
0
199
0
1449
97
150
147
50
50
0
191
149
0
50
0
243
50
343
152
2124
1542
878
1435
248
50

... and so on


Use bash to prepare everything for midge:

[cputter.sh]

cat <<END
@head {
	\$time_sig 4/4
	\$tempo 250
}
@body {
	@channel 1 {
		\$patch 53
		\$length 60
		\$octave 5
		\$strum 8
		%bend e {

END

	cat log | sed -f filter.sed > score.txt

# define the scale of 'low usage' to 'high usage'

	lowest=400
	low=1200
	normal=2400
	heigh=4000


# go through every line, compare it to the scale and convert it to a tone + pitch (the heigher the tone, the heigher the CPU-usage)

	while read line;
		do
			if [ "$line" -lt "$lowest" ];
				then echo "4-2"
			elif [ "$line" -lt "$low" ];
				then echo "4-1"
			elif [ "$line" -lt "$normal" ];
				then echo "4+0"
			elif [ "$line" -lt "$heigh" ];
				then echo "4+1"
			elif [ "$line" -gt "$heigh" ]; 
				then echo "4+2"
			fi
		done < score.txt

cat <<END
		}
	}
}
END


Start recording your processor activity. Browse, code, watch some (flash) movies, read some mails and get a drink. Do some 3D rendering if you wish! (set the last iostat value high enough then though):

iostat -c 1 250 > log

When that's done:

bash cputter.sh | midge -o cputter.mid
timidity cputter.mid

enjoy!


ADJUSTMENTS & CORRECTIONS (IMPORTANT)

I found out there were some problems with my script. Mostly the bending wasn't handled in a right way and it caused trouble for different logfiles. I searched for a way where the bending was handled properly and creates an exact 'image' of the cpu process. Also, i wanted to create a second channel that reflects the idle-percentage of the cpu, and make both channels work a bit like communicating barrels. It was a bit of a struggle, but eventually i came up with this:

First, i had to make a sed file with regexp that would give me the idle-percentages, not the active.

[filter2.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/

Piping the log into this filter would give something like this:

[score2.txt]

9550
9801
8693
200
4300
4573
9750
7608
8800
9645
9704
9231
9598
7500
8374
9188
9755
9900
8310
9403
9700
9709
8971
8794
9897
9502
9646
9800
9698
9901
9950
10000
9951
10000
9950
9948
9950
9950
9950
9950

... and so on

Then i had to rewrite the bashfile quite drastically

cat <<END
@head {
	\$time_sig 4/4
	\$tempo 80
}
@body {
	@channel 1 {
		\$patch 53
		\$length 12
		\$octave 5
		\$reverb 100
		\$volume 60

END
# Use %bend to create a sequential sound that mimics an ongoing and changing process.
# The higher the tone gets, the higher the CPU usage 
cat <<END

		%bend g {
		
END

		# Pipe the log file to the filter with the regexp and store the output in a textfile

		cat log | sed -f filter.sed > score.txt

		# Define the scale of 'low usage' to 'high usage'.

		lowest=400
		low=1200
		normal=2400
		high=4000
		max=10000

		# Create variables to define on what pitch level the tones are

		minpitch=inactive
		lowpitch=inactive
		normpitch=active
		highpitch=inactive
		maxpitch=inactive

	# This is where most corrections/additions take place:	
	# Go through every line of the score.txt file
	# Compare it to the scale
	# Check which pitch is active
	# Echo a tone with the right bend value relative to the pitch that is active
	# Put the current pitch value on active and deactivate the previous one

	while read line;
		do

		# All checks are necessary to get the bending handled properly and get a correct 'image' of the cpu usage

		# MINIMAL PITCH LEVEL
		# -------------------
	
			if [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$lowpitch" == "active" ]]
				then 
				minpitch=active
				lowpitch=inactive				
				echo "4-10"
			elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$normpitch" == "active" ]]
				then 
				minpitch=active
				normpitch=inactive				
				echo "4-20"
			elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$highpitch" == "active" ]]
				then 
				minpitch=active
				highpitch=inactive				
				echo "4-30"
			elif [[ "$line" -lt "$lowest" && "$minpitch" != "active" && "$maxpitch" == "active" ]]
				then 
				minpitch=active
				maxpitch=inactive				
				echo "4-40"
			elif [[ "$line" -lt "$lowest" && "$minpitch" == "active" ]]
				then echo "4+0"

		# LOW PITCH LEVEL
		# ---------------

			elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$minpitch" == "active" ]]
				then 
				minpitch=inactive
				lowpitch=active
				echo "4+10"
			elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$normpitch" == "active" ]]
				then 
				lowpitch=active
				normpitch=inactive
				echo "4-10"
			elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$highpitch" == "active" ]]
				then 
				lowpitch=active
				highpitch=inactive
				echo "4-20"
			elif [[ "$line" -lt "$low" && "$lowpitch" != "active" && "$maxpitch" == "active" ]]
				then 
				lowpitch=active
				maxpitch=inactive				
				echo  "4-30"
			elif [[ "$line" -lt "$low" && "$lowpitch" == "active" ]]
				then echo "4+0"
		
		# NORMAL PITCH LEVEL
		# ------------------

			elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$minpitch" == "active" ]]
				then
				minpitch=inactive
				normpitch=active
				echo "4+20"
			elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$lowpitch" == "active" ]]
				then
				lowpitch=inactive
				normpitch=active
				echo "4+10"
			elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$highpitch" == "active" ]]
				then
				normpitch=active
				highpitch=inactive
				echo "4-10"
			elif [[ "$line" -lt "$normal" && "$normpitch" != "active" && "$maxpitch" == "active" ]]
				then
				normpitch=active
				maxpitch=inactive
				echo "4-20"	
			elif [[ "$line" -lt "$normal" && "$normpitch" == "active" ]]
				then echo "4+0"

		# HIGH PITCH LEVEL
		# ----------------

			elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$minpitch" == "active" ]]
				then
				minpitch=inactive
				highpitch=active
				echo "4+30"
			elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$lowpitch" == "active" ]]
				then
				lowpitch=inactive
				highpitch=active
				echo "4+20"
			elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$normpitch" == "active" ]]
				then
				normpitch=inactive
				highpitch=active
				echo "4+10"
			elif [[ "$line" -lt "$high" && "$highpitch" != "active" && "$maxpitch" == "active" ]]
				then
				highpitch=active
				maxpitch=inactive
				echo "4-10"
			elif [[ "$line" -lt "$high" && "$highpitch" == "active" ]]
				then echo "4+0"

		# MAXIMUM PITCH LEVEL
		# -------------------

			elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$minpitch" == "active" ]] 
				then
				minpitch=inactive
				maxpitch=active
				echo "4+40"
			elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$lowpitch" == "active" ]] 
				then
				lowpitch=inactive
				maxpitch=active
				echo "4+30"
			elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$normpitch" == "active" ]]
				then
				normpitch=inactive
				maxpitch=active
				echo "4+20"
			elif [[ "$line" -gt "$high" && "$maxpitch" != "active" && "$highpitch" == "active" ]]
				then
				highpitch=inactive
				maxpitch=active
				echo "4+10"
			elif [[ "$line" -gt "$high" && "$maxpitch" == "active" ]]
				then echo "4+0"
			fi		
		done < score.txt

cat <<END
			}
		}

END
		# This second channel will map the idle-percentage of the cpu
		# Since idle percentage goes down when active percentage goes up, these 2 channels are a bit like communicating barrels
		# I thought it might be nice to turn that into sound.
		# The idle percentage are the male voices (bass, in the background, lower volume), they go down when the active voices (females, foreground, higher volume) go up and vice versa

cat <<END

		@channel 2 {
			\$patch 53
			\$length 12
			\$octave 4
			\$reverb 100
			\$volume 35
		
		%bend f {

END

		# create a new scale for the idle statistics

		idlemin=400
		idlelow=2000
		idlenorm=5000
		idlehigh=8000
		idlemax=10000

		minpitch=inactive
		lowpitch=inactive
		normpitch=active
		highpitch=inactive
		maxpitch=inactive		

		cat log | sed -f filter2.sed > score2.txt
		
		while read line;
		do

		# MINIMAL PITCH LEVEL
		# -------------------
	
			if [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$lowpitch" == "active" ]]
				then 
				minpitch=active
				lowpitch=inactive				
				echo "4-10"
			elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$normpitch" == "active" ]]
				then 
				minpitch=active
				normpitch=inactive				
				echo "4-20"
			elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$highpitch" == "active" ]]
				then 
				minpitch=active
				highpitch=inactive				
				echo "4-30"
			elif [[ "$line" -lt "$idlemin" && "$minpitch" != "active" && "$maxpitch" == "active" ]]
				then 
				minpitch=active
				maxpitch=inactive				
				echo "4-40"
			elif [[ "$line" -lt "$idlemin" && "$minpitch" == "active" ]]
				then echo "4+0"

		# LOW PITCH LEVEL
		# ---------------

			elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$minpitch" == "active" ]]
				then 
				minpitch=inactive
				lowpitch=active				
				echo "4+10"
			elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$normpitch" == "active" ]]
				then 
				lowpitch=active
				normpitch=inactive				
				echo "4-10"
			elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$highpitch" == "active" ]]
				then 
				lowpitch=active
				highpitch=inactive				
				echo "4-20"
			elif [[ "$line" -lt "$idlelow" && "$lowpitch" != "active" && "$maxpitch" == "active" ]]
				then 
				lowpitch=active
				maxpitch=inactive				
				echo  "4-30"
			elif [[ "$line" -lt "$idlelow" && "$lowpitch" == "active" ]]
				then echo "4+0"
		
		# NORMAL PITCH LEVEL
		# ------------------

			elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$minpitch" == "active" ]]
				then
				minpitch=inactive
				normpitch=active
				echo "4+20"
			elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$lowpitch" == "active" ]]
				then
				lowpitch=inactive
				normpitch=active
				echo "4+10"
			elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$highpitch" == "active" ]]
				then
				normpitch=active
				highpitch=inactive
				echo "4-10"
			elif [[ "$line" -lt "$idlenorm" && "$normpitch" != "active" && "$maxpitch" == "active" ]]
				then
				normpitch=active
				maxpitch=inactive
				echo "4-20"	
			elif [[ "$line" -lt "$idlenorm" && "$normpitch" == "active" ]]
				then echo "4+0"

		# HIGH PITCH LEVEL
		# ----------------

			elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$minpitch" == "active" ]]
				then
				minpitch=inactive
				highpitch=active
				echo "4+30"
			elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$lowpitch" == "active" ]]
				then
				lowpitch=inactive
				highpitch=active
				echo "4+20"
			elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$normpitch" == "active" ]]
				then
				normpitch=inactive
				highpitch=active
				echo "4+10"
			elif [[ "$line" -lt "$idlehigh" && "$highpitch" != "active" && "$maxpitch" == "active" ]]
				then
				highpitch=active
				maxpitch=inactive
				echo "4-10"
			elif [[ "$line" -lt "$idlehigh" && "$highpitch" == "active" ]]
				then echo "4+0"

		# MAXIMUM PITCH LEVEL
		# -------------------

			elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$minpitch" == "active" ]] 
				then
				minpitch=inactive
				maxpitch=active
				echo "4+40"
			elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$lowpitch" == "active" ]] 
				then
				lowpitch=inactive
				maxpitch=active
				echo "4+30"
			elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$normpitch" == "active" ]]
				then
				normpitch=inactive
				maxpitch=active
				echo "4+20"
			elif [[ "$line" -gt "$idlehigh" && "$maxpitch" != "active" && "$highpitch" == "active" ]]
				then
				highpitch=inactive
				maxpitch=active
				echo "4+10"
			elif [[ "$line" -gt "$idlehigh" && "$maxpitch" == "active" ]]
				then echo "4+0"
			fi
		done < score2.txt

cat <<END
		}
	}
}
END


Possible midge file

@head {
	$time_sig 4/4
	$tempo 80
}
@body {

	@channel 1 {
		$patch 53
		$length 12
		$octave 5
		$reverb 100
		$volume 60


		%bend g {
		
4+0
4+0
4+0
4+0
4+10
4+0
4-10
4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