Skip to content

Commit

Permalink
Add tracing of built-in operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Nov 27, 2019
1 parent a3dede6 commit c174c7a
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 56 deletions.
1 change: 1 addition & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ SOURCES += src/sysfiles.c
SOURCES += src/sysmem.c
SOURCES += src/system.c
SOURCES += src/tietze.c
SOURCES += src/tracing.c
SOURCES += src/trans.cc
SOURCES += src/vars.c
SOURCES += src/vec8bit.c
Expand Down
1 change: 1 addition & 0 deletions doc/ref/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ afterwards.
<#Include Label="UntraceMethods">
<#Include Label="UntraceAllMethods">
<#Include Label="TraceImmediateMethods">
<#Include Label="TraceInternalMethods">

</Section>

Expand Down
87 changes: 87 additions & 0 deletions lib/oper.g
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,92 @@ BIND_GLOBAL( "TraceImmediateMethods", function( arg )
fi;
end );

#############################################################################
##
##
## <#GAPDoc Label="TraceInternalMethods">
## <ManSection>
## <Func Name="TraceInternalMethods" Arg=''/>
## <Func Name="UntraceInternalMethods" Arg=''/>
## <Func Name="GetTracedInternalMethodsCounts" Arg=''/>
## <Func Name="ClearTraceInternalMethodsCounts" Arg=''/>
##
## <Description>
## <Ref Func="TraceInternalMethods"/> enables tracing for all internal methods.
## Internal methods are methods which implement many fundamental operations in GAP.
## In this version of GAP, the internal methods which can be traced is:
## <List>
## <Mark>Zero, ZeroMut</Mark><Item>Mutable and Immutable <Ref Attr="Zero"/></Item>
## <Mark>AInv, AInvMut</Mark><Item>Mutable and Immutable <Ref Attr="AdditiveInverse"/></Item>
## <Mark>One, OneMut</Mark><Item>Mutable and Immutable <Ref Attr="One"/></Item>
## <Mark>Inv, InvMut</Mark><Item>Mutable and Immutable <Ref Attr="Inverse"/></Item>
## <Mark>Sum</Mark><Item>The operator <Ref Oper="\+"/></Item>
## <Mark>Diff</Mark><Item>The operator <C>-</C> operator</Item>
## <Mark>Prod</Mark><Item>The operator <Ref Oper="\*"/></Item>
## <Mark>Quo</Mark><Item>The operator <Ref Oper="\/"/></Item>
## <Mark>LQuo</Mark><Item>The left-quotient operator</Item>
## <Mark>Pow</Mark><Item>The operator <Ref Oper="\^"/></Item>
## <Mark>Comm</Mark><Item>The operator <Ref Oper="Comm"/></Item>
## <Mark>Mod</Mark><Item>The operator <Ref Oper="\mod"/></Item>
## </List>
## <P/>
## <Ref Func="UntraceInternalMethods"/> turns tracing off.
## As these methods can be called hundreds of thousands of times in simple GAP
## code, there isn't a statement printed each time one is called. Instead, the
## method <Ref Func="GetTracedInternalMethodsCounts"/> returns how many times
## each operation has been applied to each type of variable (the type of a
## variable can be found with the <C>TNAM_OBJ</C> method).
## The return value for two argument operators is a record of records <C>r</C>, where
## <C>r.op</C> stores information about operator <C>op</C>. For one argument operators
## <C>r.op.i</C> stores how many times <C>op</C> was called with an argument of type
## <C>i</C>, while for two argument operators <C>r.op.i.j</C> stores how many times
## <C>op</C> was called with arguments of type <C>i</C> and <C>j</C>.
## <Log><![CDATA[
## gap> TraceInternalMethods();
## true
## gap> 2+3+4+5+6;;
## gap> 2.0+2.0;;
## gap> 3^(1,2,3);;
## gap> GetTracedInternalMethodsCounts();
## rec( Pow := rec( integer := rec( ("permutation (small)") := 1 ) ),
## Sum := rec( integer := rec( integer := 4 ), macfloat := rec( macfloat := 1 ) ) )
## # 'macfloat' is a floating point number
## gap> UntraceInternalMethods();
## ]]></Log>
## </Description>
## </ManSection>
## <#/GAPDoc>
##

