📄 proflfun.c
字号:
{ EnvPrintRouter(theEnv,WDISPLAY,"-------------- "); }
EnvPrintRouter(theEnv,WDISPLAY,"------- ------ ----- --------- ------\n");
}
if (ProfileFunctionData(theEnv)->LastProfileInfo == USER_FUNCTIONS) OutputUserFunctionsInfo(theEnv);
if (ProfileFunctionData(theEnv)->LastProfileInfo == CONSTRUCTS_CODE) OutputConstructsCodeInfo(theEnv);
}
/**********************************************/
/* StartProfile: Initiates bookkeeping needed */
/* to profile a construct or function. */
/**********************************************/
globle void StartProfile(
void *theEnv,
struct profileFrameInfo *theFrame,
struct userData **theList,
intBool checkFlag)
{
double startTime, addTime;
struct constructProfileInfo *profileInfo;
if (! checkFlag)
{
theFrame->profileOnExit = FALSE;
return;
}
profileInfo = (struct constructProfileInfo *) FetchUserData(theEnv,ProfileFunctionData(theEnv)->ProfileDataID,theList);
theFrame->profileOnExit = TRUE;
theFrame->parentCall = FALSE;
startTime = gentime();
theFrame->oldProfileFrame = ProfileFunctionData(theEnv)->ActiveProfileFrame;
if (ProfileFunctionData(theEnv)->ActiveProfileFrame != NULL)
{
addTime = startTime - ProfileFunctionData(theEnv)->ActiveProfileFrame->startTime;
ProfileFunctionData(theEnv)->ActiveProfileFrame->totalSelfTime += addTime;
}
ProfileFunctionData(theEnv)->ActiveProfileFrame = profileInfo;
ProfileFunctionData(theEnv)->ActiveProfileFrame->numberOfEntries++;
ProfileFunctionData(theEnv)->ActiveProfileFrame->startTime = startTime;
if (! ProfileFunctionData(theEnv)->ActiveProfileFrame->childCall)
{
theFrame->parentCall = TRUE;
theFrame->parentStartTime = startTime;
ProfileFunctionData(theEnv)->ActiveProfileFrame->childCall = TRUE;
}
}
/*******************************************/
/* EndProfile: Finishes bookkeeping needed */
/* to profile a construct or function. */
/*******************************************/
globle void EndProfile(
void *theEnv,
struct profileFrameInfo *theFrame)
{
double endTime, addTime;
if (! theFrame->profileOnExit) return;
endTime = gentime();
if (theFrame->parentCall)
{
addTime = endTime - theFrame->parentStartTime;
ProfileFunctionData(theEnv)->ActiveProfileFrame->totalWithChildrenTime += addTime;
ProfileFunctionData(theEnv)->ActiveProfileFrame->childCall = FALSE;
}
ProfileFunctionData(theEnv)->ActiveProfileFrame->totalSelfTime += (endTime - ProfileFunctionData(theEnv)->ActiveProfileFrame->startTime);
if (theFrame->oldProfileFrame != NULL)
{ theFrame->oldProfileFrame->startTime = endTime; }
ProfileFunctionData(theEnv)->ActiveProfileFrame = theFrame->oldProfileFrame;
}
/******************************************/
/* OutputProfileInfo: Prints out a single */
/* line of profile information. */
/******************************************/
static intBool OutputProfileInfo(
void *theEnv,
char *itemName,
struct constructProfileInfo *profileInfo,
char *printPrefixBefore,
char *printPrefix,
char *printPrefixAfter,
char **banner)
{
double percent = 0.0, percentWithKids = 0.0;
char buffer[512];
if (profileInfo == NULL) return(FALSE);
if (profileInfo->numberOfEntries == 0) return(FALSE);
if (ProfileFunctionData(theEnv)->ProfileTotalTime != 0.0)
{
percent = (profileInfo->totalSelfTime * 100.0) / ProfileFunctionData(theEnv)->ProfileTotalTime;
if (percent < 0.005) percent = 0.0;
percentWithKids = (profileInfo->totalWithChildrenTime * 100.0) / ProfileFunctionData(theEnv)->ProfileTotalTime;
if (percentWithKids < 0.005) percentWithKids = 0.0;
}
if (percent < ProfileFunctionData(theEnv)->PercentThreshold) return(FALSE);
if ((banner != NULL) && (*banner != NULL))
{
EnvPrintRouter(theEnv,WDISPLAY,*banner);
*banner = NULL;
}
if (printPrefixBefore != NULL)
{ EnvPrintRouter(theEnv,WDISPLAY,printPrefixBefore); }
if (printPrefix != NULL)
{ EnvPrintRouter(theEnv,WDISPLAY,printPrefix); }
if (printPrefixAfter != NULL)
{ EnvPrintRouter(theEnv,WDISPLAY,printPrefixAfter); }
if (strlen(itemName) >= 40)
{
EnvPrintRouter(theEnv,WDISPLAY,itemName);
EnvPrintRouter(theEnv,WDISPLAY,"\n");
itemName = "";
}
sprintf(buffer,ProfileFunctionData(theEnv)->OutputString,
itemName,
(long) profileInfo->numberOfEntries,
(double) profileInfo->totalSelfTime,
(double) percent,
(double) profileInfo->totalWithChildrenTime,
(double) percentWithKids);
EnvPrintRouter(theEnv,WDISPLAY,buffer);
return(TRUE);
}
/*******************************************/
/* ProfileResetCommand: H/L access routine */
/* for the profile-reset command. */
/*******************************************/
globle void ProfileResetCommand(
void *theEnv)
{
struct FunctionDefinition *theFunction;
int i;
#if DEFFUNCTION_CONSTRUCT
DEFFUNCTION *theDeffunction;
#endif
#if DEFRULE_CONSTRUCT
struct defrule *theDefrule;
#endif
#if DEFGENERIC_CONSTRUCT
DEFGENERIC *theDefgeneric;
unsigned int methodIndex;
DEFMETHOD *theMethod;
#endif
#if OBJECT_SYSTEM
DEFCLASS *theDefclass;
HANDLER *theHandler;
unsigned handlerIndex;
#endif
ProfileFunctionData(theEnv)->ProfileStartTime = 0.0;
ProfileFunctionData(theEnv)->ProfileEndTime = 0.0;
ProfileFunctionData(theEnv)->ProfileTotalTime = 0.0;
ProfileFunctionData(theEnv)->LastProfileInfo = NO_PROFILE;
for (theFunction = GetFunctionList(theEnv);
theFunction != NULL;
theFunction = theFunction->next)
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theFunction->usrData));
}
for (i = 0; i < MAXIMUM_PRIMITIVES; i++)
{
if (EvaluationData(theEnv)->PrimitivesArray[i] != NULL)
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,EvaluationData(theEnv)->PrimitivesArray[i]->usrData));
}
}
#if DEFFUNCTION_CONSTRUCT
for (theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,NULL);
theDeffunction != NULL;
theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,theDeffunction))
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theDeffunction->header.usrData));
}
#endif
#if DEFRULE_CONSTRUCT
for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);
theDefrule != NULL;
theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule))
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theDefrule->header.usrData));
}
#endif
#if DEFGENERIC_CONSTRUCT
for (theDefgeneric = (DEFGENERIC *) EnvGetNextDefgeneric(theEnv,NULL);
theDefgeneric != NULL;
theDefgeneric = (DEFGENERIC *) EnvGetNextDefgeneric(theEnv,theDefgeneric))
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theDefgeneric->header.usrData));
for (methodIndex = EnvGetNextDefmethod(theEnv,theDefgeneric,0);
methodIndex != 0;
methodIndex = EnvGetNextDefmethod(theEnv,theDefgeneric,methodIndex))
{
theMethod = GetDefmethodPointer(theDefgeneric,methodIndex);
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theMethod->usrData));
}
}
#endif
#if OBJECT_SYSTEM
for (theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL);
theDefclass != NULL;
theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,theDefclass))
{
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theDefclass->header.usrData));
for (handlerIndex = EnvGetNextDefmessageHandler(theEnv,theDefclass,0);
handlerIndex != 0;
handlerIndex = EnvGetNextDefmessageHandler(theEnv,theDefclass,handlerIndex))
{
theHandler = GetDefmessageHandlerPointer(theDefclass,handlerIndex);
ResetProfileInfo((struct constructProfileInfo *)
TestUserData(ProfileFunctionData(theEnv)->ProfileDataID,theHandler->usrData));
}
}
#endif
}
/*************************************************/
/* ResetProfileInfo: Sets the initial values for */
/* a constructProfileInfo data structure. */
/*************************************************/
globle void ResetProfileInfo(
struct constructProfileInfo *profileInfo)
{
if (profileInfo == NULL) return;
profileInfo->numberOfEntries = 0;
profileInfo->childCall = FALSE;
profileInfo->startTime = 0.0;
profileInfo->totalSelfTime = 0.0;
profileInfo->totalWithChildrenTime = 0.0;
}
/*************************************************/
/* OutputUserFunctionsInfo: */
/*************************************************/
static void OutputUserFunctionsInfo(
void *theEnv)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -