Update of /cvsroot/monetdb/MonetDB5/src/optimizer
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23107/src/optimizer

Modified Files:
      Tag: GDK-2
        Makefile.ag 
Added Files:
      Tag: GDK-2
        opt_trace.mx 
Log Message:
propagated changes of Monday Sep 10 2007 - Tuesday Sep 18 2007
from the development trunk to the GDK-2 branch


Index: Makefile.ag
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/Makefile.ag,v
retrieving revision 1.47.2.1
retrieving revision 1.47.2.2
diff -u -d -r1.47.2.1 -r1.47.2.2
--- Makefile.ag 13 Aug 2007 21:41:41 -0000      1.47.2.1
+++ Makefile.ag 18 Sep 2007 12:43:54 -0000      1.47.2.2
@@ -33,7 +33,7 @@
                opt_remoteQueries.mx opt_joinselect.mx opt_partitions.mx \
                opt_evaluate.mx opt_inline.mx opt_pushranges.mx \
                opt_accessmode.mx opt_joinpath.mx opt_heuristics.mx 
opt_remap.mx \
-               opt_statistics.mx
+               opt_statistics.mx opt_trace.mx
 
        HEADERS = h 
        #SCRIPTS = mal
@@ -42,7 +42,8 @@
                 $(MALLOC_LIBS) $(PTHREAD_LIBS) $(DL_LIBS) 
 }
 
-scripts_mal = {
+headers_mal = {
+       HEADERS = mal
        DIR = pkglibdir
        SOURCES =  opt_prelude.mx \
                opt_support.mx  opt_crack.mx optimizer.mx  opt_factorize.mx \
@@ -54,7 +55,7 @@
                opt_remoteQueries.mx opt_joinselect.mx opt_partitions.mx \
                opt_evaluate.mx opt_inline.mx opt_pushranges.mx \
                opt_accessmode.mx opt_joinpath.mx opt_heuristics.mx 
opt_remap.mx \
-               opt_statistics.mx
+               opt_statistics.mx opt_trace.mx
 }
 
 EXTRA_DIST_DIR = Tests

--- NEW FILE: opt_trace.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.

@f opt_trace
@- MAL Instruction Trace 
Collection of runtime statistics on specific instructions
is sometimes handy for post-session analysis. To accomplish
this, you need a small optimizer that works its way through
the MAL program and injects calls to your data collector.

The example presented here can act as a template. It has
been designed to gather runtime information over select()
calls for a study on fragmentation. The collector code uses
the target variable to link it with the instruction of interest.
If optimizers decide to move things around, it can still be
localized at runtime.
@example
_26{rows=31:lng} := algebra.uselect(_22,nil:sht,2,false,false);
mdb.collect(_26);
@end example

The result is appended to the hardwired file /tmp/MALtrace.
The mdb module is(should be) extended with signatures
to set the trace file and manipulate the trace table.
@{
@mal
pattern optimizer.trace():str
address OPTtrace;
pattern optimizer.trace(mod:str, fcn:str):str
address OPTdeadcode
comment "Collect trace of a specific operation";

pattern mdb.collect(v:any_1):void
address OPTtraceCall
comment "Dump the previous instruction to a temporary file";
@h
#ifndef _OPT_TRACE_
#define _OPT_TRACE_
#include "opt_prelude.h"
#include "opt_support.h"
#include "mal_interpreter.h"
#include "mal_instruction.h"
#include "mal_function.h"

opt_export str
OPTtraceCall(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
/* #define _DEBUG_OPT_TRACE_      trace its behavior */

@c
#include "mal_config.h"
#include "opt_trace.h"

static str defaultLog;
static struct{
        str modnme,fcnnme;
        ptr modptr,fcnptr;
} monitor[]={
{"algebra","select",0,0},
{"algebra","uselect",0,0},
{0,0,0,0}
};


str
OPTtraceCall(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
        static FILE *trace;
        str msg;
        int i,v;

        if( trace == 0){
                if( defaultLog== 0){
                        char buf[PATHLENGTH];
                        GDKfilepath(buf,"/tmp","MALtrace",NULL);
                        defaultLog= GDKstrdup(buf);
                }

                trace= fopen(defaultLog,"a");
                if( trace == 0)
                        throw(MAL,"mdb.collect","Could not create trace file");
                fprintf(trace,"#-------- \n");
                fflush(trace);
        }
        v= getArg(pci,1);
        for(i=getPC(mb,pci)-1; i>0; i--){
                pci= getInstrPtr(mb,i);
                if( getArg(pci,0) == v){
                        msg= call2str(mb,stk,i,LIST_MAL_ALL);
                        fprintf(trace,"%s\n",msg);
                        GDKfree(msg);
                        break;
                }
        }
        return MAL_SUCCEED;
}

static int 
OPTtraceImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
        int i, k,limit;
        InstrPtr p=0, *old= mb->stmt, q;
        int actions = 0;
        str mod= putName("mdb",3);
        str fcn= putName("collect",7);

        (void) pci;
        (void) stk;             /* to fool compilers */

#ifdef _DEBUG_OPT_TRACE_
        stream_printf(GDKout,"ENTERING TRACE CODE \n");
        printFunction(GDKout,mb,LIST_MAL_ALL);
#endif

        if( monitor[0].modptr == 0)
                for(i=0; monitor[i].modnme; i++){
                        monitor[i].modptr= putName(monitor[i].modnme, 
strlen(monitor[i].modnme));
                        monitor[i].fcnptr= putName(monitor[i].fcnnme, 
strlen(monitor[i].fcnnme));
                }
        limit= mb->stop;
        newMalBlkStmt(mb, mb->stop); /* a new statement stack */

        pushInstruction(mb, old[0]);
        for (i = 1; i < limit; i++) {
                p= old[i];
                pushInstruction(mb,p);
                if( getModuleId(p) )
                for(k=0; monitor[k].modnme; k++)
                if( getModuleId(p) == monitor[k].modptr &&
                        getFunctionId(p) == monitor[k].fcnptr ){
                        /* inject mdb.collect(_n) */
                        q= newFcnCall(mb,mod,fcn);
                        pushArgument(mb,q,getArg(p,0));
                        actions++;
                        break;
                }
        }

#ifdef _DEBUG_OPT_TRACE_
        stream_printf(GDKout,"LEAVING DEAD CODE ELIMINATION\n");
        printFunction(GDKout,mb,LIST_MAL_ALL);
#endif
        GDKfree(old);
        return actions+i;
}
@include optimizerWrapper.mx
@h
@:exportOptimizer(trace)@
#endif
@c
#include "opt_statistics.h"
@:wrapOptimizer(trace,OPT_CHECK_ALL)@
@}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to