Debian Codegraph @

lib/report.c

raw symbols SCIP
1 /*
2 Copyright(C) 2015-2018 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "grn_report.h"
20
21 const grn_log_level GRN_REPORT_INDEX_LOG_LEVEL = GRN_LOG_INFO;
22
23 void
24 grn_report_index(grn_ctx *ctx,
25 const char *action,
26 const char *tag,
27 grn_obj *index)
28 {
29 char index_name[GRN_TABLE_MAX_KEY_SIZE];
30 int index_name_size;
31
32 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
33 return;
34 }
35
36 index_name_size = grn_obj_name(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZE);
37 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
38 "%s[index]%s <%.*s>",
39 action, tag, index_name_size, index_name);
40 }
41
42 void
43 grn_report_index_not_used(grn_ctx *ctx,
44 const char *action,
45 const char *tag,
46 grn_obj *index,
47 const char *reason)
48 {
49 char index_name[GRN_TABLE_MAX_KEY_SIZE];
50 int index_name_size;
51
52 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
53 return;
54 }
55
56 index_name_size = grn_obj_name(ctx, index, index_name, GRN_TABLE_MAX_KEY_SIZE);
57 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
58 "%s[index-not-used]%s <%.*s>: %s",
59 action, tag, index_name_size, index_name, reason);
60 }
61
62 void
63 grn_report_table(grn_ctx *ctx,
64 const char *action,
65 const char *tag,
66 grn_obj *table)
67 {
68 grn_obj description;
69 grn_obj *target;
70 grn_obj *previous_target = NULL;
71
72 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
73 return;
74 }
75
76 GRN_TEXT_INIT(&description, 0);
77 for (target = table;
78 target;
79 previous_target = target, target = grn_ctx_at(ctx, target->header.domain)) {
80 char name[GRN_TABLE_MAX_KEY_SIZE];
81 int name_size;
82
83 name_size = grn_obj_name(ctx, target, name, GRN_TABLE_MAX_KEY_SIZE);
84 if (GRN_TEXT_LEN(&description) > 0) {
85 GRN_TEXT_PUTS(ctx, &description, " -> ");
86 }
87 if (name_size == 0) {
88 GRN_TEXT_PUTS(ctx, &description, "(temporary)");
89 } else {
90 GRN_TEXT_PUTS(ctx, &description, "<");
91 GRN_TEXT_PUT(ctx, &description, name, name_size);
92 GRN_TEXT_PUTS(ctx, &description, ">");
93 }
94 if (previous_target && previous_target != table) {
95 grn_obj_unref(ctx, previous_target);
96 }
97 }
98 if (previous_target && previous_target != table) {
99 grn_obj_unref(ctx, previous_target);
100 }
101 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
102 "%s[table]%s %.*s",
103 action, tag,
104 (int)GRN_TEXT_LEN(&description),
105 GRN_TEXT_VALUE(&description));
106 GRN_OBJ_FIN(ctx, &description);
107 }
108
109 void
110 grn_report_column(grn_ctx *ctx,
111 const char *action,
112 const char *tag,
113 grn_obj *column)
114 {
115 grn_obj description;
116 grn_obj *target;
117 grn_obj *previous_target = NULL;
118
119 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
120 return;
121 }
122
123 GRN_TEXT_INIT(&description, 0);
124 for (target = column;
125 target;
126 previous_target = target, target = grn_ctx_at(ctx, grn_obj_get_range(ctx, target))) {
127 char name[GRN_TABLE_MAX_KEY_SIZE];
128 int name_size;
129
130 name_size = grn_obj_name(ctx, target, name, GRN_TABLE_MAX_KEY_SIZE);
131 if (GRN_TEXT_LEN(&description) > 0) {
132 GRN_TEXT_PUTS(ctx, &description, " -> ");
133 }
134 if (name_size == 0) {
135 GRN_TEXT_PUTS(ctx, &description, "(temporary)");
136 } else {
137 GRN_TEXT_PUTS(ctx, &description, "<");
138 GRN_TEXT_PUT(ctx, &description, name, name_size);
139 GRN_TEXT_PUTS(ctx, &description, ">");
140 }
141 if (previous_target && previous_target != column) {
142 grn_obj_unref(ctx, previous_target);
143 }
144 }
145 if (previous_target && previous_target != column) {
146 grn_obj_unref(ctx, previous_target);
147 }
148 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
149 "%s[column]%s %.*s",
150 action, tag,
151 (int)GRN_TEXT_LEN(&description),
152 GRN_TEXT_VALUE(&description));
153 GRN_OBJ_FIN(ctx, &description);
154 }
155
156 void
157 grn_report_accessor(grn_ctx *ctx,
158 const char *action,
159 const char *tag,
160 grn_obj *accessor)
161 {
162 grn_obj description;
163 grn_obj *range;
164
165 if (!grn_logger_pass(ctx, GRN_REPORT_INDEX_LOG_LEVEL)) {
166 return;
167 }
168
169 GRN_TEXT_INIT(&description, 0);
170 grn_accessor_name(ctx, accessor, &description);
171 range = grn_ctx_at(ctx, grn_obj_get_range(ctx, accessor));
172 if (range) {
173 char name[GRN_TABLE_MAX_KEY_SIZE];
174 int name_size;
175
176 name_size = grn_obj_name(ctx, range, name, GRN_TABLE_MAX_KEY_SIZE);
177 GRN_TEXT_PUTS(ctx, &description, " -> ");
178 if (name_size == 0) {
179 GRN_TEXT_PUTS(ctx, &description, "(temporary)");
180 } else {
181 GRN_TEXT_PUTS(ctx, &description, "<");
182 GRN_TEXT_PUT(ctx, &description, name, name_size);
183 GRN_TEXT_PUTS(ctx, &description, ">");
184 }
185 grn_obj_unref(ctx, range);
186 }
187 GRN_LOG(ctx, GRN_REPORT_INDEX_LOG_LEVEL,
188 "%s[accessor]%s %.*s",
189 action, tag,
190 (int)GRN_TEXT_LEN(&description),
191 GRN_TEXT_VALUE(&description));
192 GRN_OBJ_FIN(ctx, &description);
193 }