Browse thread
Name of currently executing function
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-07-14 (13:53) |
From: | blue storm <bluestorm.dylc@g...> |
Subject: | Re: [Caml-list] Name of currently executing function |
Here is a little camlp4 code for an ad-hoc solution : http://bluestorm.info/camlp4/Camlp4GenericProfiler.ml It's based upon the Camlp4Filters/Camlp4Profiler.ml from the camlp4 distribution. The GenericMake functor will traverse your code and apply the parametrized function to the body of each function declaration. You can use it with a functor providing a (with_fun_name : string -> Ast.expr -> Ast.expr), transforming the Ast to your liking, given the function name. I've written a small LoggingDecorator module that operates on the __LOG__ identifier. Example code : let __LOG_FUNC__ func msg = Printf.eprintf "in function %s: %s\n%!" func msg let test_function p = if not p then __LOG__ "p is false !" It will replace the __LOG__ identifier with a __LOG_FUNC__ "p". You can change that behavior, in particular you could be interested (for logging purpose) in the location of the function declaration, not only his name : see how the initial Camlp4Profiler behavior (wich i kept in the ProfilingDecorator) do that (Loc.dump).