| 1 | /* |
| 2 | Copyright(C) 2019-2022 Sutou Kouhei <[email protected]> |
| 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_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | |
| 23 | #ifdef WIN32 |
| 24 | /* For Windows Server 2018 or earlier. */ |
| 25 | # define PSAPI_VERSION 1 |
| 26 | # include <psapi.h> |
| 27 | #endif |
| 28 | |
| 29 | uint64_tcxx . . $ uint64_t# |
| 30 | grn_memory_get_usagecxx . . $ grn_memory_get_usage(a974fc13268e0b36).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 31 | { |
| 32 | #ifdef WIN32 |
| 33 | PROCESS_MEMORY_COUNTERS_EX counters; |
| 34 | if (!GetProcessMemoryInfo(GetCurrentProcess(), |
| 35 | (PPROCESS_MEMORY_COUNTERS)&counters, |
| 36 | sizeof(counters))) { |
| 37 | SERR("GetProcessMemoryInfo"); |
| 38 | return 0; |
| 39 | } |
| 40 | return counters.PrivateUsage; |
| 41 | #elif defined(HAVE_GETRUSAGEcxx . . $ `build/config.h:172:9`!) |
| 42 | struct rusagecxx . . $ rusage# usage; |
| 43 | if (getrusagecxx . . $ getrusage(4e901535a26e1d19).(RUSAGE_SELFcxx . . $ `<external>/1890803886155400780/resource.h:162:9`!, &usage) != 0) { |
| 44 | SERRcxx . . $ `lib/grn_error.h:411:11`!("getrusage"); |
| 45 | return 0; |
| 46 | } |
| 47 | return (uint64_tcxx . . $ uint64_t#)(usage.ru_maxrsscxx . . $ rusage#$anonymous_type_0#ru_maxrss.) * 1024; |
| 48 | #else |
| 49 | return 0; |
| 50 | #endif |
| 51 | } |