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/4a59e54e-0fbc-4249-b538-92425b947e10%40gmail.com.
From 60861acf1fbcd572303591d259781dd5b8979c44 Mon Sep 17 00:00:00 2001
From: Qian Yun <[email protected]>
Date: Wed, 13 Dec 2023 18:00:09 +0800
Subject: [PATCH] Do not store stats information into symbol plist

---
 src/interp/g-timer.boot  | 59 +++++++++++++++++++++++-----------------
 src/interp/i-toplev.boot |  4 +--
 2 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/interp/g-timer.boot b/src/interp/g-timer.boot
index cb373c43e..b3044b456 100644
--- a/src/interp/g-timer.boot
+++ b/src/interp/g-timer.boot
@@ -34,18 +34,21 @@
 --% Code instrumentation facilities
 --  These functions can be used with arbitrary lists of
 --  named stats (listofnames) grouped in classes (listofclasses)
---  and with measurement types (property, classproperty).
+--  and with measurement types (property).
 
 makeLongStatStringByProperty _
- (listofnames, listofclasses, property, classproperty, units, flag) ==
+ (listofnames, listofclasses, property, units, flag) ==
   total := 0
   str := '""
-  otherStatTotal := GET('other, property)
+  statsInfo := $statsInfo
+  if property = 'TimeTotal then statVec := first statsInfo
+  if property = 'SpaceTotal then statVec := CADR statsInfo
+  otherStatTotal := statVec.(GET('other, 'index))
   insignificantStat := 0
+  classStats := GETZEROVEC(1 + # listofclasses)
   for [name,class,:ab] in listofnames repeat
-    cl := first LASSOC(class, listofclasses)
-    n := GET(name, property)
-    PUT(cl, classproperty, n + GET(cl, classproperty))
+    n := statVec.(GET(name, 'index))
+    classStats.class := classStats.class + n
     total := total + n
     name = 'other or flag ~= 'long => 'iterate
     if significantStat? n then
@@ -56,7 +59,7 @@ makeLongStatStringByProperty _
     str := makeStatString(str, otherStatTotal + insignificantStat, 'other, flag)
   else
     for [class,name,:ab] in listofclasses repeat
-      n := GET(name, classproperty)
+      n := classStats.class
       str := makeStatString(str, n, ab, flag)
   total := STRCONC(normalizeStatAndStringify total,'" ", units)
   str = '"" =>  total
@@ -141,34 +144,42 @@ DEFPARAMETER($interpreterTimedClasses, '(
   ( 4    reclaim         .  GC) _
   ))
 
-initializeTimedNames(listofnames,listofclasses) ==
-  for [name,:.] in listofnames repeat
-    PUT(name, 'TimeTotal, 0.0)
-    PUT(name, 'SpaceTotal,  0)
-  for [.,name,:.] in listofclasses repeat
-    PUT( name, 'ClassTimeTotal, 0.0)
-    PUT( name, 'ClassSpaceTotal,  0)
+-- $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]
+  for [name, :.] in listofnames for i in 0..len repeat
+    PUT(name, 'index, i)
+  initializeTimedStack()
+
+initializeTimedStack() ==
   $timedNameStack := '(other)
   computeElapsedTime()
   computeElapsedSpace()
-  PUT('gc, 'TimeTotal, 0.0)
-  PUT('gc, 'SpaceTotal,  0)
   NIL
 
 updateTimedName name ==
-  count := (GET(name, 'TimeTotal) or 0) + computeElapsedTime()
-  PUT(name, 'TimeTotal, count)
-  count := (GET(name, 'SpaceTotal) or 0) + computeElapsedSpace()
-  PUT(name, 'SpaceTotal, count)
+  i := GET(name, 'index)
+  statsInfo := $statsInfo
+  timeVec := first statsInfo
+  spaceVec := CADR statsInfo
+  [time, gcTime] := computeElapsedTime()
+  timeVec.i := timeVec.i + time
+  i2 := GET('gc, 'index)
+  timeVec.i2 := timeVec.i2 + gcTime
+  spaceVec.i := spaceVec.i + computeElapsedSpace()
 
 makeLongTimeString(listofnames,listofclasses) ==
   makeLongStatStringByProperty(listofnames, listofclasses,  _
-                               'TimeTotal, 'ClassTimeTotal, _
+                               'TimeTotal, _
                                '"sec", $printTimeIfTrue)
 
 makeLongSpaceString(listofnames,listofclasses) ==
   makeLongStatStringByProperty(listofnames, listofclasses,    _
-                               'SpaceTotal, 'ClassSpaceTotal, _
+                               'SpaceTotal, _
                                '"bytes", $printStorageIfTrue)
 
 DEFPARAMETER($inverseTimerTicksPerSecond, 1.0/$timerTicksPerSecond)
@@ -179,11 +190,9 @@ computeElapsedTime() ==
   gcDelta := currentGCTime - $oldElapsedGCTime
   elapsedSeconds:= $inverseTimerTicksPerSecond *
      (currentTime-$oldElapsedTime-gcDelta)
-  PUT('gc, 'TimeTotal, GET('gc, 'TimeTotal) +
-                   $inverseTimerTicksPerSecond*gcDelta)
   $oldElapsedTime := currentTime
   $oldElapsedGCTime := currentGCTime
-  elapsedSeconds
+  [elapsedSeconds, $inverseTimerTicksPerSecond * gcDelta]
 
 computeElapsedSpace() ==
   currentElapsedSpace := HEAPELAPSED()
diff --git a/src/interp/i-toplev.boot b/src/interp/i-toplev.boot
index 744bc703e..18f9f3dbd 100644
--- a/src/interp/i-toplev.boot
+++ b/src/interp/i-toplev.boot
@@ -69,7 +69,7 @@ interpsysInitialization(display_messages) ==
   interpOpen(display_messages)
   createInitializers()
   if $displayStartMsgs then sayKeyedMsg("S2IZ0053",['"interpreter"])
-  initializeTimedNames($interpreterTimedNames,$interpreterTimedClasses)
+  initializeTimedNames($interpreterTimedNames)
   $InteractiveFrame := makeInitialModemapFrame()
   initializeSystemCommands()
   initializeInterpreterFrameRing()
@@ -128,7 +128,7 @@ DEFPARAMETER($inRetract, nil)
 
 processInteractive(form, posnForm) ==
     $timedNameStack : local := NIL
-    initializeTimedNames($interpreterTimedNames,$interpreterTimedClasses);
+    initializeTimedStack()
     finally(
         object := processInteractive0(form, posnForm),
           while $timedNameStack repeat stopTimingProcess peekTimedName())

Reply via email to