Static Value-Flow Analysis
Loading...
Searching...
No Matches
AEStat.cpp
Go to the documentation of this file.
1//===- AEStat.cpp -- Statistics for Abstract Execution----------//
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#include "AE/Svfexe/AEStat.h"
25#include "SVFIR/SVFIR.h"
26
27using namespace SVF;
28using namespace SVFUtil;
29
30// count the size of memory map
32{
33 if (count == 0)
34 {
35 generalNumMap["ES_Var_AVG_Num"] = 0;
36 generalNumMap["ES_Loc_AVG_Num"] = 0;
37 generalNumMap["ES_Var_Addr_AVG_Num"] = 0;
38 generalNumMap["ES_Loc_Addr_AVG_Num"] = 0;
39 }
40 ++count;
41}
42
44{
46 if (count > 0)
47 {
48 generalNumMap["ES_Var_AVG_Num"] /= count;
49 generalNumMap["ES_Loc_AVG_Num"] /= count;
50 generalNumMap["ES_Var_Addr_AVG_Num"] /= count;
51 generalNumMap["ES_Loc_Addr_AVG_Num"] /= count;
52 }
53 generalNumMap["SVF_STMT_NUM"] = count;
54
56 generalNumMap["ICFG_Node_Num"] = totalICFGNodes;
57
58 // Calculate coverage: use allAnalyzedNodes which tracks all nodes across all entry points
60 generalNumMap["Analyzed_ICFG_Node_Num"] = analyzedNodes;
61
62 // Coverage percentage (stored as integer percentage * 100 for precision)
63 if (totalICFGNodes > 0)
64 {
65 double coveragePercent = (double)analyzedNodes / (double)totalICFGNodes * 100.0;
66 generalNumMap["ICFG_Coverage_Percent"] = (u32_t)(coveragePercent * 100); // Store as percentage * 100
67 }
68 else
69 {
70 generalNumMap["ICFG_Coverage_Percent"] = 0;
71 }
72
77 for (const auto &it: *_ae->svfir->getICFG())
78 {
79 if (it.second->getFun())
80 {
81 funs.insert(it.second->getFun());
82 // Check if this node was analyzed (across all entry points)
83 if (_ae->allAnalyzedNodes.find(it.second) != _ae->allAnalyzedNodes.end())
84 {
85 analyzedFuns.insert(it.second->getFun());
86 }
87 }
89 {
90 if (!isExtCall(callNode))
91 {
93 }
94 else
95 {
97 }
98 }
99 }
100 generalNumMap["Func_Num"] = funs.size();
101 generalNumMap["Analyzed_Func_Num"] = analyzedFuns.size();
102
103 // Function coverage percentage
104 if (funs.size() > 0)
105 {
106 double funcCoveragePercent = (double)analyzedFuns.size() / (double)funs.size() * 100.0;
107 generalNumMap["Func_Coverage_Percent"] = (u32_t)(funcCoveragePercent * 100); // Store as percentage * 100
108 }
109 else
110 {
111 generalNumMap["Func_Coverage_Percent"] = 0;
112 }
113
114 generalNumMap["EXT_CallSite_Num"] = extCallSiteNum;
115 generalNumMap["NonEXT_CallSite_Num"] = callSiteNum;
116 timeStatMap["Total_Time(sec)"] = (double)(endTime - startTime) / TIMEINTERVAL;
117
118}
119
121{
122 std::string fullName(_ae->moduleName);
123 std::string name;
124 std::string moduleName;
125 if (fullName.find('/') == std::string::npos)
126 {
127 std::string name = fullName;
128 moduleName = name.substr(0, fullName.find('.'));
129 }
130 else
131 {
132 std::string name = fullName.substr(fullName.find('/'), fullName.size());
133 moduleName = name.substr(0, fullName.find('.'));
134 }
135
136 SVFUtil::outs() << "\n************************\n";
137 SVFUtil::outs() << "################ (program : " << moduleName << ")###############\n";
138 SVFUtil::outs().flags(std::ios::left);
139 unsigned field_width = 30;
140 for (NUMStatMap::iterator it = generalNumMap.begin(), eit = generalNumMap.end(); it != eit; ++it)
141 {
142 // Special handling for percentage fields (stored as percentage * 100)
143 if (it->first == "ICFG_Coverage_Percent" || it->first == "Func_Coverage_Percent")
144 {
145 double percent = (double)it->second / 100.0;
146 std::cout << std::setw(field_width) << it->first << std::fixed << std::setprecision(2) << percent << "%\n";
147 }
148 else
149 {
150 std::cout << std::setw(field_width) << it->first << it->second << "\n";
151 }
152 }
153 SVFUtil::outs() << "-------------------------------------------------------\n";
154 for (TIMEStatMap::iterator it = timeStatMap.begin(), eit = timeStatMap.end(); it != eit; ++it)
155 {
156 // format out put with width 20 space
157 SVFUtil::outs() << std::setw(field_width) << it->first << it->second << "\n";
158 }
159 SVFUtil::outs() << "Memory usage: " << memUsage << "\n";
160
161 SVFUtil::outs() << "#######################################################" << std::endl;
162 SVFUtil::outs().flush();
163}
#define TIMEINTERVAL
Definition SVFType.h:621
const char *const name
Definition cJSON.h:264
s32_t count
Definition AEStat.h:57
std::string memUsage
Definition AEStat.h:59
void finializeStat()
Definition AEStat.cpp:43
void performStat() override
Definition AEStat.cpp:120
std::string getMemUsage()
Definition AEStat.h:46
void countStateSize()
Definition AEStat.cpp:31
AbstractInterpretation * _ae
Definition AEStat.h:56
SVFIR * svfir
protected data members, also used in subclasses
Set< const ICFGNode * > allAnalyzedNodes
u32_t nodeNum
total num of edge
ICFG * getICFG() const
Definition SVFIR.h:227
NUMStatMap generalNumMap
Definition SVFStat.h:76
std::string moduleName
Definition SVFStat.h:99
TIMEStatMap timeStatMap
Definition SVFStat.h:78
double endTime
Definition SVFStat.h:81
double startTime
Definition SVFStat.h:80
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:437
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:47