Kouhei Sutou
null+****@clear*****
Sun Jun 25 00:02:52 JST 2017
Kouhei Sutou 2017-06-25 00:02:52 +0900 (Sun, 25 Jun 2017) New Revision: 1235f71c46c50a34b4f6d0cc854738f7befaf178 https://github.com/groonga/groonga/commit/1235f71c46c50a34b4f6d0cc854738f7befaf178 Message: Add parser and dumper for query log flags They are new API. Modified files: include/groonga/groonga.h include/groonga/util.h lib/logger.c lib/util.c Modified: include/groonga/groonga.h (+5 -1) =================================================================== --- include/groonga/groonga.h 2017-06-25 00:02:00 +0900 (790ca4a) +++ include/groonga/groonga.h 2017-06-25 00:02:52 +0900 (f3f473e) @@ -1,5 +1,5 @@ /* - Copyright(C) 2009-2016 Brazil + Copyright(C) 2009-2017 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -1121,6 +1121,10 @@ struct _grn_query_logger { void (*fin)(grn_ctx *ctx, void *user_data); }; +GRN_API grn_bool grn_query_log_flags_parse(const char *string, + int string_size, + unsigned int *flags); + GRN_API grn_rc grn_query_logger_set(grn_ctx *ctx, const grn_query_logger *logger); GRN_API void grn_query_logger_set_flags(grn_ctx *ctx, unsigned int flags); GRN_API void grn_query_logger_add_flags(grn_ctx *ctx, unsigned int flags); Modified: include/groonga/util.h (+3 -0) =================================================================== --- include/groonga/util.h 2017-06-25 00:02:00 +0900 (9195df1) +++ include/groonga/util.h 2017-06-25 00:02:52 +0900 (0a574c6) @@ -31,6 +31,9 @@ GRN_API grn_obj *grn_inspect_limited(grn_ctx *ctx, GRN_API grn_obj *grn_inspect_name(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj); GRN_API grn_obj *grn_inspect_encoding(grn_ctx *ctx, grn_obj *buffer, grn_encoding encoding); GRN_API grn_obj *grn_inspect_type(grn_ctx *ctx, grn_obj *buffer, unsigned char type); +GRN_API grn_obj *grn_inspect_query_log_flags(grn_ctx *ctx, + grn_obj *buffer, + unsigned int flags); GRN_API void grn_p(grn_ctx *ctx, grn_obj *obj); GRN_API void grn_p_geo_point(grn_ctx *ctx, grn_geo_point *point); Modified: lib/logger.c (+52 -0) =================================================================== --- lib/logger.c 2017-06-25 00:02:00 +0900 (de1540b) +++ lib/logger.c 2017-06-25 00:02:52 +0900 (f7c8d5a) @@ -459,6 +459,58 @@ static grn_critical_section default_query_logger_lock; static off_t default_query_logger_size = 0; static off_t default_query_logger_rotate_threshold_size = 0; +grn_bool +grn_query_log_flags_parse(const char *string, + int string_size, + unsigned int *flags) +{ + const char *string_end; + + *flags = GRN_QUERY_LOG_NONE; + + if (!string) { + return GRN_TRUE; + } + + if (string_size < 0) { + string_size = strlen(string); + } + + string_end = string + string_size; + + while (string < string_end) { + if (*string == '|' || *string == ' ') { + string += 1; + continue; + } + +#define CHECK_FLAG(name) \ + if (((string_end - string) >= (sizeof(#name) - 1)) && \ + (memcmp(string, #name, sizeof(#name) - 1) == 0) && \ + (((string_end - string) == (sizeof(#name) - 1)) || \ + (string[sizeof(#name) - 1] == '|') || \ + (string[sizeof(#name) - 1] == ' '))) { \ + *flags |= GRN_QUERY_LOG_ ## name; \ + string += sizeof(#name) - 1; \ + continue; \ + } + + CHECK_FLAG(NONE); + CHECK_FLAG(COMMAND); + CHECK_FLAG(RESULT_CODE); + CHECK_FLAG(DESTINATION); + CHECK_FLAG(CACHE); + CHECK_FLAG(SIZE); + CHECK_FLAG(SCORE); + +#undef CHECK_FLAG + + return GRN_FALSE; + } + + return GRN_TRUE; +} + static void default_query_logger_log(grn_ctx *ctx, unsigned int flag, const char *timestamp, const char *info, Modified: lib/util.c (+33 -0) =================================================================== --- lib/util.c 2017-06-25 00:02:00 +0900 (cc57e2f) +++ lib/util.c 2017-06-25 00:02:52 +0900 (27fc944) @@ -248,6 +248,39 @@ grn_inspect_type(grn_ctx *ctx, grn_obj *buf, unsigned char type) return buf; } + +grn_obj * +grn_inspect_query_log_flags(grn_ctx *ctx, grn_obj *buffer, unsigned int flags) +{ + grn_bool have_content = GRN_FALSE; + + if (flags == GRN_QUERY_LOG_NONE) { + GRN_TEXT_PUTS(ctx, buffer, "NONE"); + return buffer; + } + +#define CHECK_FLAG(NAME) do { \ + if (flags & GRN_QUERY_LOG_ ## NAME) { \ + if (have_content) { \ + GRN_TEXT_PUTS(ctx, buffer, "|"); \ + } \ + GRN_TEXT_PUTS(ctx, buffer, #NAME); \ + have_content = GRN_TRUE; \ + } \ + } while (GRN_FALSE) + + CHECK_FLAG(COMMAND); + CHECK_FLAG(RESULT_CODE); + CHECK_FLAG(DESTINATION); + CHECK_FLAG(CACHE); + CHECK_FLAG(SIZE); + CHECK_FLAG(SCORE); + +#undef CHECK_FALG + + return buffer; +} + static grn_rc grn_proc_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) { -------------- next part -------------- HTML����������������������������... Download