forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoverTool.cpp
124 lines (86 loc) · 3.08 KB
/
CoverTool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "CoverTool.h"
CoverTool::CoverTool()
{
size_t threads=1;//一个就好了
for (unsigned i = 0; i < threads; ++i)
m_checks.emplace_back([=](){
setThreadName("CoverTool:check" );
this->output();
});
}
CoverTool:: ~CoverTool()
{
// cout<<"~CoverTool"<<endl;
m_aborting = true;
for (auto& i: m_checks)
i.join();
m_checks.clear();
}
bool CoverTool::has(Address address)
{
return m_statitems.find(address) != m_statitems.end() ? true:false;
}
void CoverTool::init(Address address,bytes cspace)
{
//cout<<"CoverTool init"<<endl;
DEV_WRITE_GUARDED(m_lock)
{
//cout<<"address="<<address<<",size="<<cspace.size()<<endl;
if( this->has(address) )
return ;
StatItem s(cspace);
m_statitems.insert(std::pair<Address, StatItem>(address,s) );
}
}
void CoverTool::hint(Address address,size_t index,size_t codespacesize)
{
DEV_WRITE_GUARDED(m_lock)
{
if( this->has(address) )
{
//cout<<"CoverTool hint"<<",index="<<index<<endl;
m_statitems.find(address)->second.hint(index,codespacesize);
}
}
}
void CoverTool::output()
{
while(!m_aborting)
{
DEV_WRITE_GUARDED(m_lock)
{
try
{
uint64_t now=utcTime();
std::map<Address, StatItem>::iterator iter=m_statitems.begin();
for(; iter != m_statitems.end();iter++)
{
if( now - iter->second.lasttime > 600 )//超时就输出
{
std::string message="";//toString(iter->first)+"\n";
//message +="lasttime:"+toString(iter->second.lasttime)+"\n";
//message +="outputtime:"+toString(now)+"\n";
for( size_t i=0;i<iter->second.vectorinfo.size();i++)
{
message +=iter->second.vectorinfo.at(i).opname+"\t";
message +=toString(iter->second.vectorinfo.at(i).hint)+"\n";
}//for
//写文件
if( !m_outputpath.empty() )
writeFile(m_outputpath+toString(iter->first), message, true);
//一天没更新就删除
if( now - iter->second.lasttime > 24*3600*1000 )
m_statitems.erase(iter);
}//if
}//for
}
catch (...)
{
// should not happen as exceptions
LOG(WARNING) << "Bad CoverTool:" << boost::current_exception_diagnostic_information();
m_aborting=true;
}
}
this_thread::sleep_for(std::chrono::milliseconds(10000));
}//while
}//fun