PreferredTechnologies

Overview

This page represents our best attempt at gathering the common tools and practices used by engineers on the Ubuntu Foundations team.

Development

Emacs

We are in alphabetical order, right?! =)

Vim

Plugins

Turns Vim into a fully-functional IDE:

Testing and Debugging

Python

Use pyflakes to check for common errors. Hook this up to your preferred test harness using something akin to the following:

Mock is one of the better mocking libraries and is already used in ubiquity, software-center, and apport.

ipdb iPython like debugging shell with superior tab completion. import ipdb; ipdb.set_trace() is pure heaven.

C

Tracing

Memory Checkers

Note: to use memory checkers reliably, you need to tell (e(g))libc and glib to disable all their checks too like this:

   1 export G_SLICE=always-malloc
   2 export G_DEBUG=gc-friendly,resident-modules
   3 export MALLOC_CHECK_=0

Note the trailing underscore at the end of the last variable!

valgrind

No need to recompile code.

Basic memory checking:

   1    valgrind -v myprogram --arg=foo -baz

More aggressive checking:

   1 valgrind -v \
   2   --track-fds=yes \
   3   --log-file=/tmp/valgrind.log \
   4   --tool=memcheck \
   5   --leak-check=full \
   6   --track-origins=yes \
   7   --malloc-fill=0x0 \
   8   --free-fill=0x0 \
   9   --show-reachable=yes \
  10   myprogram --arg=foo -baz

Deep magic which will spawn gdb when an error is detected (--db-attach=yes):

   1 valgrind \
   2   -v \
   3   --trace-children=yes \
   4   --track-fds=yes \
   5   --time-stamp=yes \
   6   --db-attach=yes \
   7   --read-var-info=yes \
   8   --tool=memcheck \
   9   --leak-check=full \
  10   --leak-resolution=high \
  11   --num-callers=40 \
  12   --show-reachable=yes \
  13   --track-origins=yes \
  14   --undef-value-errors=yes \
  15   --freelist-vol=60000000 \
  16   --malloc-fill=0x7 \
  17   --free-fill=0x8 \
  18   myprogram --arg=foo -baz

dmalloc

Install:

   1 sudo apt-get install -y libdmalloc5 libdmalloc-dev

   1 eval `dmalloc -b -i 1 -l /tmp/dmalloc.log all`
   2 myapp --arg=foo -bar
   3 cat /tmp/dmalloc.log

Using dmalloc with LD_PRELOAD:

   1 (eval `dmalloc -b -i 1 -l /tmp/dmalloc.log all`; LD_PRELOAD=libmalloc.so.5; ./myapp --arg=foo -bar)

wrap_malloc

Simpler more hackable/configurable tool than dmalloc/electric-fence:

http://people.canonical.com/~jhunt/utils/wrap_malloc/

Static Analysis

cppcheck

  •    1 check:
       2     ...
       3     if type cppcheck >/dev/null 2>&1; then \
       4         cppcheck -v . --error-exitcode=1; \
       5     fi
    

splint

Excellent static analysis tool. May now be unmaintained? Does not understand C99 (variadic macros).

  •    1    splint -I/usr/include -I/some/where -DMY_DEFINE=1 -DFOO src/main.c 2>&1|tee splint.log
    
  • LLVM/Clang
       1    sudo apt-get install -y clang
       2    scan-build -v -v -v make 2>&1|tee scan-build.log
    

smatch

Smatch is a static analysis that uses Linus' sparse C parser.

  •    1    make clean
       2    make CHECK="smatch --full-path" CC="cgcc -std=gnu99"
    

Performance testing

  • judge runs two commands 50 times and provides the following report:

    ubuntu@server-8149:~$ ./judge/judge ./2281 ./with_changes
    v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
    
        n mean sd min max cmd
       50 10316.2ms 355.7 9945.9 11638.6 ./2281
       50 9867.5ms 625.8 9385.6 13061.3 ./with_changes
     -448.636ms -4.3% p=0.000
    difference is significant at 95.0% confidence (p=0.000):
    based on these samples, suggested sample size is n>=283 to have a 112.16ms confidence interval

Cloud infrastructure

cloud-init provides a means to run scripts during the creation of a Canonicloud instance. You can use this to create configurations for the infrastructure you need for a project and rapidly deploy that, either to develop or run tests against. See the code in whoopsie-daisy as an example.

Building

  • sbuild (far superior to pbuilder: quicker per-build setup, closer to Launchpad buildd environment, integrates well with schroot for ad-hoc testing)

Productivity

Efficiently splitting a terminal into several smaller windows

tmux is a terminal multiplexer, similar to GNU Screen, but arguably better.

Some tips:

  • The default keybindings let you use ^b arrow to move between panes. However, because this is a sequence of keys rather than a modifier, you can easily get into timing issues where you meant to move to the pane above, then downward in the open file, but actually moved to the pane above and back into the previous one. You can fix this by telling tmux to not wait for commands:

     set -g escape-time 0
  • You can bind a key to take the current tmux selection and put it in the X11 clipboard:
     unbind ^C
     bind ^C run "tmux show-buffer | xclip -i -selection clipboard"

    Using the standard keybindings, you would hit ^b^[ to enter copy mode, ^space to mark the beginning of a selection, the arrow keys to mark the end, and alt-w to select. Then press ^b^c to copy that text to the X11 clipboard.

FoundationsTeam/PreferredTechnologies (last edited 2012-11-23 10:08:08 by host-78-147-189-182)