forked from kaigai/pg_strom
/
debug.c
137 lines (122 loc) · 3.03 KB
/
debug.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
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
/*
* debug.c
*
* Various debugging stuff of PG-Strom
* ----
* Copyright 2011-2014 (C) KaiGai Kohei <kaigai@kaigai.gr.jp>
* Copyright 2014 (C) The PG-Strom Development Team
*
* This software is an extension of PostgreSQL; You can use, copy,
* modify or distribute it under the terms of 'LICENSE' included
* within this package.
*/
#include "postgres.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "pg_strom.h"
bool pgstrom_kernel_debug;
/*
* pgstrom_dump_kernel_debug
*
* It dumps all the debug message during kernel execution, if any.
*/
void
pgstrom_dump_kernel_debug(int elevel, kern_resultbuf *kresult)
{
kern_debug *kdebug;
char *baseptr;
cl_uint i, j, offset = 0;
if (kresult->debug_usage == KERN_DEBUG_UNAVAILABLE ||
kresult->debug_nums == 0)
return;
baseptr = (char *)&kresult->results[kresult->nrooms];
for (i=0; i < kresult->debug_nums; i++)
{
char buf[1024];
kdebug = (kern_debug *)(baseptr + offset);
j = snprintf(buf, sizeof(buf),
"Global(%u/%u+%u) Local (%u/%u) %s = ",
kdebug->global_id,
kdebug->global_sz,
kdebug->global_ofs,
kdebug->local_id,
kdebug->local_sz,
kdebug->label);
switch (kdebug->v_class)
{
case 'c':
snprintf(buf + j, sizeof(buf) - j, "%hhd",
(cl_char)(kdebug->value.v_int & 0x000000ff));
break;
case 's':
snprintf(buf + j, sizeof(buf) - j, "%hd",
(cl_short)(kdebug->value.v_int & 0x0000ffff));
break;
case 'i':
snprintf(buf + j, sizeof(buf) - j, "%d",
(cl_int)(kdebug->value.v_int & 0xffffffff));
break;
case 'l':
snprintf(buf + j, sizeof(buf) - j, "%ld",
(cl_long)kdebug->value.v_int);
break;
case 'f':
case 'd':
snprintf(buf + j, sizeof(buf) - j, "%f",
(cl_double)kdebug->value.v_fp);
break;
default:
snprintf(buf + j, sizeof(buf) - j,
"0x%016lx (unknown class)", kdebug->value.v_int);
break;
}
elog(elevel, "kdebug: %s", buf);
offset += kdebug->length;
}
}
/*
* Debugging facilities for shmem.c
*/
Datum
pgstrom_shmem_alloc_func(PG_FUNCTION_ARGS)
{
#ifdef PGSTROM_DEBUG
Size size = PG_GETARG_INT64(0);
void *address;
address = pgstrom_shmem_alloc(size);
PG_RETURN_INT64((Size) address);
#else
elog(ERROR, "%s is not implemented for production release", __FUNCTION__);
PG_RETURN_NULL();
#endif
}
PG_FUNCTION_INFO_V1(pgstrom_shmem_alloc_func);
Datum
pgstrom_shmem_free_func(PG_FUNCTION_ARGS)
{
#ifdef PGSTROM_DEBUG
void *address = (void *) PG_GETARG_INT64(0);
pgstrom_shmem_free(address);
PG_RETURN_BOOL(true);
#else
elog(ERROR, "%s is not implemented for production release", __FUNCTION__);
PG_RETURN_NULL();
#endif
}
PG_FUNCTION_INFO_V1(pgstrom_shmem_free_func);
/*
* initialization of debugging facilities
*/
void
pgstrom_init_debug(void)
{
/* turn on/off kernel device debug support */
DefineCustomBoolVariable("pg_strom.kernel_debug",
"turn on/off kernel debug support",
NULL,
&pgstrom_kernel_debug,
false,
PGC_SUSET,
GUC_NOT_IN_SAMPLE,
NULL, NULL, NULL);
}