caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "blue storm" <bluestorm.dylc@gmail.com>
To: "Dave Benjamin" <dave@ramenlabs.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Name of currently executing function
Date: Mon, 14 Jul 2008 15:53:30 +0200	[thread overview]
Message-ID: <527cf6bc0807140653w6bb30b5nfa73e2e16462f181@mail.gmail.com> (raw)
In-Reply-To: <487AE3A6.2080008@ramenlabs.com>

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).


  reply	other threads:[~2008-07-14 13:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-14  5:27 Dave Benjamin
2008-07-14 13:53 ` blue storm [this message]
2008-07-15  6:13   ` [Caml-list] " Dave Benjamin
2008-07-20 16:17   ` Dave Benjamin
2008-07-20 17:35     ` blue storm
2008-07-20 23:41       ` Dave Benjamin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=527cf6bc0807140653w6bb30b5nfa73e2e16462f181@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=dave@ramenlabs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).