Skip to content

Commit

Permalink
clean up and improve SVF stats (#1341)
Browse files Browse the repository at this point in the history
* Fix numOfElements for a C++ object with vtable

* clean up SVF statistics

* update AndersenStat

* update AndersenStat
  • Loading branch information
yuleisui committed Jan 20, 2024
1 parent 896a0bf commit bccd2da
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 40 deletions.
9 changes: 0 additions & 9 deletions svf/include/MemoryModel/PointerAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace SVF

class CommonCHGraph;

class TypeSystem;
class SVFModule;
class ICFG;
class PTAStat;
Expand Down Expand Up @@ -156,8 +155,6 @@ class PointerAnalysis
ICFG* icfg;
/// CHGraph
CommonCHGraph *chgraph;
/// TypeSystem
TypeSystem *typeSystem;

public:
/// Get ICFG
Expand Down Expand Up @@ -433,12 +430,6 @@ class PointerAnalysis
virtual void resolveCPPIndCalls(const CallICFGNode* cs,
const PointsTo& target,
CallEdgeMap& newEdges);

/// get TypeSystem
const TypeSystem *getTypeSystem() const
{
return typeSystem;
}
};

} // End namespace SVF
Expand Down
3 changes: 3 additions & 0 deletions svf/include/Util/SVFStat.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class SVFStat
/// Default call for getClk is unmarked, while MarkedClocksOnly is false by default.
static double getClk(bool mark = false);

/// SVF's general statistics are only printed once even if you run multiple anayses
static bool printGeneralStats;

NUMStatMap generalNumMap;
NUMStatMap PTNumStatMap;
TIMEStatMap timeStatMap;
Expand Down
4 changes: 2 additions & 2 deletions svf/lib/DDA/DDAStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ void DDAStat::performStat()
PTNumStatMap["NumOfMustAA"] = _TotalNumOfMustAliases;
PTNumStatMap["NumOfInfePath"] = _TotalNumOfInfeasiblePath;
PTNumStatMap["NumOfStore"] = SVFIR::getPAG()->getPTASVFStmtSet(SVFStmt::Store).size();
PTNumStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
PTNumStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;
timeStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
timeStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;

printStat();
}
Expand Down
6 changes: 2 additions & 4 deletions svf/lib/Graphs/SVFGStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,13 @@ void SVFGStat::performSCCStat(SVFGEdgeSet insensitiveCalRetEdges)
PTNumStatMap["InsenRetEdge"] = insensitiveRetEdge;


SVFUtil::outs() << "\n****SVFG SCC Stat****\n";
PTAStat::printStat();
PTAStat::printStat("SVFG SCC Stat");

delete svfgSCC;

}

