Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to debug perl code that uses threads

by BrowserUk (Pope)
on Nov 23, 2011 at 10:09 UTC ( #939629=note: print w/ replies, xml ) Need Help??


in reply to How to debug perl code that uses threads

The real answer to debugging threads is to design the code for ease of development/debugging from the outset. Which as far as threads is concerned, means designing each individual thread as a linear flow or data-driven loop with as few inter-thread communications and no synchronisation points. And ensuring that those few inter-thread communications are done via tried and tested mechanisms.

This allows each thread to be tested individually by mocking up its communications flow in a light-weight test environment. Once all the parts have been proven to work alone, testing them together becomes a process of monitoring or tracing the combined communication flows.

But none of that helps you given your situation.

My approach to your problem would be ignore the debugger at the start and add a few trace lines into the actual code at critical points. The trace would be written to a new queue added for the purpose and would consist of (just):

threadId timestamp linenumber

I'd start another thread who's only purpose is to simply write everything on the queue to a file.

By writing this minimal information to a queue, you have minimal impact upon the code under test whilst obtaining a clear overall picture of the flows through the program without producing too huge a trace file to have to plough your way through.

I've also tended to add a ^C interrupt handler in main that simply injects a flag into the trace queue. This is useful when the program manifests behaviour the programmer can see and may want to investigate. You just hit ^C when you see the event occur, and it adds a flag to the trace for off-line investigation later.

If the program uses one or more pools of identical worker threads, temporarily reduce the number of each type to one. It greatly simplifies the trace.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: How to debug perl code that uses threads
Download Code
Re^2: How to debug perl code that uses threads
by raybies (Chaplain) on Nov 23, 2011 at 15:10 UTC

    This is an aside, but I would love to see the contents of your suggestions in a Perl tutorial... I think it'd be a really valuable resource that spoke to the general approach that explained:

    1. Linear Flow or a Data-Driven Loop

    2. Minimal interthread communications/No Synchronization points

    3. Interthread communications use tried/tested means.

    (and yes... I want a pony... ;) )

      It was my intent to respond to your request here, but the more time I spend on it, the more it's going to take to do the job properly. Hence, I'll try to post a meditation in the next couple of weeks.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        /me grins widely... "Sweeeeet." Thanks!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-09-01 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (15 votes), past polls