-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_parsing.c
70 lines (52 loc) · 1.61 KB
/
trace_parsing.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
#include "postgres.h"
#include <time.h>
#include "trace_lock_on_buffers.h"
#include "trace_session.h"
#include "trace_file.h"
#include "trace_parsing.h"
typedef struct ParsingTrace
{
uint64 startTime;
} ParsingTrace;
static ParsingTrace parsingTrace = {.startTime = 0};
static void ParsingTraceInFunc(void* data);
static void ParsingTraceRetFunc(void* data);
static void ParsingTraceCleanFunc(UprobeAttachInterface* uprobe);
static void
ParsingTraceInFunc(void* data)
{
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
parsingTrace.startTime = time.tv_sec * 1000000000L + time.tv_nsec;
LockOnBuffersTraceStatPush();
}
static void
ParsingTraceRetFunc(void* data)
{
struct timespec time;
uint64 timeDiff;
clock_gettime(CLOCK_MONOTONIC, &time);
timeDiff = time.tv_sec * 1000000000L + time.tv_nsec - parsingTrace.startTime;
if (writeMode == TEXT_WRITE_MODE)
TracePrintf("TRACE PARSE. parsingTime %lu nanosec\n", timeDiff);
else
TracePrintf("{\n\"parsingTime\": \"%lu nanosec\",\n", timeDiff);
LockOnBuffersTraceDumpCurrentStatWithPrefix("Buffer locks usage for parsing", "LWLockParsing");
LockOnBuffersTraceStatPop();
}
static void
ParsingTraceCleanFunc(UprobeAttachInterface* uprobe)
{
pfree(uprobe);
}
UprobeAttachInterface*
ParsingUprobeGet(void)
{
UprobeAttachInterface* res = (UprobeAttachInterface*) palloc0(sizeof(UprobeAttachInterface));
res->cleanFunc = ParsingTraceCleanFunc;
res->inFunc = ParsingTraceInFunc;
res->numArgs = 0;
res->retFunc = ParsingTraceRetFunc;
res->targetSymbol = "raw_parser";
return res;
}