# The return type here is stored as a record, as 0 is a valid TNUM.
BIND_GLOBAL("GetTracedInternalMethodsCounts", function()
local ret, type, i, j, counts,member, nicename;
counts := GET_TRACED_INTERNAL_METHODS_COUNTS();
ret := rec();
for type in REC_NAMES(counts) do
# Drop the 'Funcs' part
nicename := type{[1..LENGTH(type)-5]};
ret.(nicename) := rec();
member := counts.(type);
for i in [1..LENGTH(member)] do
if IsBound(member[i]) then
if IS_LIST(member[LENGTH(member)]) then
# Is a 2D array
ret.(nicename).(GET_TNAM_FROM_TNUM(i-1)) := rec();
for j in [1..LENGTH(member[i])] do
if IsBound(member[i][j]) then
ret.(nicename).(GET_TNAM_FROM_TNUM(i-1)).(GET_TNAM_FROM_TNUM(j-1)) := member[i][j];
fi;
od;
else
# Is a 1D array
ret.(nicename).(GET_TNAM_FROM_TNUM(i-1)) := member[i];
fi;
fi;
od;
od;
return ret;
end);

#############################################################################
##
Expand Down Expand Up @@ -2068,3 +2154,4 @@ BIND_GLOBAL( "RECALCULATE_ALL_METHOD_RANKS", function()

Assert(2, CHECK_ALL_METHOD_RANKS());
end );

42 changes: 41 additions & 1 deletion src/ariths.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "error.h"
#include "modules.h"
#include "opers.h"

#include "tracing.h"

#define RequireValue(funcname, val) \
do { \
Expand Down Expand Up @@ -1357,6 +1357,44 @@ static void InstallModObject ( Int verb )
}
}

DEFINE_OP_WRAPPER1(ZeroFuncs);
DEFINE_OP_WRAPPER1(ZeroMutFuncs);
DEFINE_OP_WRAPPER1(AInvFuncs);
DEFINE_OP_WRAPPER1(AInvMutFuncs);
DEFINE_OP_WRAPPER1(OneFuncs);
DEFINE_OP_WRAPPER1(OneMutFuncs);
DEFINE_OP_WRAPPER1(InvFuncs);
DEFINE_OP_WRAPPER1(InvMutFuncs);

DEFINE_OP_WRAPPER2(SumFuncs);
DEFINE_OP_WRAPPER2(DiffFuncs);
DEFINE_OP_WRAPPER2(ProdFuncs);
DEFINE_OP_WRAPPER2(QuoFuncs);
DEFINE_OP_WRAPPER2(LQuoFuncs);
DEFINE_OP_WRAPPER2(PowFuncs);
DEFINE_OP_WRAPPER2(CommFuncs);
DEFINE_OP_WRAPPER2(ModFuncs);

static void InstallArithWrappers(void)
{
INSTALL_OP_WRAPPER(ZeroFuncs);
INSTALL_OP_WRAPPER(ZeroMutFuncs);
INSTALL_OP_WRAPPER(AInvFuncs);
INSTALL_OP_WRAPPER(AInvMutFuncs);
INSTALL_OP_WRAPPER(OneFuncs);
INSTALL_OP_WRAPPER(InvFuncs);
INSTALL_OP_WRAPPER(OneMutFuncs);
INSTALL_OP_WRAPPER(InvMutFuncs);

INSTALL_OP_WRAPPER(SumFuncs);
INSTALL_OP_WRAPPER(DiffFuncs);
INSTALL_OP_WRAPPER(ProdFuncs);
INSTALL_OP_WRAPPER(QuoFuncs);
INSTALL_OP_WRAPPER(LQuoFuncs);
INSTALL_OP_WRAPPER(PowFuncs);
INSTALL_OP_WRAPPER(CommFuncs);
INSTALL_OP_WRAPPER(ModFuncs);
}

