Static Value-Flow Analysis
Loading...
Searching...
No Matches
PTAStat.cpp
Go to the documentation of this file.
1//===- PTAStat.cpp -- Base class for statistics in SVF-----------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23/*
24 * PTAStat.cpp
25 *
26 * Created on: Oct 13, 2013
27 * Author: Yulei Sui
28 */
29
30#include <iomanip>
31#include "Graphs/PTACallGraph.h"
32#include "Util/PTAStat.h"
34#include "SVFIR/SVFIR.h"
35
36using namespace SVF;
37using namespace std;
38
40 pta(p),
41 _vmrssUsageBefore(0),
42 _vmrssUsageAfter(0),
43 _vmsizeUsageBefore(0),
44 _vmsizeUsageAfter(0)
45{
46 u32_t vmrss = 0;
47 u32_t vmsize = 0;
50}
51
53{
54
56
58
59 SVFIR* pag = SVFIR::getPAG();
60 for(SVFIR::iterator it = pag->begin(), eit = pag->end(); it!=eit; ++it)
61 {
62 PAGNode* node = it->second;
63 if(SVFUtil::isa<ObjVar>(node))
64 {
66 {
68 }
69 }
70 }
71 PTNumStatMap["LocalVarInRecur"] = localVarInRecursion.count();
72
73 u32_t vmrss = 0;
74 u32_t vmsize = 0;
77 timeStatMap["MemoryUsageVmrss"] = _vmrssUsageAfter - _vmrssUsageBefore;
78 timeStatMap["MemoryUsageVmsize"] = _vmsizeUsageAfter - _vmsizeUsageBefore;
79}
80
82{
83
84 PTACallGraph* graph = pta->getCallGraph();
86 callgraphSCC->find();
87
88 unsigned totalNode = 0;
89 unsigned totalCycle = 0;
90 unsigned nodeInCycle = 0;
91 unsigned maxNodeInCycle = 0;
92 unsigned totalEdge = 0;
93 unsigned edgeInCycle = 0;
94
98 for (; it != eit; ++it)
99 {
100 totalNode++;
101 if(callgraphSCC->isInCycle(it->first))
102 {
103 sccRepNodeSet.insert(callgraphSCC->repNode(it->first));
104 nodeInCycle++;
105 const NodeBS& subNodes = callgraphSCC->subNodes(it->first);
106 if(subNodes.count() > maxNodeInCycle)
107 maxNodeInCycle = subNodes.count();
108 }
109
110 PTACallGraphNode::const_iterator edgeIt = it->second->InEdgeBegin();
111 PTACallGraphNode::const_iterator edgeEit = it->second->InEdgeEnd();
112 for (; edgeIt != edgeEit; ++edgeIt)
113 {
115 totalEdge+= edge->getDirectCalls().size() + edge->getIndirectCalls().size();
116 if(callgraphSCC->repNode(edge->getSrcID()) == callgraphSCC->repNode(edge->getDstID()))
117 {
118 edgeInCycle+=edge->getDirectCalls().size() + edge->getIndirectCalls().size();
119 }
120 }
121 }
122
123 totalCycle = sccRepNodeSet.size();
124
125 PTNumStatMap["TotalNode"] = totalNode;
126 PTNumStatMap["TotalCycle"] = totalCycle;
127 PTNumStatMap["NodeInCycle"] = nodeInCycle;
128 PTNumStatMap["MaxNodeInCycle"] = maxNodeInCycle;
129 PTNumStatMap["TotalEdge"] = totalEdge;
130 PTNumStatMap["CalRetPairInCycle"] = edgeInCycle;
131
133 SVFStat::printStat("PTACallGraph Stats (Andersen analysis)");
135 SVFStat::printStat("PTACallGraph Stats (Flow-sensitive analysis)");
137 SVFStat::printStat("PTACallGraph Stats (CFL-R analysis)");
139 SVFStat::printStat("PTACallGraph Stats (DDA analysis)");
140 else
141 SVFStat::printStat("PTACallGraph Stats");
142
143 delete callgraphSCC;
144}
cJSON * p
Definition cJSON.cpp:2559
iterator begin()
Iterators.
IDToNodeMapTy::iterator iterator
Node Iterators.
GEdgeSetTy::const_iterator const_iterator
CallInstSet & getDirectCalls()
void setMemUsageBefore(u32_t vmrss, u32_t vmsize)
Definition PTAStat.h:56
void setMemUsageAfter(u32_t vmrss, u32_t vmsize)
Definition PTAStat.h:62
u32_t _vmsizeUsageBefore
Definition PTAStat.h:77
NodeBS localVarInRecursion
Definition PTAStat.h:54
PointerAnalysis * pta
Definition PTAStat.h:74
u32_t _vmsizeUsageAfter
Definition PTAStat.h:78
u32_t _vmrssUsageAfter
Definition PTAStat.h:76
PTAStat(PointerAnalysis *p)
Definition PTAStat.cpp:39
void performStat() override
Definition PTAStat.cpp:52
u32_t _vmrssUsageBefore
Definition PTAStat.h:75
void callgraphStat() override
Definition PTAStat.cpp:81
@ Cxt_DDA
context sensitive DDA
@ CFLFICI_WPA
Flow-, context-, insensitive CFL-reachability-based analysis.
@ FSCS_WPA
Flow-, context- sensitive WPA.
@ FSDATAFLOW_WPA
Traditional Dataflow-based flow sensitive WPA.
@ Andersen_BASE
Base Andersen PTA.
@ CFLFSCS_WPA
Flow-, context-, CFL-reachability-based analysis.
@ FieldS_DDA
Field sensitive DDA.
@ Steensgaard_WPA
Steensgaard PTA.
bool isLocalVarInRecursiveFun(NodeID id) const
Whether a local variable is in function recursions.
PTACallGraph * getCallGraph() const
Return call graph.
PTATY getAnalysisTy() const
Type of pointer analysis.
SCCDetection< PTACallGraph * > CallGraphSCC
NodeID getId() const
Get ID.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
NUMStatMap PTNumStatMap
Definition SVFStat.h:77
virtual void printStat(std::string str="")
Definition SVFStat.cpp:67
TIMEStatMap timeStatMap
Definition SVFStat.h:78
virtual void performStat()=0
Definition SVFStat.cpp:110
void set(unsigned Idx)
unsigned count() const
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
Definition SVFUtil.cpp:178
for isBitcode
Definition BasicTypes.h:68
Set< NodeID > NodeSet
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46