my debug handler won't stick

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

my debug handler won't stick

Vance Shipley-2

The sys module has a function to install a custom debug
function which will be called whenever a system event is
generated.  It is defined as:

        sys:install(Name, Func, FuncState) -> done | NewFuncState

So I create a debug function like this:

        dbg_fun(FuncState, Event, ProcState) ->
                io:fwrite("~w ~w ~w~n", [FuncState, Event, ProcState]),
                FuncState.

and install it with:

        sys:install(testing, {test, dbg_fun}, foo)

Now the next time I send a message ('bar') to testing I get:

        foo {in, {'$gen_event', bar}} {testing, state1}

Which is great however subsequent messages don't result in
dbg_fun getting called.  The documentation says:

        Func is called whenever a system event is generated.
        This function should return done, or a new func state.
        In the first case, the function is removed. It is removed
        if the function fails.

I assume that FuncState is used to do things like keep counters,
or file names etc. as persistant data through subsequent calls.
It is of type term.  My read is that it should stay put unless
I return 'done'.

What am I doing wrong?

        -Vance





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

my debug handler won't stick

Martin Bjorklund-2
"Vance Shipley" <vances> wrote:

>
> The sys module has a function to install a custom debug
> function which will be called whenever a system event is
> generated.  It is defined as:
>
> sys:install(Name, Func, FuncState) -> done | NewFuncState
>
> So I create a debug function like this:
>
> dbg_fun(FuncState, Event, ProcState) ->
> io:fwrite("~w ~w ~w~n", [FuncState, Event, ProcState]),
> FuncState.
>
> and install it with:
>
> sys:install(testing, {test, dbg_fun}, foo)


You probaly mean:

  sys:install(testing, {{test, dbg_fun}, foo})


> Now the next time I send a message ('bar') to testing I get:
>
> foo {in, {'$gen_event', bar}} {testing, state1}
>
> Which is great however subsequent messages don't result in
> dbg_fun getting called.

You can check the status of you process by calling sys:get_status/1.
There you'll see if your handler is installed:

2> sys:install(error_logger, {{test, dbg_fun}, foo}).
ok
3> sys:get_status(error_logger).
{status,<0.4.0>,
        {module,gen_event},
        [[{'$ancestors',[<0.1.0>]},
          {'$initial_call',{gen,init_it,
                                [gen_event,
                                 <0.1.0>,
                                 <0.1.0>,
                                 {local,error_logger},
                                 [],
                                 [],
                                 []]}}],
         running,
         <0.1.0>,
         [{{test,dbg_fun},foo}],        <-----------------
         [error_logger,
          [{handler,error_logger,false,[],false},
           {handler,error_logger_tty_h,false,{<0.18.0>,error_logger},false}]]]}


This works fine for me.


/martin



Loading...