Changes between Version 10 and Version 11 of Commentary/ResourceLimits


Ignore:
Timestamp:
Mar 15, 2013 6:48:58 PM (2 years ago)
Author:
ezyang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/ResourceLimits

    v10 v11  
    66
    77{{{
    8 type CCS
    9 type CC
    10 type Listener
     8-- | A cost-centre; not garbage-collected.
     9data CostCentre
    1110
    12 data ProfType = Residence | Allocated
     11-- | A cost-centre stack.  Cost-centres are composed into cost-centre
     12-- stacks, for which costs are actually attributed.  Cost-centre stacks
     13-- are not garbage-collected.
     14data CostCentreStack
    1315
    14 ccsDynamic :: CCS
     16-- | A listener on a cost-centre stack.  Active listeners are considered
     17-- roots, so be sure to unlisten when you are done.
     18data Listener
    1519
    16 newCC :: IO CC
    17 pushCC :: CCS -> CC -> IO CCS
    18 setCCS :: CCS -> a -> IO ()
    19 withCCS :: CCS -> IO a -> IO a
    20 listenCCS :: CCS -> ProfType -> Int -> IO () -> IO Listener
     20-- | Type of profiling information to track.  We currently support two
     21-- types: instantaneous heap residence, and overall memory allocation
     22-- (which is monotonically increasing).
     23data ProfType = Resident | Allocated
     24
     25-- | Allocates a new cost-centre.
     26newCC :: IO CostCentre
     27
     28-- | Pushes a cost-centre onto a new cost-centre stack.  This function
     29-- is memoized, so if you push the same CostCentre onto the same CostCentreStack, you will
     30-- get the same CostCentreStack back.
     31pushCC :: CostCentreStack -> CostCentre -> IO CostCentreStack
     32
     33-- | Attaches a listener to a cost-centre.  The resolution of the
     34-- listener depends on the type and runtime options.  For resident
     35-- memory listeners, listeners are checked whenever a heap census is run
     36-- (which is controllable using @-i@).  For allocated memory listeners,
     37-- listeners are checked every GC.  When you are no longer interested
     38-- in events from a listener, make sure you unregister the listener, or
     39-- you will leak memory.
     40listenCCS :: CostCentreStack -> ProfType -> Int -> IO () -> IO Listener
     41
     42-- | Unregisters a listener, so that it action will no longer be run.
    2143unlistenCCS :: Listener -> IO ()
    22 getCCSOf :: a -> IO CCS -- already exists
    23 getCurrentCCS :: IO CCS -- already exists
    24 queryCCS :: CCS -> ProfType -> Int
     44
     45-- | Sets the cost-centre of a object on the heap.
     46setCCSOf :: CostCentreStack -> a -> IO ()
     47
     48-- | Runs an IO action with the CostCentreCS set to @ccs@.
     49withCCS :: CostCentreStack -> IO a -> IO a
     50
     51-- | Allocates a new dynamic cost-centre stack; generally, if you want
     52-- something to check usage, this is what you want.
     53newCCS :: IO CostCentreStack
     54
     55-- | Queries for memory statistics about a cost-centre stack.
     56queryCCS :: CostCentreStack -> ProfType -> IO Int
     57
     58-- | Root cost-center stack for dynamically allocated cost center
     59-- stacks.
     60ccsDynamic :: CostCentreStack
    2561}}}
    26 
    27 Listeners automatically deregister themselves when they trigger.
    2862
    2963The general usage of this API goes like: