-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrumentation_context.h
59 lines (48 loc) · 1.64 KB
/
instrumentation_context.h
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
#pragma once
extern "C" {
#include "postgres.h"
}
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
struct PgObject
{
const void *id;
std::string data; // Serialized object data
const void *parent = nullptr; // Logical parent:
// Path -> RelOptInfo -> PlannerInfo
Oid oid = InvalidOid; // (RelOptInfo) relation's OID
bool isChosen = false; // (Path) was used to build a plan
std::vector<const void *> backtrace;
PgObject(const void *id_, const char *data_): id(id_), data(data_) {}
};
struct InstrumentationContext
{
std::unordered_map<const void *, size_t> samples_index;
std::vector<PgObject> samples;
std::unordered_set<Oid> types;
std::unordered_set<Oid> functions;
std::unordered_set<Oid> operators;
};
void clear_instrumentation_context(InstrumentationContext &ic);
std::unique_ptr<InstrumentationContext>
create_instrumentation_context();
void make_report(std::ostream &os, const InstrumentationContext &ic);
std::string submit_report(const InstrumentationContext &ic, const char *url);
inline void clear_instrumentation_context(InstrumentationContext &ic)
{
ic.samples_index.clear();
ic.samples.clear();
ic.types.clear();
ic.functions.clear();
ic.operators.clear();
}
inline std::unique_ptr<InstrumentationContext>
create_instrumentation_context()
{
auto ic = std::make_unique<InstrumentationContext>();
return ic;
}