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
125
126
127
128
129
130
131
132
133
134
135
136
137
|
// file : data/client.h
// project : Salis-VM
// author : Paul Oliver <contact@pauloliver.dev>
// index:
// [section] macros
// [section] trace declarations
// [section] plot declarations
// ----------------------------------------------------------------------------
// [section] macros
// ----------------------------------------------------------------------------
#define CLIENT_DEFVAL_ENTRIES 0x800l
#define CLIENT_DEFVAL_HM_LEFT 0l
#define CLIENT_DEFVAL_HM_PIXEL_COUNT 0x400l
#define CLIENT_DEFVAL_NTH 1l
#define CLIENT_DEFVAL_X_AXIS 0
#define CLIENT_DEFVAL_X_HIGH INT64_MAX
#define CLIENT_DEFVAL_X_LOW 0l
// Client implementation must define this.
// Server implementation must not (as it's C not C++).
#if defined(CLIENT_DECLARE_TRACES_AND_PLOTS)
// ----------------------------------------------------------------------------
// [section] trace declarations
// ----------------------------------------------------------------------------
struct StringComparator {
bool operator()(const char *a, const char *b) const;
};
template <class T>
struct Trace : public std::vector<T> {
Trace();
virtual ~Trace();
virtual size_t start_offset() const;
virtual void trim();
#if !defined(NDEBUG)
virtual void validate() const;
#endif
void clear();
void push_back(T value);
T *start();
T &operator[](size_t n);
T operator[](size_t n) const;
protected:
void trim_spec(int64_t multiplier = 1);
};
template <class T>
struct TraceNamed : public Trace<T> {
TraceNamed(const char *name, const char *label);
const char *get_name() const;
const char *get_label() const;
private:
const char *m_name;
const char *m_label;
};
template <class T>
struct TraceHeatmap : public TraceNamed<T> {
TraceHeatmap(const char *name, const char *label);
size_t start_offset() const;
void trim();
#if !defined(NDEBUG)
void validate() const;
#endif
};
// ----------------------------------------------------------------------------
// [section] plot declarations
// ----------------------------------------------------------------------------
typedef int (*AxisFormatter)(double value, char *buff, int size, void *data);
struct Plot {
Plot(const char *name, const char *section);
virtual ~Plot();
virtual void handle_input(int key, int mods);
virtual void flag_for_reset();
const char *get_name() const;
const char *get_section() const;
void render(const ImVec2 &frame_size);
bool m_visible;
private:
static int hex_formatter(double value, char *buff, int size, void *data);
virtual AxisFormatter x_formatter() const;
virtual AxisFormatter y_formatter() const;
virtual float right_margin() const;
virtual int flags() const;
virtual void render_internal(const ImVec2 &frame_size) = 0;
virtual void render_post(const ImVec2 &frame_size);
const char *m_name;
const char *m_section;
};
struct PlotLines : public Plot {
PlotLines(const char *name, const char *section, std::vector<const char *> trace_keys);
private:
void render_internal(const ImVec2 &frame_size);
std::vector<const char *> m_trace_keys;
};
struct PlotStacked : public Plot {
PlotStacked(const char *name, const char *section, std::vector<const char *> trace_keys);
void flag_for_reset();
private:
static int percent_formatter(double value, char *buff, int size, void *data);
AxisFormatter y_formatter() const;
void render_internal(const ImVec2 &frame_size);
std::vector<const char *> m_trace_keys;
std::vector<bool> m_trace_states;
Trace<ImS64> m_trace_totals;
std::vector<Trace<double>> m_trace_normals;
bool m_needs_reset;
};
struct PlotHeatmap : public Plot {
PlotHeatmap(const char *name, const char *section, const char *trace_key);
void handle_input(int key, int mods);
void flag_for_reset();
private:
float right_margin() const;
int flags() const;
void render_internal(const ImVec2 &frame_size);
void render_end(const ImVec2 &frame_size);
void render_post(const ImVec2 &frame_size);
const char *m_trace_key;
float m_tex_scale_pow;
float m_tex_scale_high;
size_t m_tex_rendered_last;
size_t m_rows_rendered;
GLuint m_tex_id;
std::vector<uint8_t> m_tex_render;
bool m_needs_reset;
};
#endif
|