Kouhei Sutou
null+****@clear*****
Sun Jun 25 00:03:53 JST 2017
Kouhei Sutou 2017-06-25 00:03:53 +0900 (Sun, 25 Jun 2017) New Revision: 3b91a9d917b2543ea7160c3d7351ccfe57775996 https://github.com/groonga/groonga/commit/3b91a9d917b2543ea7160c3d7351ccfe57775996 Message: Add query_log_flags command Added files: lib/proc/proc_query_log.c test/command/suite/query_log_flags/add.expected test/command/suite/query_log_flags/add.test test/command/suite/query_log_flags/invalid/flags.expected test/command/suite/query_log_flags/invalid/flags.test test/command/suite/query_log_flags/invalid/mode.expected test/command/suite/query_log_flags/invalid/mode.test test/command/suite/query_log_flags/remove.expected test/command/suite/query_log_flags/remove.test test/command/suite/query_log_flags/set.expected test/command/suite/query_log_flags/set.test Modified files: lib/grn_proc.h lib/proc.c lib/proc/sources.am Modified: lib/grn_proc.h (+1 -0) =================================================================== --- lib/grn_proc.h 2017-06-25 00:02:52 +0900 (47eb487) +++ lib/grn_proc.h 2017-06-25 00:03:53 +0900 (64b7919) @@ -61,6 +61,7 @@ void grn_proc_init_object_inspect(grn_ctx *ctx); void grn_proc_init_object_list(grn_ctx *ctx); void grn_proc_init_object_remove(grn_ctx *ctx); void grn_proc_init_query_expand(grn_ctx *ctx); +void grn_proc_init_query_log_flags(grn_ctx *ctx); void grn_proc_init_schema(grn_ctx *ctx); void grn_proc_init_select(grn_ctx *ctx); void grn_proc_init_snippet(grn_ctx *ctx); Modified: lib/proc.c (+2 -0) =================================================================== --- lib/proc.c 2017-06-25 00:02:52 +0900 (e275a07) +++ lib/proc.c 2017-06-25 00:03:53 +0900 (47a6a95) @@ -4020,4 +4020,6 @@ grn_db_init_builtin_commands(grn_ctx *ctx) grn_proc_init_table_copy(ctx); grn_proc_init_in_records(ctx); + + grn_proc_init_query_log_flags(ctx); } Added: lib/proc/proc_query_log.c (+112 -0) 100644 =================================================================== --- /dev/null +++ lib/proc/proc_query_log.c 2017-06-25 00:03:53 +0900 (bf4dac6) @@ -0,0 +1,112 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2017 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "../grn_proc.h" + +#include <groonga/plugin.h> + +static grn_obj * +command_query_log_flags(grn_ctx *ctx, + int nargs, + grn_obj **args, + grn_user_data *user_data) +{ + unsigned int previous_flags; + grn_obj *flags_text; + + previous_flags = grn_query_logger_get_flags(ctx); + flags_text = grn_plugin_proc_get_var(ctx, user_data, "flags", -1); + if (GRN_TEXT_LEN(flags_text) > 0) { + unsigned int flags = 0; + grn_obj *mode_value; + + if (!grn_query_log_flags_parse(GRN_TEXT_VALUE(flags_text), + GRN_TEXT_LEN(flags_text), + &flags)) { + GRN_PLUGIN_ERROR(ctx, + GRN_INVALID_ARGUMENT, + "[query-log][flags] invalid query log flags: <%.*s>", + (int)GRN_TEXT_LEN(flags_text), + GRN_TEXT_VALUE(flags_text)); + grn_ctx_output_null(ctx); + return NULL; + } + + mode_value = grn_plugin_proc_get_var(ctx, user_data, "mode", -1); + if (GRN_TEXT_LEN(mode_value) == 0 || + GRN_TEXT_EQUAL_CSTRING(mode_value, "SET")) { + grn_query_logger_set_flags(ctx, flags); + } else if (GRN_TEXT_EQUAL_CSTRING(mode_value, "ADD")) { + grn_query_logger_add_flags(ctx, flags); + } else if (GRN_TEXT_EQUAL_CSTRING(mode_value, "REMOVE")) { + grn_query_logger_remove_flags(ctx, flags); + } else { + GRN_PLUGIN_ERROR(ctx, + GRN_INVALID_ARGUMENT, + "[query-log][flags] " + "mode must be <SET>, <ADD> or <REMOVE>: <%.*s>", + (int)GRN_TEXT_LEN(mode_value), + GRN_TEXT_VALUE(mode_value)); + grn_ctx_output_null(ctx); + return NULL; + } + } + + { + unsigned int current_flags; + grn_obj inspected_flags; + + current_flags = grn_query_logger_get_flags(ctx); + GRN_TEXT_INIT(&inspected_flags, 0); + + grn_ctx_output_map_open(ctx, "query_log_flags", 2); + + grn_inspect_query_log_flags(ctx, &inspected_flags, previous_flags); + grn_ctx_output_cstr(ctx, "previous"); + grn_ctx_output_str(ctx, + GRN_TEXT_VALUE(&inspected_flags), + GRN_TEXT_LEN(&inspected_flags)); + + GRN_BULK_REWIND(&inspected_flags); + grn_inspect_query_log_flags(ctx, &inspected_flags, current_flags); + grn_ctx_output_cstr(ctx, "current"); + grn_ctx_output_str(ctx, + GRN_TEXT_VALUE(&inspected_flags), + GRN_TEXT_LEN(&inspected_flags)); + + grn_ctx_output_map_close(ctx); + + GRN_OBJ_FIN(ctx, &inspected_flags); + } + + return NULL; +} + +void +grn_proc_init_query_log_flags(grn_ctx *ctx) +{ + grn_expr_var vars[2]; + + grn_plugin_expr_var_init(ctx, &(vars[0]), "flags", -1); + grn_plugin_expr_var_init(ctx, &(vars[1]), "mode", -1); + grn_plugin_command_create(ctx, + "query_log_flags", -1, + command_query_log_flags, + 2, + vars); +} Modified: lib/proc/sources.am (+1 -0) =================================================================== --- lib/proc/sources.am 2017-06-25 00:02:52 +0900 (3113901) +++ lib/proc/sources.am 2017-06-25 00:03:53 +0900 (6eddfea) @@ -10,6 +10,7 @@ libgrnproc_la_SOURCES = \ proc_object_inspect.c \ proc_object_list.c \ proc_query.c \ + proc_query_log.c \ proc_schema.c \ proc_select.c \ proc_snippet.c \ Added: test/command/suite/query_log_flags/add.expected (+24 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/add.expected 2017-06-25 00:03:53 +0900 (057a040) @@ -0,0 +1,24 @@ +query_log_flags --flags COMMAND|RESULT_CODE --mode SET +[ + [ + 0, + 0.0, + 0.0 + ], + { + "previous": "COMMAND|RESULT_CODE|DESTINATION|CACHE|SIZE|SCORE", + "current": "COMMAND|RESULT_CODE" + } +] +query_log_flags --flags SIZE|SCORE --mode ADD +[ + [ + 0, + 0.0, + 0.0 + ], + { + "previous": "COMMAND|RESULT_CODE", + "current": "COMMAND|RESULT_CODE|SIZE|SCORE" + } +] Added: test/command/suite/query_log_flags/add.test (+2 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/add.test 2017-06-25 00:03:53 +0900 (d9e43a7) @@ -0,0 +1,2 @@ +query_log_flags --flags COMMAND|RESULT_CODE --mode SET +query_log_flags --flags SIZE|SCORE --mode ADD Added: test/command/suite/query_log_flags/invalid/flags.expected (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/invalid/flags.expected 2017-06-25 00:03:53 +0900 (4cab91c) @@ -0,0 +1,13 @@ +query_log_flags --flags nonexistent +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "[query-log][flags] invalid query log flags: <nonexistent>" + ], + null +] +#|e| [query-log][flags] invalid query log flags: <nonexistent> Added: test/command/suite/query_log_flags/invalid/flags.test (+1 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/invalid/flags.test 2017-06-25 00:03:53 +0900 (c6adc1b) @@ -0,0 +1 @@ +query_log_flags --flags nonexistent Added: test/command/suite/query_log_flags/invalid/mode.expected (+13 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/invalid/mode.expected 2017-06-25 00:03:53 +0900 (b81cd76) @@ -0,0 +1,13 @@ +query_log_flags --flags SIZE --mode nonexistent +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "[query-log][flags] mode must be <SET>, <ADD> or <REMOVE>: <nonexistent>" + ], + null +] +#|e| [query-log][flags] mode must be <SET>, <ADD> or <REMOVE>: <nonexistent> Added: test/command/suite/query_log_flags/invalid/mode.test (+1 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/invalid/mode.test 2017-06-25 00:03:53 +0900 (3ec97bc) @@ -0,0 +1 @@ +query_log_flags --flags SIZE --mode nonexistent Added: test/command/suite/query_log_flags/remove.expected (+12 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/remove.expected 2017-06-25 00:03:53 +0900 (7bc74d9) @@ -0,0 +1,12 @@ +query_log_flags --flags DESTINATION|CACHE|SIZE|SCORE --mode REMOVE +[ + [ + 0, + 0.0, + 0.0 + ], + { + "previous": "COMMAND|RESULT_CODE|DESTINATION|CACHE|SIZE|SCORE", + "current": "COMMAND|RESULT_CODE" + } +] Added: test/command/suite/query_log_flags/remove.test (+1 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/remove.test 2017-06-25 00:03:53 +0900 (6b97cf5) @@ -0,0 +1 @@ +query_log_flags --flags DESTINATION|CACHE|SIZE|SCORE --mode REMOVE Added: test/command/suite/query_log_flags/set.expected (+12 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/set.expected 2017-06-25 00:03:53 +0900 (669aec3) @@ -0,0 +1,12 @@ +query_log_flags --flags SIZE --mode SET +[ + [ + 0, + 0.0, + 0.0 + ], + { + "previous": "COMMAND|RESULT_CODE|DESTINATION|CACHE|SIZE|SCORE", + "current": "SIZE" + } +] Added: test/command/suite/query_log_flags/set.test (+1 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/query_log_flags/set.test 2017-06-25 00:03:53 +0900 (bf5f1c2) @@ -0,0 +1 @@ +query_log_flags --flags SIZE --mode SET -------------- next part -------------- HTML����������������������������...Download