Kouhei Sutou 2019-03-19 15:10:54 +0900 (Tue, 19 Mar 2019) Revision: ee5d5f9c5bf5aa5053d28576132bcd9592f9b25e https://github.com/groonga/groonga/commit/ee5d5f9c5bf5aa5053d28576132bcd9592f9b25e Message: Add grn_memory_get_usage() Added files: include/groonga/memory.h lib/memory.c Modified files: build/ac_macros/check_functions.m4 config.h.cmake include/groonga.h include/groonga/Makefile.am lib/c_sources.am Modified: build/ac_macros/check_functions.m4 (+1 -0) =================================================================== --- build/ac_macros/check_functions.m4 2019-03-19 15:10:15 +0900 (8c2081dbb) +++ build/ac_macros/check_functions.m4 2019-03-19 15:10:54 +0900 (f6dae2518) @@ -5,6 +5,7 @@ AC_CHECK_FUNCS(_localtime64_s) AC_CHECK_FUNCS(_strtoui64) AC_CHECK_FUNCS(futimens) AC_CHECK_FUNCS(futimes) +AC_CHECK_FUNCS(getrusage) AC_CHECK_FUNCS(gmtime_r) AC_CHECK_FUNCS(localtime_r) AC_CHECK_FUNCS(mkstemp) Modified: config.h.cmake (+1 -0) =================================================================== --- config.h.cmake 2019-03-19 15:10:15 +0900 (81fced427) +++ config.h.cmake 2019-03-19 15:10:54 +0900 (12a329892) @@ -138,6 +138,7 @@ #cmakedefine HAVE_FPCLASSIFY #cmakedefine HAVE_FUTIMENS #cmakedefine HAVE_FUTIMES +#cmakedefine HAVE_GETRUSAGE #cmakedefine HAVE_GMTIME_R #cmakedefine HAVE_LOCALTIME_R #cmakedefine HAVE_MKSTEMP Modified: include/groonga.h (+1 -0) =================================================================== --- include/groonga.h 2019-03-19 15:10:15 +0900 (a735c5def) +++ include/groonga.h 2019-03-19 15:10:54 +0900 (266de1fcb) @@ -42,6 +42,7 @@ #include "groonga/id.h" #include "groonga/ii.h" #include "groonga/index_column.h" +#include "groonga/memory.h" #include "groonga/obj.h" #include "groonga/operator.h" #include "groonga/option.h" Modified: include/groonga/Makefile.am (+1 -0) =================================================================== --- include/groonga/Makefile.am 2019-03-19 15:10:15 +0900 (45860bc95) +++ include/groonga/Makefile.am 2019-03-19 15:10:54 +0900 (3987dc29a) @@ -21,6 +21,7 @@ groonga_include_HEADERS = \ id.h \ ii.h \ index_column.h \ + memory.h \ msgpack.h \ obj.h \ operator.h \ Added: include/groonga/memory.h (+29 -0) 100644 =================================================================== --- /dev/null +++ include/groonga/memory.h 2019-03-19 15:10:54 +0900 (7f651738e) @@ -0,0 +1,29 @@ +/* + Copyright(C) 2019 Kouhei Sutou <kou****@clear*****> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 +*/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +GRN_API uint64_t grn_memory_get_usage(grn_ctx *ctx); + +#ifdef __cplusplus +} +#endif Modified: lib/c_sources.am (+1 -0) =================================================================== --- lib/c_sources.am 2019-03-19 15:10:15 +0900 (637bb2ebd) +++ lib/c_sources.am 2019-03-19 15:10:54 +0900 (806aa674d) @@ -52,6 +52,7 @@ libgroonga_c_sources = \ grn_load.h \ logger.c \ grn_logger.h \ + memory.c \ mrb.c \ grn_mrb.h \ msgpack.c \ Added: lib/memory.c (+45 -0) 100644 =================================================================== --- /dev/null +++ lib/memory.c 2019-03-19 15:10:54 +0900 (28236ed2f) @@ -0,0 +1,45 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2019 Kouhei Sutou <kou****@clear*****> + + 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_ctx.h" + +#include <stdio.h> + +uint64_t +grn_memory_get_usage(grn_ctx *ctx) +{ +#ifdef WIN32 + PROCESS_MEMORY_COUNTERS_EX counters; + if (!GetProcessMemoryInfo(GetCurrentProcess(), + &counters, + sizeof(counters))) { + SERR("GetProcessMemoryInfo"); + return 0; + } + return counters.PrivateUsage; +#elif defined(HAVE_GETRUSAGE) + struct rusage usage; + if (getrusage(RUSAGE_SELF, &usage) != 0) { + SERR("getrusage"); + return 0; + } + return usage.ru_maxrss * 1024; +#else + return 0; +#endif +} -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190319/27e9be1c/attachment-0001.html>