summaryrefslogtreecommitdiff
path: root/src/odin.h
blob: dac8e55df58ae20b193fddc61f7cada06b37f887 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
   This file is part of odin, a memory profiler with fragmentation analysis.

   Copyright (C) 2007 Chris Wilson <chris@chris-wilson.co.uk>

   odin is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 3 of the
   License, or (at your option) any later version.

   odin is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with odin. If not, see <http://www.gnu.org/licenses/>/

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef ODIN_H
#define ODIN_H

#include <gtk/gtk.h>

G_BEGIN_DECLS

#define NUM_CALLERS 12

typedef struct _app App;
typedef struct _client Client;
typedef struct _allocator Allocator;
typedef struct _allocator_time AllocatorTime;
typedef struct _block Block;
typedef struct _chunk Chunk;
typedef struct _thread_faults ThreadFaults;

typedef struct _frame Frame;
typedef struct _frames Frames;

typedef struct _shared_object SharedObject;
typedef struct _shared_objects SharedObjects;

typedef struct _allocators Allocators;
typedef struct _block_map BlockMap;
typedef struct _call_graph CallGraph;
typedef struct _procmap Procmap;
typedef struct _summary Summary;
typedef struct _timeline Timeline;
typedef struct _spacetime Spacetime;

typedef struct _call_graph_frame CallGraphFrame;
typedef struct _call_graph_store CallGraphStore;
typedef struct _call_graph_store_class CallGraphStoreClass;


struct _block {
    Block *next, *ht_next;
    Block *prev, *ht_prev;
    gulong addr;
    gsize size;
    guint age;
    Allocator *allocator;
};

struct _chunk {
    struct _chunk *next;
    guint used, size;
    gchar mem[0];
};

struct _thread_faults {
    guint tid;
    guint fault_cnt;
    guint n_faults;
    ThreadFaults *next;
};

struct _allocator {
    gulong key;
    Allocator *next, *ht_next;
    guint n_frames;
    Frame **frames;
    const gchar *alloc_fn;
    guint alloc_fn_serial;
    guint64 max_bytes;
    struct _allocator_time {
	guint time;
	guint64 bytes;
	guint64 freed;
	gsize max_size;
	guint size_allocs[32];
	guint max_size_alloc;
	guint n_allocs;
	guint n_reallocs;
	guint n_frees;
	guint n_realloced_blocks;
	guint peak_blocks;
	gsize peak_bytes;
	ThreadFaults faults;
	AllocatorTime *next, *prev;
    } time[1];
    AllocatorTime *time_tail;
};

typedef enum {
    ALLOC,
    REALLOC,
    DEALLOC
} EventType;

typedef struct _event_base {
    EventType type;
    guint time;
    guint tid;
    Allocator *allocator;
} EventBase;

typedef struct _event_alloc {
    EventType type;
    guint time;
    guint tid;
    Allocator *allocator;

    gulong addr;
    gsize size;
} EventAlloc;

typedef struct _event_realloc {
    EventType type;
    guint time;
    guint tid;
    Allocator *allocator;

    gulong old_addr;
    gsize old_size;
    gulong new_addr;
    gsize new_size;
} EventRealloc;

typedef struct _event_dealloc {
    EventType type;
    guint time;
    guint tid;
    Allocator *allocator;

    gulong addr;
    gsize size;
} EventDealloc;

typedef union _event {
    EventType type;
    EventBase base;
    EventAlloc alloc;
    EventRealloc realloc;
    EventDealloc dealloc;
} Event;


App *
app_get (GtkWidget *widget);

void
app_set_busy (App *app, gboolean busy);

gboolean
app_add_alloc_fn (App *app, const gchar *pattern, GError **error);

gboolean
app_is_alloc_fn (App *app, Frame *f);

guint
app_get_alloc_fns_serial (App *app);

const gchar *
app_get_main_function (App *app);

guint
app_get_number_of_frames (App *app);

guint
app_get_number_of_allocators (App *app);

guint
app_get_number_of_blocks (App *app);

GtkWidget *
block_map_new (void);

void
block_map_set_highlight (BlockMap *block_map, GSList *blocks);

GtkWidget *
timeline_new (void);

void
timeline_reset (Timeline *tl);

void
timeline_add_datum (Timeline *tl, Client *client, guint time, Allocator *A);

GtkWidget *
spacetime_new (void);

void
spacetime_reset (Spacetime *st);

void
spacetime_add_datum (Spacetime *st, Client *client, guint time, Allocator *A);

GtkWidget *
allocators_new (void);

void
allocators_reset (Allocators *allocators);

GSList *
allocators_get_blocks_for_iter (Allocators *self,
	                        GtkTreeIter *iter,
				GSList *blocks);

void
allocators_select_blocks (Allocators *self, GSList *blocks);

gboolean
allocators_add_alloc_fn (Allocators *self,
	                 const gchar *pattern,
			 GError **error);

GtkWidget *
call_graph_new (void);

void
call_graph_update_view (CallGraph *self);

GtkWidget *
call_graph_tree_map_new (void);

GtkWidget *
call_graph_ring_new (void);

GtkWidget *
procmap_new (void);

G_CONST_RETURN Event *
app_find_prev_event_for_addr_range (App *app, guint time, gulong min, gulong max);

GtkWidget *
summary_new (gboolean total);

void
summary_update (Summary *summary, Client *client);

void
pretty_print_number (const char *number, gint len, char *output);

void
cell_layout_pretty_print_uint (GtkCellLayout   *layout,
	                       GtkCellRenderer *cell,
			       GtkTreeModel    *model,
			       GtkTreeIter     *iter,
			       gpointer         data);

void
cell_layout_pretty_print_uint64 (GtkCellLayout   *layout,
	                         GtkCellRenderer *cell,
				 GtkTreeModel    *model,
				 GtkTreeIter     *iter,
				 gpointer         data);

void
hsv_to_rgb (gdouble h, gdouble s, gdouble v, gdouble *rgb);

gdouble
median_double (gdouble *v, guint n);

G_END_DECLS

#endif /* ODIN_H */