Skip to content

Commit

Permalink
Remove ActivateProfileColour
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Dec 12, 2022
1 parent bb4d9ab commit 3eb09cb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 149 deletions.
1 change: 0 additions & 1 deletion doc/ref/debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ Profiles are transformed into a human-readable form with
<#Include Label="CoverageLineByLine">
<#Include Label="UnprofileLineByLine">
<#Include Label="UncoverageLineByLine">
<#Include Label="ActivateProfileColour">
<#Include Label="IsLineByLineProfileActive">


Expand Down
22 changes: 0 additions & 22 deletions lib/newprofile.g
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,3 @@ end);
BIND_GLOBAL("UncoverageLineByLine", function()
return DEACTIVATE_PROFILING();
end);


#############################################################################
##
##
## <#GAPDoc Label="ActivateProfileColour">
## <ManSection>
## <Func Name="ActivateProfileColour" Arg=""/>
##
## <Description>
## Called with argument <K>true</K>,
## <Ref Func="ActivateProfileColour"/>
## makes GAP colour functions when printing them to show which lines
## have been executed while profiling was active via
## <Ref Func="ProfileLineByLine" /> at any time during this GAP session.
## Passing <K>false</K> disables this behaviour.
## </Description>
## </ManSection>
## <#/GAPDoc>
BIND_GLOBAL("ActivateProfileColour",function(b)
return ACTIVATE_COLOR_PROFILING(b);
end);
128 changes: 2 additions & 126 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@
** we provide -P (profiling) and -c (code coverage) options to the GAP
** executable so the user can start before code loading starts
**
** 3) Operating at just a line basis can sometimes be too course. We can
** see this when we use ActivateProfileColour. However, without some
** serious additional overheads, I can't see how to provide this
** 3) Operating at just a line basis can sometimes be too course. However,
** without some serious additional overheads, I can't see how to provide this
** functionality in output (basically we would have to store
** line and character positions for the start and end of every expression).
**
Expand Down Expand Up @@ -836,128 +835,6 @@ static Obj FuncIsLineByLineProfileActive(Obj self)
}
}

/****************************************************************************
**
** We are now into the functions which deal with colouring printing output.
** This code basically wraps all the existing print functions and will colour
** their output either green or red depending on if statements are marked
** as being executed.
*/

static Int CurrentColour = 0;

static void setColour(void)
{
if(CurrentColour == 0) {
Pr("\x1b[0m", 0, 0);
}
else if(CurrentColour == 1) {
Pr("\x1b[32m", 0, 0);
}
else if(CurrentColour == 2) {
Pr("\x1b[31m", 0, 0);
}
}

static void ProfilePrintStatPassthrough(Stat stat)
{
Int SavedColour = CurrentColour;
if (visitedStat(stat)) {
CurrentColour = 1;
}
else {
CurrentColour = 2;
}
setColour();
OriginalPrintStatFuncsForHook[TNUM_STAT(stat)](stat);
CurrentColour = SavedColour;
setColour();
}

static void ProfilePrintExprPassthrough(Expr stat)
{
Int SavedColour = -1;
/* There are two cases we must pass through without touching */
/* From TNUM_EXPR */
if(IS_REF_LVAR(stat)) {
OriginalPrintExprFuncsForHook[EXPR_REF_LVAR](stat);
} else if(IS_INTEXPR(stat)) {
OriginalPrintExprFuncsForHook[EXPR_INT](stat);
} else {
SavedColour = CurrentColour;
if (visitedStat(stat)) {
CurrentColour = 1;
}
else {
CurrentColour = 2;
}
setColour();
OriginalPrintExprFuncsForHook[TNUM_STAT(stat)](stat);
CurrentColour = SavedColour;
setColour();
}
}

static struct PrintHooks profilePrintHooks =
{ProfilePrintStatPassthrough, ProfilePrintExprPassthrough};

static Obj activate_colored_output_from_profile(void)
{
HashLock(&profileState);

if(profileState.ColouringOutput) {
HashUnlock(&profileState);
return Fail;
}

ActivatePrintHooks(&profilePrintHooks);

profileState.ColouringOutput = 1;
CurrentColour = 0;
setColour();

HashUnlock(&profileState);

return True;
}

static Obj deactivate_colored_output_from_profile(void)
{
HashLock(&profileState);

if(!profileState.ColouringOutput) {
HashUnlock(&profileState);
return Fail;
}

DeactivatePrintHooks(&profilePrintHooks);

profileState.ColouringOutput = 0;
CurrentColour = 0;
setColour();

HashUnlock(&profileState);

return True;
}

static Obj FuncACTIVATE_COLOR_PROFILING(Obj self, Obj arg)
{
if(arg == True)
{
return activate_colored_output_from_profile();
}
else if(arg == False)
{
return deactivate_colored_output_from_profile();
}
else
return Fail;
}




/****************************************************************************
**
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *
Expand All @@ -977,7 +854,6 @@ static StructGVarFunc GVarFuncs[] = {
resolution),
GVAR_FUNC_0ARGS(DEACTIVATE_PROFILING),
GVAR_FUNC_0ARGS(IsLineByLineProfileActive),
GVAR_FUNC_1ARGS(ACTIVATE_COLOR_PROFILING, arg),
{ 0, 0, 0, 0, 0 }
};

Expand Down

0 comments on commit 3eb09cb

Please sign in to comment.