-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltin-sql.c
95 lines (83 loc) · 2.85 KB
/
builtin-sql.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
/*
Copyright (C) 2013
Baptiste Lepers <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2, as published by the Free Software Foundation.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "parse.h"
#include "builtin-sql.h"
static int nb_obj = 0;
static rbtree tid, oid;
struct ttid {
int tid, pid;
char *app;
};
struct ooid {
int oid, size, alloc_thr;
char *code, *type;
};
void sql_init() {
tid = rbtree_create();
oid = rbtree_create();
printf("BEGIN TRANSACTION;\n");
printf("CREATE TABLE access (target_node NUMERIC, aid NUMERIC, callchain BLOB, cause1 NUMERIC, cause2 NUMERIC, cause3 TEXT, cause4 NUMERIC, distant NUMERIC, function TEXT, latency NUMERIC, mode TEXT, node NUMERIC, oid NUMERIC, tid NUMERIC);\n");
printf("CREATE TABLE obj (alloc_thread NUMERIC, code_location TEXT, oid NUMERIC, size NUMERIC, type TEXT);\n");
printf("CREATE TABLE thread (app TEXT, pid NUMERIC, tid NUMERIC);\n");
}
static int aid = 0;
void sql_parse(struct s* s) {
struct symbol *ob = get_object(s);
struct dyn_lib* ob3 = sample_to_mmap(s);
char *obj = NULL;
if(ob)
obj = ob->object_name;
if(!obj && ob3)
obj = ob3->name;
struct ooid *o = rbtree_lookup(oid, obj, (compare_func)pointer_cmp);
if(!o) {
o = calloc(1, sizeof(*o));
o->oid = nb_obj++;
o->alloc_thr = ob?ob->allocator_tid:get_pid(s);
o->size = 0;
o->code = obj;
o->type = "nimps";
rbtree_insert(oid, obj, o, (compare_func)pointer_cmp);
printf("INSERT INTO obj VALUES(%d,'%s',%d,%d,'%s');\n",
o->alloc_thr, o->code, o->oid, o->size, o->type
);
}
struct ttid *t = rbtree_lookup(tid, (void*)(long)get_tid(s), (compare_func)pointer_cmp);
if(!t) {
t= calloc(1, sizeof(*t));
t->tid = get_tid(s);
t->pid = get_pid(s);
t->app = s->comm;
rbtree_insert(tid, (void*)(long)get_tid(s), t, (compare_func)pointer_cmp);
printf("INSERT INTO thread VALUES('%s',%d,%d);\n",
t->app, t->pid, t->tid);
}
printf("INSERT INTO access VALUES(%d,%d,'%s',%d,%d,%d,%d,%d,'%s',%d,'%s',%d,%d,%d);\n",
get_addr_node(s),
aid++,
"rien",
0,0,0,0,
is_distant(s),
get_function(s)->function_name,
get_latency(s),
is_kernel(s)?"kernel":"user",
cpu_to_node(s->cpu),
o->oid,
t->tid
);
}
void sql_show() {
printf("COMMIT;\n");
}