-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuprobe_factory.c
112 lines (90 loc) · 2.45 KB
/
uprobe_factory.c
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
#include "postgres.h"
#include "count_uprobes.h"
#include "lockmanager_trace.h"
#include "uprobe_factory.h"
#define UNVALIDTYPESTR "INVALID_TYPE"
typedef struct UprobeFactoryEntry
{
StorageInitFunc storageInit;
UprobeInterfaceInitFunc interfaceInit;
UprobeAttachType type;
char* stringtype;
} UprobeFactoryEntry;
UprobeFactoryEntry staticEntries [] = {
{
.interfaceInit = UprobeAttachTimeInit,
.storageInit = UprobeStorageTimeInit,
.type = TIME,
.stringtype = "TIME"
},
{
.interfaceInit = UprobeAttachHistInit,
.storageInit = UprobeStorageHistInit,
.type = HIST,
.stringtype = "HIST"
},
{
.interfaceInit = UprobeAttachMemInit,
.storageInit = UprobeStorageMemInit,
.type = MEM,
.stringtype = "MEM"
},
{
.interfaceInit = LWLockAcquireInit,
.storageInit = NullStorageInit,
.type = LOCK_ACQUIRE,
.stringtype ="LOCK_ACQUIRE"
},
{
.interfaceInit = LWLockReleaseInit,
.storageInit = LockManagerStorageInit,
.type = LOCK_RELEASE,
.stringtype = "LOCK_RELEASE"
}
};
#define STATIC_ENTRIES_SIZE sizeof(staticEntries) / sizeof(staticEntries[0])
void
CreateUprobeAttachForType(const char* type, const char* symbol, UprobeAttach* uprobeAttach)
{
for (size_t i = 0; i < STATIC_ENTRIES_SIZE; i++)
{
if (strcmp(type, staticEntries[i].stringtype) == 0)
{
uprobeAttach->type = staticEntries[i].type;
uprobeAttach->impl = staticEntries[i].interfaceInit(symbol);
return;
}
}
uprobeAttach->type = INVALID_TYPE;
uprobeAttach->impl = NULL;
}
const char*
GetCharNameForUprobeAttachType(UprobeAttachType type)
{
for (size_t i = 0; i < STATIC_ENTRIES_SIZE; i++)
{
if (type == staticEntries[i].type)
return staticEntries[i].stringtype;
}
return UNVALIDTYPESTR;
}
UprobeStorage*
GetUprobeStorageForType(UprobeAttachType type, const char* symbol)
{
for (size_t i = 0; i < STATIC_ENTRIES_SIZE; i++)
{
if (type == staticEntries[i].type)
return staticEntries[i].storageInit(symbol);
}
return NULL;
}
UprobeAttachType
GetTypeByCharName(const char* name)
{
for (size_t i = 0; i < STATIC_ENTRIES_SIZE; i++)
{
if (strcmp(name, staticEntries[i].stringtype) == 0)
return staticEntries[i].type;
}
return INVALID_TYPE;
}