From 9574759c6216a63115acc0fdaf869749b0a05569 Mon Sep 17 00:00:00 2001 From: Joachim Protze Date: Wed, 11 Aug 2021 12:39:23 +0200 Subject: [PATCH 1/2] Accept reported column to match the width of the variable including the assignment --- scripts/raceCheck.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/raceCheck.py b/scripts/raceCheck.py index bd3652c..4df1206 100644 --- a/scripts/raceCheck.py +++ b/scripts/raceCheck.py @@ -10,21 +10,31 @@ CDIR="C" FDIR="Fortran" +pd.set_option('display.max_rows', 500) +pd.set_option('display.max_columns', 500) +pd.set_option('display.width', 200) + +def matchLineAndCol(gt, tool, id1, id2, r1, r2): + return (gt.loc[id1, r1+"_line"] == tool.loc[id2, r2+"_line"] and + # tool reported column is in the annotation range ( column , column + len(dataname) + 1 ) + int(tool.loc[id2, r1+"_column"]) in range(int(gt.loc[id1, r2+"_column"]), int(gt.loc[id1, r2+"_column"])+len(gt.loc[id1, r2+"_dataname"])+2)) + def queryandcompare(argv): #print(argv[0]) sourceRace = pd.read_json(argv[0]) sourceRace = sourceRace.transpose() # ref1 is always "W", whereas ref2 can be "R" or "W" - sourceRace.loc[sourceRace['ref1_type']=='R', ['ref1_line','ref1_column','ref1_type','ref2_line','ref2_column','ref2_type']] = sourceRace.loc[sourceRace['ref1_type']=='R',['ref2_line','ref2_column','ref2_type','ref1_line','ref1_column','ref1_type']].values + sourceRace.loc[sourceRace['ref1_type']=='R', ['ref1_line','ref1_column','ref1_type','ref1_dataname','ref2_line','ref2_column','ref2_type','ref2_dataname']] = sourceRace.loc[sourceRace['ref1_type']=='R',['ref2_line','ref2_column','ref2_type','ref2_dataname','ref1_line','ref1_column','ref1_type','ref1_dataname']].values print(sourceRace) toolReport = pd.read_json(argv[1]) toolReport = toolReport.transpose() # we should force the format to keep only common essential columns - toolReport = toolReport.drop(columns=['memAddr','ref1_thread','ref2_thread','ref2_filename']) - toolReport.loc[toolReport['ref1_type']=='R', ['ref1_line','ref1_column','ref1_type','ref2_line','ref2_column','ref2_type']] = toolReport.loc[toolReport['ref1_type']=='R',['ref2_line','ref2_column','ref2_type','ref1_line','ref1_column','ref1_type']].values - # For all the possible instances, we only care those with distinct loocation info. - toolReport = toolReport.drop_duplicates() + if(len(toolReport)>0): + toolReport = toolReport.drop(columns=['memAddr','ref1_thread','ref2_thread','ref2_filename']) + toolReport.loc[toolReport['ref1_type']=='R', ['ref1_line','ref1_column','ref1_type','ref2_line','ref2_column','ref2_type']] = toolReport.loc[toolReport['ref1_type']=='R',['ref2_line','ref2_column','ref2_type','ref1_line','ref1_column','ref1_type']].values + # For all the possible instances, we only care those with distinct loocation info. + toolReport = toolReport.drop_duplicates() print(toolReport) # sourceRace['raceTypeMatch?'] = np.where((sourceRace['ref1_type'] == toolReport['ref1_type']) & (sourceRace['ref2_type'] == toolReport['ref2_type']), 'True', 'False') #create new column in df1 to check if prices match @@ -37,11 +47,14 @@ def queryandcompare(argv): typematched = (sourceRace.loc[id1, "ref1_type"] == toolReport.loc[id2, "ref1_type"]) & (sourceRace.loc[id1, "ref2_type"] == toolReport.loc[id2, "ref2_type"]) if( typematched & (sourceRace.loc[id1, "ref2_type"] == 'R')): linematched = (sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"]) - colmatched = linematched & (sourceRace.loc[id1, "ref1_column"] == toolReport.loc[id2, "ref1_column"]) & (sourceRace.loc[id1, "ref2_column"] == toolReport.loc[id2, "ref2_column"]) + colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2"))) elif( typematched & (sourceRace.loc[id1, "ref2_type"] == 'W')): linematched = (((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"])) | ((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref2_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref1_line"]))) - colmatched = linematched & (((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"]) & (sourceRace.loc[id1, "ref1_column"] == toolReport.loc[id2, "ref1_column"]) & (sourceRace.loc[id1, "ref2_column"] == toolReport.loc[id2, "ref2_column"])) | ((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref2_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref1_column"] == toolReport.loc[id2, "ref2_column"]) & (sourceRace.loc[id1, "ref2_column"] == toolReport.loc[id2, "ref1_column"]))) - + colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2")) or + (matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref2") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref1"))) print(typematched, linematched, colmatched) From 3d8c756f3981cb61481531db47a8ef13fd75d9f3 Mon Sep 17 00:00:00 2001 From: Joachim Protze Date: Wed, 11 Aug 2021 14:21:31 +0200 Subject: [PATCH 2/2] Fix logic in raceCheck --- scripts/raceCheck.py | 63 ++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/scripts/raceCheck.py b/scripts/raceCheck.py index 4df1206..14839de 100644 --- a/scripts/raceCheck.py +++ b/scripts/raceCheck.py @@ -10,6 +10,8 @@ CDIR="C" FDIR="Fortran" +TP,FP = (0,1) + pd.set_option('display.max_rows', 500) pd.set_option('display.max_columns', 500) pd.set_option('display.width', 200) @@ -19,6 +21,12 @@ def matchLineAndCol(gt, tool, id1, id2, r1, r2): # tool reported column is in the annotation range ( column , column + len(dataname) + 1 ) int(tool.loc[id2, r1+"_column"]) in range(int(gt.loc[id1, r2+"_column"]), int(gt.loc[id1, r2+"_column"])+len(gt.loc[id1, r2+"_dataname"])+2)) +def evalTFP(vals): + if vals[FP]: + return "FP" + if vals[TP]: + return "TP" + return "FN" def queryandcompare(argv): #print(argv[0]) @@ -39,24 +47,45 @@ def queryandcompare(argv): # sourceRace['raceTypeMatch?'] = np.where((sourceRace['ref1_type'] == toolReport['ref1_type']) & (sourceRace['ref2_type'] == toolReport['ref2_type']), 'True', 'False') #create new column in df1 to check if prices match - for id1 in sourceRace.index: - typematched = False - linematched = False - colmatched = False + typeMatchResult = [False,False] + lineMatchResult = [False,False] + colMatchResult = [False,False] + + + if(len(toolReport)>0): for id2 in toolReport.index: - typematched = (sourceRace.loc[id1, "ref1_type"] == toolReport.loc[id2, "ref1_type"]) & (sourceRace.loc[id1, "ref2_type"] == toolReport.loc[id2, "ref2_type"]) - if( typematched & (sourceRace.loc[id1, "ref2_type"] == 'R')): - linematched = (sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"]) - colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and - matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2"))) - elif( typematched & (sourceRace.loc[id1, "ref2_type"] == 'W')): - linematched = (((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"])) | ((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref2_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref1_line"]))) - colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and - matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2")) or - (matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref2") and - matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref1"))) - - print(typematched, linematched, colmatched) + typematchedFP = True + linematchedFP = True + colmatchedFP = True + for id1 in sourceRace.index: + colmatched = linematched = typematched = (sourceRace.loc[id1, "ref1_type"] == toolReport.loc[id2, "ref1_type"]) & (sourceRace.loc[id1, "ref2_type"] == toolReport.loc[id2, "ref2_type"]) + if (typematched): + typematchedFP = False + typeMatchResult[TP] = True + if( typematched & (sourceRace.loc[id1, "ref2_type"] == 'R')): + linematched = (sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"]) + colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2"))) + elif( typematched & (sourceRace.loc[id1, "ref2_type"] == 'W')): + linematched = (((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref1_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref2_line"])) | ((sourceRace.loc[id1, "ref1_line"] == toolReport.loc[id2, "ref2_line"]) & (sourceRace.loc[id1, "ref2_line"] == toolReport.loc[id2, "ref1_line"]))) + colmatched = linematched & ((matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref1") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref2")) or + (matchLineAndCol(sourceRace, toolReport, id1, id2, "ref1", "ref2") and + matchLineAndCol(sourceRace, toolReport, id1, id2, "ref2", "ref1"))) + if (linematched): + linematchedFP = False + lineMatchResult[TP] = True + if (colmatched): + colmatchedFP = False + colMatchResult[TP] = True + if(typematchedFP): + typeMatchResult[FP]=True + if(linematchedFP): + lineMatchResult[FP]=True + if(colmatchedFP): + colMatchResult[FP]=True + + print(evalTFP(typeMatchResult), evalTFP(lineMatchResult),evalTFP(colMatchResult)) if __name__ == "__main__": queryandcompare(sys.argv[1:])