Optimizing
From Buzztard
This page is about ideas of how to optimize ressource usage of linux apps.
Contents |
[edit] Linking
[edit] --as-needed flag
see discussion about --as-needed flag
[edit] elf visibility
[edit] Analysing
[edit] strace
strace is a good too to check whats going on. Here are two examples:
strace -e trace=file 2>trace.log.0003 ./bt-cmd --command=info --input-file=../share/buzztard/songs/simple2.xml strace -c 2>trace.sum.0003 ./bt-cmd --command=info --input-file=../share/buzztard/songs/simple2.xml
Additionally we can use strace together with plot-timeline.py:
strace -ttt -f -o /tmp/logfile.strace my-program plot-timeline.py -o prettygraph.png /tmp/logfile.strace
We can also test if bt-edit operates tickless (which it doesn't yet, because of the cpu-monitor),
strace -ttt -e poll -p `pidof bt-edit`
[edit] oprofile
To collect data run
opcontrol --reset opcontrol --start <run programm> opcontrol --stop opcontrol --dump opcontrol --shutdown
To analyse profiling data:
opreport -l | head -n20 opreport -l /home/ensonic/lib/libx* | head -n20 opannotate --source --output-dir=/home/ensonic/temp/libx /home/ensonic/lib/libx*
[edit] Memory usage
[edit] use g_alloca
Alloca reserves memory on the stack. It is a bit more tedious to handle (maybe we can wrap it up in a macro), but has several advantages. It only works if we just temporaily need the space. Advantages are
- its fast
- we don't need to free the stuff
- it does not fragment memory space
Instead of doing:
gchar *status=g_strdup_printf(_("Loading file \"%s\""),file_name);
g_object_set(G_OBJECT(self),"status",status,NULL);
g_free(status);
do it like below:
gchar *status=g_alloca(strlen(_("Loading file \"%s\""))+strlen(file_name)-1);
g_sprintf(status,_("Loading file \"%s\""),file_name);
g_object_set(G_OBJECT(self),"status",status,NULL);
It is not trivial to write it as a macro, as it needs to figure the length of the result string.



