-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathcoverageTracker.h
More file actions
89 lines (76 loc) · 2.21 KB
/
coverageTracker.h
File metadata and controls
89 lines (76 loc) · 2.21 KB
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
#ifndef VSHARP_COVERAGEINSTRUMENTER_COVERAGETRACKER_H
#define VSHARP_COVERAGEINSTRUMENTER_COVERAGETRACKER_H
#include "logging.h"
#include "memory.h"
#include "threadTracker.h"
#include <vector>
#include <algorithm>
#include <mutex>
namespace vsharp {
enum CoverageEvent {
EnterMain,
Enter,
LeaveMain,
Leave,
BranchHit,
Call,
Tailcall,
TrackCoverage,
StsfldHit,
ThrowLeave,
};
struct MethodInfo {
mdMethodDef token;
ULONG assemblyNameLength;
WCHAR *assemblyName;
ULONG moduleNameLength;
WCHAR *moduleName;
std::string methodName;
void serialize(std::vector<char>& buffer) const;
// frees previously allocated resources for it; the object is not supposed to be used afterwards
void Dispose();
};
struct CoverageRecord {
OFFSET offset;
CoverageEvent event;
ThreadID thread;
int methodId;
long long timestamp;
void serialize(std::vector<char>& buffer) const;
};
class CoverageHistory {
private:
std::vector<CoverageRecord*> records{};
public:
explicit CoverageHistory(OFFSET offset, int methodId);
void addCoverage(OFFSET offset, CoverageEvent event, int methodId);
void serialize(std::vector<char>& buffer) const;
~CoverageHistory();
std::set<int> visitedMethods;
};
class CoverageTracker {
private:
bool collectMainOnly;
std::mutex visitedMethodsMutex;
std::set<int> visitedMethods;
ThreadStorage<CoverageHistory*>* trackedCoverage;
ThreadTracker* threadTracker;
std::mutex serializedCoverageMutex;
std::vector<int> serializedCoverageThreadIds;
std::vector<std::vector<char>> serializedCoverage;
std::mutex collectedMethodsMutex;
std::vector<MethodInfo> collectedMethods;
public:
explicit CoverageTracker(ThreadTracker* threadTracker, ThreadInfo* threadInfo, bool collectMainOnly);
bool isCollectMainOnly() const;
void addCoverage(OFFSET offset, CoverageEvent event, int methodId);
void invocationAborted();
void invocationFinished();
size_t collectMethod(MethodInfo info);
char* serializeCoverageReport(size_t* size);
void clear();
void printMethodDebug(int methodId);
~CoverageTracker();
};
}
#endif //VSHARP_COVERAGEINSTRUMENTER_COVERAGETRACKER_H