Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code instrumentation in haskell

Suppose I maintain complex application connected to external systems. One day it starts to return unexpected results for certain input and I need to find out why. It could be DNS problem, filesytem related problem, external system change, anything.

Assuming that amount of processing is extensive, before I can identify possible locations of the problem I would need to obtain detailed traces which original application does not produce.

How can I instrument existing code so that I can (for example) provide non-volatile proof (not a live debug session) that certain component or function has a bug.

like image 344
Rumca Avatar asked Apr 21 '14 20:04

Rumca


1 Answers

This sounds like more of an architecture/best practices type question than anything Haskell-specific, unless I'm misunderstanding something.

It sounds like your application needs to use a logging system, such as hslogger. The general approach is to have each component of your code create logging messages with an attached priority. You can then have the application handle different priority levels differently, so for example critical errors could be displayed on the console, while debug and info-level errors go to logfiles.

It's sometimes useful to use Debug.Trace.traceEvent and Debug.Trace.traceEventIO instead of a logging system, particularly if you suspect a concurrency issue, as the ghc eventlog also logs information about thread spawning/switching and garbage collection. But in general it's not a substitution for an actual logging framework.

Also, you may want to make use of assert as a sanity check that "impossible" conditions really don't occur.

like image 187
John L Avatar answered Sep 25 '22 18:09

John L