@@ -8,11 +8,20 @@ Class TestCoverage.Utils.LineByLineMonitor Extends %Monitor.System.LineByLine
88/// True if the line-by-line monitor has been started.
99Property Started As %Boolean [ Calculated , Private , ReadOnly ];
1010
11+ /// True if the Python trace has been set
12+ Property PyStarted As %Boolean [ Calculated , Private , ReadOnly ];
13+
1114Method StartedGet () As %Boolean [ CodeMode = expression ]
1215{
1316$zu (84 ,8 )
1417}
1518
19+ Method PyStartedGet () As %Boolean [ Language = python ]
20+ {
21+ import sys
22+ return sys .gettrace () is not None
23+ }
24+
1625/// True if the line-by-line monitor is paused
1726Property Paused As %Boolean [ Calculated , Private , ReadOnly ];
1827
@@ -30,6 +39,8 @@ Property LastMetricList As %List [ Private ];
3039
3140Property LastProcessList As %List [ Private ];
3241
42+ Property LastPythonList As %List [ Private ];
43+
3344/// This callback method is invoked by the <METHOD>%Close</METHOD> method to
3445/// provide notification that the current object is being closed.
3546///
@@ -98,33 +109,43 @@ Method StartWithScope(pRoutineList As %List, pPyClasses As %List, pMetricList As
98109 Set tSC = $$$OK
99110 Try {
100111 Set ..PythonClassList = pPyClasses
101- Set tDifferentScope = (..LastRoutineList '= pRoutineList ) || (..LastMetricList '= pMetricList ) || (..LastProcessList '= pProcessList )
102- If tDifferentScope && ..Started {
112+ Set tDifferentScope = (..LastRoutineList '= pRoutineList ) || (..LastMetricList '= pMetricList ) || (..LastProcessList '= pProcessList ) || (.. LastPythonList '= pPyClasses )
113+ If tDifferentScope && ( ..Started || .. PyStarted ) {
103114 // If we need to track different routines/metrics/processes, need to stop the monitor before restarting with the new context.
104- Do ..Stop ()
105- Do ..PyStop ()
115+ If (..Started ) {
116+ Do ..Stop ()
117+ }
118+ Do ..PyStop () // setting the trace to None can and should always be done
106119 Set ..LastRoutineList = pRoutineList
107120 Set ..LastMetricList = pMetricList
108121 Set ..LastProcessList = pProcessList
122+ Set ..LastPythonList = pPyClasses
109123 }
110124
111- If '.. Started {
112- Do .. PyClearCounters ()
125+ // take care of starting the ObjectScript Monitor
126+ If ('.. Started && $ListLength ( pRoutineList ) '= 0 ) {
113127 Set tSC = ..Start (pRoutineList , pMetricList , pProcessList )
114- Do ..PyStartWithScope (pPyClasses )
115128 If $System .Status .Equals (tSC ,$$$ERRORCODE($$$MonitorMemoryAlloc)) {
116129 // Construct a more helpful error message.
117130 Set tSC = $$$EMBEDSC(..CheckAvailableMemory ($ListLength (pProcessList ),$ListLength (pRoutineList ),1 ),tSC )
118131 }
119132 $$$ThrowOnError(tSC )
120133 } Else {
121134 // If the monitor was already running, clear the counters.
122- Set tSC = ..ClearCounters ()
123- $$$ThrowOnError(tSC )
124- If ..Paused {
125- $$$ThrowOnError(..Resume ())
126- Do ..PyStartWithScope (pPyClasses )
135+ if (..Started ) {
136+ Set tSC = ..ClearCounters ()
137+ $$$ThrowOnError(tSC )
127138 }
139+ If (..Paused && $ListLength (pRoutineList ) '= 0 ){
140+ $$$ThrowOnError(..Resume ())
141+ }
142+ }
143+
144+ If ('..PyStarted && $ListLength (pPyClasses ) '= 0 ) {
145+ // whether we're resuming or restarting, we either way want to clear counters
146+ // since StoreIntCoverage should have already
147+ Do ..PyClearCounters ()
148+ Do ..PyStartWithScope (pPyClasses )
128149 }
129150 } Catch e {
130151 Set tSC = e .AsStatus ()
0 commit comments