void SVFGStat::printStat(string str)
{
SVFUtil::outs() << "\n****SVFG Statistics****\n";
PTAStat::printStat(str);
PTAStat::printStat("SVFG Statistics");
}
2 changes: 1 addition & 1 deletion svf/lib/MemoryModel/PointerAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const std::string PointerAnalysis::aliasTestFailNoAliasMangled = "_Z20EXPECTEDF
* Constructor
*/
PointerAnalysis::PointerAnalysis(SVFIR* p, PTATY ty, bool alias_check) :
svfMod(nullptr),ptaTy(ty),stat(nullptr),ptaCallGraph(nullptr),callGraphSCC(nullptr),icfg(nullptr),chgraph(nullptr),typeSystem(nullptr)
svfMod(nullptr),ptaTy(ty),stat(nullptr),ptaCallGraph(nullptr),callGraphSCC(nullptr),icfg(nullptr),chgraph(nullptr)
{
pag = p;
OnTheFlyIterBudgetForStat = Options::StatBudget();
Expand Down
28 changes: 19 additions & 9 deletions svf/lib/Util/PTAStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ using namespace SVF;
using namespace std;

PTAStat::PTAStat(PointerAnalysis* p) : SVFStat(),
pta(p),
_vmrssUsageBefore(0),
_vmrssUsageAfter(0),
_vmsizeUsageBefore(0),
_vmsizeUsageAfter(0)
pta(p),
_vmrssUsageBefore(0),
_vmrssUsageAfter(0),
_vmsizeUsageBefore(0),
_vmsizeUsageAfter(0)
{
u32_t vmrss = 0;
u32_t vmsize = 0;
Expand All @@ -51,10 +51,11 @@ PTAStat::PTAStat(PointerAnalysis* p) : SVFStat(),

void PTAStat::performStat()
{
callgraphStat();

SVFStat::performStat();

callgraphStat();

SVFIR* pag = SVFIR::getPAG();
for(SVFIR::iterator it = pag->begin(), eit = pag->end(); it!=eit; ++it)
{
Expand All @@ -73,8 +74,8 @@ void PTAStat::performStat()
u32_t vmsize = 0;
SVFUtil::getMemoryUsageKB(&vmrss, &vmsize);
setMemUsageAfter(vmrss, vmsize);
PTNumStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
PTNumStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;
timeStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
timeStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;
}

void PTAStat::callgraphStat()
Expand Down Expand Up @@ -128,7 +129,16 @@ void PTAStat::callgraphStat()
PTNumStatMap["TotalEdge"] = totalEdge;
PTNumStatMap["CalRetPairInCycle"] = edgeInCycle;

SVFStat::printStat("CallGraph Stats");
if(pta->getAnalysisTy() >= PointerAnalysis::PTATY::Andersen_BASE && pta->getAnalysisTy() <= PointerAnalysis::PTATY::Steensgaard_WPA)
SVFStat::printStat("CallGraph Stats (Andersen analysis)");
else if(pta->getAnalysisTy() >= PointerAnalysis::PTATY::FSDATAFLOW_WPA && pta->getAnalysisTy() <= PointerAnalysis::PTATY::FSCS_WPA)
SVFStat::printStat("CallGraph Stats (Flow-sensitive analysis)");
else if(pta->getAnalysisTy() >= PointerAnalysis::PTATY::CFLFICI_WPA && pta->getAnalysisTy() <= PointerAnalysis::PTATY::CFLFSCS_WPA)
SVFStat::printStat("CallGraph Stats (CFL-R analysis)");
else if(pta->getAnalysisTy() >= PointerAnalysis::PTATY::FieldS_DDA && pta->getAnalysisTy() <= PointerAnalysis::PTATY::Cxt_DDA)
SVFStat::printStat("CallGraph Stats (DDA analysis)");
else
SVFStat::printStat("CallGraph Stats");

delete callgraphSCC;
}
16 changes: 13 additions & 3 deletions svf/lib/Util/SVFStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace std;
double SVFStat::timeOfBuildingLLVMModule = 0;
double SVFStat::timeOfBuildingSVFIR = 0;
double SVFStat::timeOfBuildingSymbolTable = 0;

bool SVFStat::printGeneralStats = true;

SVFStat::SVFStat() : startTime(0), endTime(0)
{
Expand Down Expand Up @@ -77,23 +77,28 @@ void SVFStat::printStat(string statname)
SVFUtil::outs() << "################ (program : " << moduleName << ")###############\n";
SVFUtil::outs().flags(std::ios::left);
unsigned field_width = 20;

for(NUMStatMap::iterator it = generalNumMap.begin(), eit = generalNumMap.end(); it!=eit; ++it)
{
// format out put with width 20 space
std::cout << std::setw(field_width) << it->first << it->second << "\n";
}
SVFUtil::outs() << "-------------------------------------------------------\n";

if(!timeStatMap.empty())
SVFUtil::outs() << "----------------Time and memory stats--------------------\n";
for(TIMEStatMap::iterator it = timeStatMap.begin(), eit = timeStatMap.end(); it!=eit; ++it)
{
// format out put with width 20 space
SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
}

if(!PTNumStatMap.empty())
SVFUtil::outs() << "----------------Numbers stats----------------------------\n";
for(NUMStatMap::iterator it = PTNumStatMap.begin(), eit = PTNumStatMap.end(); it!=eit; ++it)
{
// format out put with width 20 space
SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
}

SVFUtil::outs() << "#######################################################" << std::endl;
SVFUtil::outs().flush();
generalNumMap.clear();
Expand All @@ -104,6 +109,10 @@ void SVFStat::printStat(string statname)
void SVFStat::performStat()
{

/// SVF's general statistics are only printed once even if you run multiple anayses
if(printGeneralStats == false)
return;

SVFIR* pag = SVFIR::getPAG();
u32_t numOfFunction = 0;
u32_t numOfGlobal = 0;
Expand Down Expand Up @@ -199,6 +208,7 @@ void SVFStat::performStat()

printStat("General Stats");

printGeneralStats = false;
}


Expand Down
11 changes: 3 additions & 8 deletions svf/lib/WPA/AndersenStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ void AndersenStat::constraintGraphStat()


PTNumStatMap["NumOfCGNode"] = totalNodeNumber;
PTNumStatMap["TotalValidNode"] = cgNodeNumber;
PTNumStatMap["TotalValidObjNode"] = objNodeNumber;
PTNumStatMap["NumOfValidNode"] = cgNodeNumber;
PTNumStatMap["NumOfValidObjNode"] = objNodeNumber;
PTNumStatMap["NumOfCGEdge"] = consCG->getLoadCGEdges().size() + consCG->getStoreCGEdges().size()
+ numOfCopys + numOfGeps;
PTNumStatMap["NumOfAddrs"] = consCG->getAddrCGEdges().size();
Expand All @@ -196,15 +196,13 @@ void AndersenStat::constraintGraphStat()
PTNumStatMap["MaxOutLoadEdge"] = loadmaxOut;
PTNumStatMap["MaxInStoreEdge"] = storemaxIn;
PTNumStatMap["MaxOutStoreEdge"] = storemaxOut;
PTNumStatMap["AvgIn/OutStoreEdge"] = storeavgIn;
PTNumStatMap["MaxInAddrEdge"] = addrmaxIn;
PTNumStatMap["MaxOutAddrEdge"] = addrmaxOut;
timeStatMap["AvgIn/OutStoreEdge"] = storeavgIn;
timeStatMap["AvgIn/OutCopyEdge"] = copyavgIn;
timeStatMap["AvgIn/OutLoadEdge"] = loadavgIn;
timeStatMap["AvgIn/OutAddrEdge"] = addravgIn;
timeStatMap["AvgIn/OutEdge"] = avgIn;

PTAStat::printStat("Constraint Graph Stats");
}
/*!
* Stat null pointers
Expand Down Expand Up @@ -352,9 +350,6 @@ void AndersenStat::performStat()
PTNumStatMap["PointsToConstPtr"] = _NumOfConstantPtr;
PTNumStatMap["PointsToBlkPtr"] = _NumOfBlackholePtr;

PTNumStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
PTNumStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;

PTAStat::printStat("Andersen Pointer Analysis Stats");
}

3 changes: 1 addition & 2 deletions svf/lib/WPA/FlowSensitiveStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ void FlowSensitiveStat::performStat()
timeStatMap["AverageSCCSize"] = (fspta->numOfSCC == 0) ? 0 :
((double)fspta->numOfNodesInSCC / fspta->numOfSCC);

SVFUtil::outs() << "\n****Flow-Sensitive Pointer Analysis Statistics****\n";
PTAStat::printStat();
PTAStat::printStat("Flow-Sensitive Pointer Analysis Statistics");
}

void FlowSensitiveStat::statNullPtr()
Expand Down
3 changes: 1 addition & 2 deletions svf/lib/WPA/VersionedFlowSensitiveStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ void VersionedFlowSensitiveStat::performStat()
timeStatMap["AverageSCCSize"] = (vfspta->numOfSCC == 0) ? 0 :
((double)vfspta->numOfNodesInSCC / vfspta->numOfSCC);

SVFUtil::outs() << "\n****Versioned Flow-Sensitive Pointer Analysis Statistics****\n";
PTAStat::printStat();
PTAStat::printStat("Versioned Flow-Sensitive Pointer Analysis Statistics");
}

void VersionedFlowSensitiveStat::versionStat(void)
Expand Down

0 comments on commit bccd2da

Please sign in to comment.