This is the second patch (of two) to enable correct collection of statistics information on recursive calls to interpreter.
Move $statsInfo and other global variables required for timing to the top of $timedNameStack. Since $timedNameStack now has dynamic scope, recursive timing is correctly supported after this patch. - Qian On 1/16/24 19:29, Qian Yun wrote:
This is the first patch (of two) to enable correct collection of statistics information on recursive calls to interpreter. So instead of storing stats info into symbol plist of $interpreterTimedNames and $interpreterTimedClasses, (which are overwritten during recursive calls.) it now stores such info into $statsInfo. - Qian
-- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/66ff1eb3-bb69-430e-bccd-79cbb398179b%40gmail.com.
From 9eb6e0f240c686024676ce6e2ad99abbad4a8491 Mon Sep 17 00:00:00 2001 From: Qian Yun <[email protected]> Date: Wed, 13 Dec 2023 18:00:09 +0800 Subject: [PATCH] store stat information in $timedNameStack instead of global variables --- src/interp/g-timer.boot | 72 +++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/src/interp/g-timer.boot b/src/interp/g-timer.boot index b3044b456..4a2fbb121 100644 --- a/src/interp/g-timer.boot +++ b/src/interp/g-timer.boot @@ -40,7 +40,7 @@ makeLongStatStringByProperty _ (listofnames, listofclasses, property, units, flag) == total := 0 str := '"" - statsInfo := $statsInfo + statsInfo := (first $timedNameStack).3 if property = 'TimeTotal then statVec := first statsInfo if property = 'SpaceTotal then statVec := CADR statsInfo otherStatTotal := statVec.(GET('other, 'index)) @@ -84,7 +84,7 @@ significantStat? s == INTEGERP s => s ~= 0 s >= 0.1^$timePrintDigits -peekTimedName() == IFCAR $timedNameStack +peekTimedName() == IFCAR IFCDR $timedNameStack popTimedName() == name := IFCAR $timedNameStack @@ -95,25 +95,35 @@ pushTimedName name == PUSH(name,$timedNameStack) startTimingProcess name == - updateTimedName peekTimedName() + oldName := peekTimedName() + topFrame := popTimedName() + topFrame := updateTimedName(oldName, topFrame) pushTimedName name + pushTimedName topFrame stopTimingProcess name == (name ~= peekTimedName()) and null $InteractiveMode => keyedSystemError("S2GL0015",[name,peekTimedName()]) - updateTimedName peekTimedName() + oldName := peekTimedName() + topFrame := popTimedName() + topFrame := updateTimedName(oldName, topFrame) popTimedName() + pushTimedName topFrame --% Instrumentation specific to the interpreter -DEFPARAMETER($oldElapsedSpace, 0) -DEFPARAMETER($oldElapsedGCTime, 0.0) -DEFPARAMETER($oldElapsedTime, 0.0) DEFPARAMETER($timePrintDigits, 2) -- $timedNameStack is used to hold the names of sections of the -- code being timed. -DEFPARAMETER($timedNameStack, '(other)) +DEFVAR($timedNameStack) + +timedStackTopFrame() == + -- statsInfo contains stats numbers. It is a list of 2 vectors, + -- first vector is for TimeTotal, second vector is for SpaceTotal. + len := # $interpreterTimedNames + statsInfo := [GETZEROVEC len, GETZEROVEC len] + VECTOR(get_run_time(), elapsedGcTime(), HEAPELAPSED(), statsInfo) DEFPARAMETER($interpreterTimedNames, '( -- name class abbrev @@ -144,33 +154,35 @@ DEFPARAMETER($interpreterTimedClasses, '( ( 4 reclaim . GC) _ )) --- $statsInfo contains stats numbers. It is a list of 2 vectors, --- first vector is for TimeTotal, second vector is for SpaceTotal. -DEFVAR($statsInfo) - initializeTimedNames(listofnames) == - len := # listofnames - $statsInfo := [GETZEROVEC len, GETZEROVEC len] + len := # $interpreterTimedNames for [name, :.] in listofnames for i in 0..len repeat PUT(name, 'index, i) initializeTimedStack() initializeTimedStack() == $timedNameStack := '(other) - computeElapsedTime() - computeElapsedSpace() + pushTimedName timedStackTopFrame() NIL -updateTimedName name == +updateTimedName(name, topFrame) == + oldTime := topFrame.0 + oldGCTime := topFrame.1 + oldSpace := topFrame.2 + statsInfo := topFrame.3 + newTime := topFrame.0 := get_run_time() + newGCTime := topFrame.1 := elapsedGcTime() + newSpace := topFrame.2 := HEAPELAPSED() + i := GET(name, 'index) - statsInfo := $statsInfo timeVec := first statsInfo spaceVec := CADR statsInfo - [time, gcTime] := computeElapsedTime() - timeVec.i := timeVec.i + time + gcDelta := newGCTime - oldGCTime + timeVec.i := timeVec.i + (newTime - oldTime - gcDelta)*$inverseTimerTicksPerSecond i2 := GET('gc, 'index) - timeVec.i2 := timeVec.i2 + gcTime - spaceVec.i := spaceVec.i + computeElapsedSpace() + timeVec.i2 := timeVec.i2 + gcDelta * $inverseTimerTicksPerSecond + spaceVec.i := spaceVec.i + newSpace - oldSpace + topFrame makeLongTimeString(listofnames,listofclasses) == makeLongStatStringByProperty(listofnames, listofclasses, _ @@ -184,22 +196,6 @@ makeLongSpaceString(listofnames,listofclasses) == DEFPARAMETER($inverseTimerTicksPerSecond, 1.0/$timerTicksPerSecond) -computeElapsedTime() == - currentTime:= get_run_time() - currentGCTime:= elapsedGcTime() - gcDelta := currentGCTime - $oldElapsedGCTime - elapsedSeconds:= $inverseTimerTicksPerSecond * - (currentTime-$oldElapsedTime-gcDelta) - $oldElapsedTime := currentTime - $oldElapsedGCTime := currentGCTime - [elapsedSeconds, $inverseTimerTicksPerSecond * gcDelta] - -computeElapsedSpace() == - currentElapsedSpace := HEAPELAPSED() - elapsedBytes := currentElapsedSpace - $oldElapsedSpace - $oldElapsedSpace := currentElapsedSpace - elapsedBytes - timedAlgebraEvaluation(code) == startTimingProcess 'algebra r := eval code
