14

I'm trying to debug a program that uses STM. The ThreadScope readings is pointing out a very high CPU activity as you can see here:

enter image description here

So I'm trying to find out if this is happening due to a transaction that frequently aborts. The first thing that I thought was using something like this to test:

atomically $ do
  someWork 
  ...
`orElse` do
  unsafeIOToSTM $ traceEventIO "transaction aborted!"
  retry

But I'm not sure if this is correct or if this is the best approach to debugging in an STM scenario. Any ideas?

luisgabriel
  • 2,483
  • 1
  • 15
  • 10

1 Answers1

3

Use stm-stats package. It provides trackSTM that you should use instead of atomically, and dumpSTMStats :: IO () that will provide something like this:

STM transaction statistics (2011-10-09 12:28:37.188951 UTC):
Transaction     Commits    Retries      Ratio
_anonymous_           1          0       0.00
reader                1         23      23.00
writer               23          0       0.00

(Transaction names will be generated automatically, but there's helpers to set your own.)

  • Sorry for the long delay to respond. It seems that this package is not updated for a long time. I'll take a look how they check for retries. Thanks! – luisgabriel Jun 21 '16 at 17:38
  • I wouldn't be concerned about lack of updates: 1) Joachim, the maintainer, is well-known in the community; 2) the package is in Stackage LTS, which means it at least builds. – Alexander Batischev Jun 22 '16 at 13:23
  • Just had some time to test `stm-stats` and it worked perfectly! The problem was indeed a transaction frequently aborting. Thank you! – luisgabriel Jul 20 '16 at 18:50