From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=DNS_FROM_RFC_POST,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 7D1CFBB84 for ; Mon, 14 Jul 2008 15:53:33 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsBACb3ekhKfSweemdsb2JhbACDJI5IQwEBCwMEBgcRklqEXw X-IronPort-AV: E=Sophos;i="4.30,359,1212357600"; d="scan'208";a="27306186" Received: from yx-out-2324.google.com ([74.125.44.30]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Jul 2008 15:53:32 +0200 Received: by yx-out-2324.google.com with SMTP id 3so1235737yxj.3 for ; Mon, 14 Jul 2008 06:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=2NTZr27fM98jEG2pLSLJCZ00LNGp2V+Gd7aJWH+WH3E=; b=X8h9DsN9NjQwa87w8uthOV25nD4jN0y++FKtQ+WlXx/fN9jrbiW62MfLudcrbyoAxL ZirbThqFgFFJ38FLm+F0Eg7r2jB/NFE+i9FqNSXPnI/OyGqN3WghouMuVoaKVSb76pRc gKSytLuFY38FmdXGSBI//x3PznmdGsO6Dc/lk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=frCmK2HYIIlCDc+LyE675dtIXu227PDv785brQ4rS7JVNPMeKrvIeb9CeRnjoTir+Z 2VyGy+83jfuumjvVuqpMeZEo6TTy+cSw7zUOusmV2DRdBNI7faBrDP8m8qp2LVk78JUc 4YbICa6qi15GIAUOFr0HEGK/Dy+KOPN0x+cmk= Received: by 10.143.35.4 with SMTP id n4mr4222194wfj.64.1216043610910; Mon, 14 Jul 2008 06:53:30 -0700 (PDT) Received: by 10.142.185.4 with HTTP; Mon, 14 Jul 2008 06:53:30 -0700 (PDT) Message-ID: <527cf6bc0807140653w6bb30b5nfa73e2e16462f181@mail.gmail.com> Date: Mon, 14 Jul 2008 15:53:30 +0200 From: "blue storm" To: "Dave Benjamin" Subject: Re: [Caml-list] Name of currently executing function Cc: caml-list@yquem.inria.fr In-Reply-To: <487AE3A6.2080008@ramenlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <487AE3A6.2080008@ramenlabs.com> X-Spam: no; 0.00; camlp:01 ad-hoc:01 camlp:01 functor:01 parametrized:01 functor:01 expr:01 expr:01 transforming:01 printf:01 eprintf:01 storm:98 caml-list:01 func:01 func:01 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).