anchor.diff:  -module(watchdog).
   
   -export([start/0,stop/0]).
  --export([send/3,out/1]).
  +-export([add_send_subscriber/3,add_log_subscriber/0,clear_subscribers/0]).
   -export([message/1]).
   -export([loop/1]).
   
   -include("log.hrl").
   
   -record(ld, 
  -	{jailed=[]			    %jailed pids
  -	 ,subscribers=default_subs()        %where to send our reports
  -	 ,triggers=default_triggers()       %{atom(Tag), fun/1->no|fun/1}
  -	 ,prfState			    %prfTarg:subscribe return val
  -	 ,userData			    %last user data
  -	 ,prfData			    %last prf data
  -	 ,monData			    %last system_monitor data
  -	 ,lines=5			    %# of displayed procs
  +	{jailed=[]			 %jailed pids
  +	 ,subscribers=[]		 %where to send our reports
  +	 ,triggers=default_triggers()	 %{atom(Tag), fun/1->no|fun/1}
  +	 ,prfState			 %prfTarg:subscribe return val
  +	 ,userData			 %last user data
  +	 ,prfData			 %last prf data
  +	 ,monData			 %last system_monitor data
  +	 ,lines=5			 %# of displayed procs
   	}).
   
   %% constants
  -
  -default_subs() -> 
  -  [
  -   send("localhost",56669,"I'm a Cookie")
  -%   ,out(group_leader())
  -  ].
   
   default_triggers() -> 
     [ {[sysMon,long_gc],500}	      %gc time [ms]
  -   ,{[sysMon,large_heap],1024*256} %heap size [words]
  +   ,{[sysMon,large_heap],1024*1024}    %heap size [words]
      ,{user,true}
      ,{ticker,true}
      ,{[prfSys,user],fun(X)->true=(0.95<X) end}
  
positive.code: %% Val :: number() | function()
  %% ID :: list(Tag) 
  %% Tag :: atom() - tags into the data structure. i.e. [prfSys,iowait]
  new_triggers(Triggers,ID,Fun) -> 
    maybe_restart(hd(ID),[{ID,Fun}|clean_triggers(Triggers,[ID])]).
  
  maybe_restart(sysMon,Triggers) -> stop_monitor(),start_monitor(Triggers);
  maybe_restart(_,Triggers) -> Triggers.
  
  clean_triggers(Triggers,IDs) ->
    lists:filter(fun({ID,_})->not lists:member(ID,IDs) end, Triggers).
  
negative.code:   end.
  
  start_monitor(Triggers) ->
    erlang:system_monitor(self(), sysmons(Triggers)).
  
  sysmons(Triggers) ->
    [{Tag,Val} || {[sysMon,Tag],Val} <- Triggers] ++ [busy_port,busy_dist_port].
  