Skip to content

Commit eb6077f

Browse files
committed
feat: the python monitor results now store Rtnline metrics, and in a more efficient manner than before
1 parent 08e9902 commit eb6077f

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

cls/TestCoverage/Data/Coverage.cls

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ ClassMethod StoreIntCoverage(pRun As %Integer, pTestPath As %String, pName As %S
6060
#dim tResult As %SQL.StatementResult
6161
Set tSC = ##class(TestCoverage.Data.CodeUnit).GetCurrentByName(pName_"."_pType,,.tCodeUnit,.pCache)
6262
$$$ThrowOnError(tSC)
63-
6463
If ..UniqueCoverageDataExists(pRun,tCodeUnit.Hash,pTestPath,.tID) {
6564
Set tInstance = ..%OpenId(tID,,.tSC)
6665
$$$ThrowOnError(tSC)
@@ -70,6 +69,10 @@ ClassMethod StoreIntCoverage(pRun As %Integer, pTestPath As %String, pName As %S
7069
$$$ThrowOnError(tSC)
7170
Set tInstance.TestPath = pTestPath
7271
Set tInstance.Hash = tCodeUnit
72+
For tLineNumber=1:1:tCodeUnit.Lines.Count() {
73+
do tInstance.RtnLine.SetAt(0, tLineNumber) // initialized to 0 hits of each line
74+
// necessary for the python coverages because they don't track lines that aren't covered, only lines that are covered
75+
}
7376
}
7477

7578
Set tCoveredLines = tInstance.CoveredLines
@@ -102,12 +105,17 @@ ClassMethod StoreIntCoverage(pRun As %Integer, pTestPath As %String, pName As %S
102105
$$$ThrowOnError(tSC)
103106
}
104107
Else { // If pType = "PY"
105-
//^IRIS.TEMP.TestCoveragePy(ClassName) contains the number of covered lines in this class
106-
//^IRIS.TEMP.TestCoveragePy(ClassName, i) in increasing order contain the line numbers for the covered lines
108+
// $$$PyMonitorResults(classname, linenumber) = the number of times that linenumber in that class was covered
109+
107110
if $Data($$$PyMonitorResults(pName)) {
108-
for i = 1:1:($$$PyMonitorResults(pName)-1) {
109-
Set tLineNumber = $$$PyMonitorResults(pName, i)
110-
Set $Bit(tCoveredLines, tLineNumber) = 1
111+
Set tLine = ""
112+
for {
113+
Set tLine = $Order($$$PyMonitorResults(pName, tLine), 1, tLineCount)
114+
if (tLine = "") {
115+
quit
116+
}
117+
Set $Bit(tCoveredLines, tLine) = 1
118+
Do tInstance.RtnLine.SetAt(tInstance.RtnLine.GetAt(tLine) + tLineCount, tLine)
111119
}
112120
}
113121

cls/TestCoverage/Utils/LineByLineMonitor.cls

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ ClassMethod PyStartWithScope(pCoverageClasses As %List) [ Language = python ]
7171
line_no = frame.f_lineno
7272
if class_name in tCoverageClasses and line_no != 1: # if this is in a covered class
7373
tGlob = iris.gref('^IRIS.TEMP.TestCoveragePY') # python doesn't have macros -- this is $$$PyMonitorResults
74-
curId = tGlob.get([class_name])
75-
if not curId:
76-
tGlob[class_name] = 1
77-
curId = 1
78-
tGlob[class_name, curId] = line_no
79-
tGlob[class_name] = curId+1
74+
# $$$PyMonitorResults(classname, linenumber) = the number of times that linenumber in that class was covered
75+
76+
curCount = tGlob.get([class_name, line_no])
77+
if not curCount:
78+
curCount = 0
79+
tGlob[class_name, line_no] = curCount + 1
80+
8081
return my_tracer
8182
settrace(my_tracer)
8283
}

0 commit comments

Comments
 (0)