/****************************************************************************
**
Expand Down Expand Up @@ -1464,6 +1502,8 @@ static Int InitKernel (
InitHdlrOpersFromTable( GVarOpers );
InitHdlrFuncsFromTable( GVarFuncs );

InstallArithWrappers();

/* make and install the 'ZERO' arithmetic operation */
for ( t1 = FIRST_REAL_TNUM; t1 <= LAST_REAL_TNUM; t1++ ) {
assert(ZeroFuncs[t1] == 0);
Expand Down
73 changes: 18 additions & 55 deletions src/modules_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "objset.h"
#include "profile.h"
#include "syntaxtree.h"
#include "tracing.h"
#include "vec8bit.h"
#include "vecffe.h"
#include "vecgf2.h"
Expand All @@ -44,95 +45,57 @@ const InitInfoFunc InitFuncsBuiltinModules[] = {
InitInfoObjects,

/* profiling and interpreter hooking information */
InitInfoProfile,
InitInfoHookIntrprtr,
InitInfoProfile, InitInfoHookIntrprtr, InitInfoTracing,

/* scanner, reader, interpreter, coder, caller, compiler */
InitInfoIO,
InitInfoScanner,
InitInfoRead,
InitInfoCalls,
InitInfoExprs,
InitInfoStats,
InitInfoCode,
InitInfoVars, /* must come after InitExpr and InitStats */
InitInfoFuncs,
InitInfoOpers,
InitInfoInfo,
InitInfoIntrprtr,
InitInfoIO, InitInfoScanner, InitInfoRead, InitInfoCalls, InitInfoExprs,
InitInfoStats, InitInfoCode,
InitInfoVars, /* must come after InitExpr and InitStats */
InitInfoFuncs, InitInfoOpers, InitInfoInfo, InitInfoIntrprtr,
InitInfoCompiler,

/* arithmetic operations */
InitInfoAriths,

/* record packages */
InitInfoRecords,
InitInfoPRecord,
InitInfoRecords, InitInfoPRecord,

/* internal types */
InitInfoInt,
InitInfoIntFuncs,
InitInfoRat,
InitInfoCyc,
InitInfoFinfield,
InitInfoPermutat,
InitInfoTrans,
InitInfoPPerm,
InitInfoBool,
InitInfoInt, InitInfoIntFuncs, InitInfoRat, InitInfoCyc, InitInfoFinfield,
InitInfoPermutat, InitInfoTrans, InitInfoPPerm, InitInfoBool,
InitInfoMacfloat,

/* list packages */
InitInfoLists,
InitInfoListOper,
InitInfoListFunc,
InitInfoPlist,
InitInfoSet,
InitInfoVector,
InitInfoVecFFE,
InitInfoBlist,
InitInfoRange,
InitInfoString,
InitInfoGF2Vec,
InitInfoVec8bit,
InitInfoLists, InitInfoListOper, InitInfoListFunc, InitInfoPlist,
InitInfoSet, InitInfoVector, InitInfoVecFFE, InitInfoBlist, InitInfoRange,
InitInfoString, InitInfoGF2Vec, InitInfoVec8bit,

/* free and presented groups */
InitInfoFreeGroupElements,
InitInfoCosetTable,
InitInfoTietze,
InitInfoPcElements,
InitInfoCollectors,
InitInfoPcc,
InitInfoDeepThought,
InitInfoFreeGroupElements, InitInfoCosetTable, InitInfoTietze,
InitInfoPcElements, InitInfoCollectors, InitInfoPcc, InitInfoDeepThought,
InitInfoDTEvaluation,

/* algebras */
InitInfoSCTable,

/* save and load workspace, weak pointers */
InitInfoWeakPtr,
InitInfoSaveLoad,
InitInfoWeakPtr, InitInfoSaveLoad,

/* syntax and parser tools */
InitInfoSyntaxTree,

/* input and output */
InitInfoStreams,
InitInfoSysFiles,
InitInfoIOStream,
InitInfoStreams, InitInfoSysFiles, InitInfoIOStream,

/* main module */
InitInfoModules,
InitInfoGap,
InitInfoError,
InitInfoModules, InitInfoGap, InitInfoError,

// objsets / objmaps
InitInfoObjSets,

#ifdef HPCGAP
/* threads */
InitInfoThreadAPI,
InitInfoAObjects,
InitInfoSerialize,
InitInfoThreadAPI, InitInfoAObjects, InitInfoSerialize,
#else
// libgap API
InitInfoLibGapApi,
Expand Down
Loading

0 comments on commit c174c7a

Please sign in to comment.