[Haskell-cafe] Debugging misbehaving multi-threaded programs
evan at eklitzke.org
Thu Jun 11 00:40:56 EDT 2009
I've written a multi-threaded Haskell program that I'm trying to
debug. Basically what's happening is the program runs for a while, and
then at some point one of the threads goes crazy and spins the CPU
while allocating memory; this proceeds until the system runs out of
available memory. I can't fix this without figuring out what code is
being executed in the loop (or at least which thread is misbehaving,
which would narrow things down a lot).
I was hopeful that I could compile the program with profiling support
and then use +RTS -M100M along with some of the RTS profiling options
and get profiling information on CPU and memory usage at the time that
my program runs out of memory. The thinking here is that nearly all of
the CPU time and heap space will be from the misbehaving thread, so at
that point I could do more investigation into exactly what is
happening. Unfortunately, this doesn't seem to work; whenever the
program terminates due to running out of heap space, the generated
.prof file is empty.
Another strategy I tried was running the program in ghci and use
-fbreak-on-exception and :trace; by hitting Ctrl-C I was hopeful I'd
stop the program in whatever is looping (this is all described and
suggested in the ghc docs). Unfortunately, this also didn't seem to
work, because the Ctrl-C only stops the main thread.
Does anyone have any tips for dealing this? Have other people run into
similar problems? I'm out of ideas, so I'm open to any suggestions.
Evan Klitzke <evan at eklitzke.org> :wq
More information about the Haskell-Cafe