Next, we want to guide the compilation using information gather during a previous profiling
run of the application. To do this, we first have to build an interpreted version of
the application using the option -profile:
> jamaica -profile -smart CaffeineMarkEmbeddedApp
Jamaica Builder Tool
+ CaffeineMarkEmbeddedApp.c
+ CaffeineMarkEmbeddedApp.makefile
Classfile compaction gain: 86.110947% (241514 ==> 33544)
gcc -O2 -o CaffeineMarkEmbeddedApp.o -c CaffeineMarkEmbeddedApp.c ...
gcc -o CaffeineMarkEmbeddedApp CaffeineMarkEmbeddedApp.o /home/...
strip CaffeineMarkEmbeddedApp |
We execute this profiling version and save the profiling output in a file caff.prof:
> ./CaffeineMarkEmbeddedApp >caff.prof |
Such a profiling run could be repeated several times, e.g., if an application should be profiled
using different sample input data sets. In this case, it is sufficient to concatenate all
the resulting profile output into a single file (e.g. using output redircetion with '>>').
Next, we can finally compile the application using the profiling information to restrict
compilation to those methods that cause the highest run-time cost. As a first example,
we restrict compilation to just 10% of the methods that were executed during the profiling
run:
> jamaica -compile -smart -useProfile caff.prof 10 CaffeineMarkEmbeddedApp
Jamaica Builder Tool
+ CaffeineMarkEmbeddedApp.c
+ CaffeineMarkEmbeddedApp.makefile
Classfile compaction gain: 86.9225% (241514 ==> 31584)
gcc -O2 -o CaffeineMarkEmbeddedApp.o -c CaffeineMarkEmbeddedApp.c ...
gcc -o CaffeineMarkEmbeddedApp CaffeineMarkEmbeddedApp.o /home/...
strip CaffeineMarkEmbeddedApp |
The resulting code is reduced to just 168KB
> ll CaffeineMarkEmbeddedApp
-rwxr-xr-x 1 user group 168344 May 24 09:01 CaffeineMarkEmbeddedApp |
while the run-time performance is even improved by the denser code
> ./CaffeineMarkEmbeddedApp
Sieve score = 6036 (98)
Loop score = 10474 (2017)
Logic score = 24448 (0)
String score = 4535 (708)
Float score = 3894 (185)
Method score = 10070 (166650)
Overall score = 8063 |
The size of the binary file can be reduced further by limiting compilation to a still smaller
subset of the methods, e.g., 5% of the methods execution during profiling:
> jamaica -compile -smart -useProfile caff.prof 5 CaffeineMarkEmbeddedApp
Jamaica Builder Tool
+ CaffeineMarkEmbeddedApp.c
+ CaffeineMarkEmbeddedApp.makefile
Classfile compaction gain: 86.775925% (241514 ==> 31938)
gcc -O2 -o CaffeineMarkEmbeddedApp.o -c CaffeineMarkEmbeddedApp.c ...
gcc -o CaffeineMarkEmbeddedApp CaffeineMarkEmbeddedApp.o /home/...
strip CaffeineMarkEmbeddedApp |
The resulting code size cas reduced by about 6KB
> ll CaffeineMarkEmbeddedApp
-rwxr-xr-x 1 user group 162488 May 24 09:03 CaffeineMarkEmbeddedApp |
but, unfortunately, the run-time performance suffers from this reduction, since now too
much interpreted code is executed:
> ./CaffeineMarkEmbeddedApp
Sieve score = 6004 (98)
Loop score = 10336 (2017)
Logic score = 24133 (0)
String score = 3107 (708)
Float score = 3658 (185)
Method score = 4875 (166650)
Overall score = 6604 |