fpco / weigh

Measure allocations of a Haskell functions/values

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation of 'fork'

opened this issue · comments

Hi, I'm using Weigh as part of a system I'm building for automated testing. The fact that Weigh spawns a copy of the executable per test case (related issue #22) is causing problems for my system because it performs subsequent analysis on results from multiple test cases simultaneously (e.g., regression analysis). I've just hacked together a new version of the fork function that uses the async package:

fork :: Action  -> IO Weight
fork (Action !run !arg !name _) = do
  sync <- async $ do
    (bytes, gcs, liveBytes, maxByte) <- case run of
      Right f -> weighFunc   f arg
      Left a  -> weighAction a arg
    return Weight { weightLabel          = name
                  , weightAllocatedBytes = bytes
                  , weightGCs            = gcs
                  , weightLiveBytes      = liveBytes
                  , weightMaxBytes       = maxByte
                  }
  wait sync

I did some tests with the new code, and the results seem to be pretty much the same as the existing code, but maybe I'm missing something. So, I was just wondering if there was a particular reason why the existing implementation spawns a copy of the executable, e.g., from an RTS/memory management perspective?

Many thanks

The spawning a new process is to ensure a cold start for each of your tests, to allow also multithreaded code to be tested.

I understand the first point, would you mind clarifying the second? Do you mean that each test case can run in parallel?

Running consecutive tests in the same exe risks there being a remaining thread open at the end of a test, which might be fine, but that would affect the next test. Process isolation removes these concerns. You should be able to use the existing function weighResults to gather the measurements up to do your regression analysis on.