1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdarg.h>
17 #include <malloc.h>
18 #include <errno.h>
19 #include <string.h>
20 #include "pthread_impl.h"
21
malloc_info(int options,FILE * fp)22 int malloc_info(int options, FILE* fp)
23 {
24 return 0;
25 }
26
27 #ifdef USE_JEMALLOC_DFX_INTF
28 extern struct mallinfo je_mallinfo();
29 extern void je_malloc_stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
30 const char *opts);
31 #endif
32
malloc_stats_print(void (* write_cb)(void *,const char *),void * cbopaque,const char * opts)33 void malloc_stats_print(void (*write_cb) (void *, const char *), void *cbopaque, const char *opts)
34 {
35 #ifdef USE_JEMALLOC_DFX_INTF
36 je_malloc_stats_print(write_cb, cbopaque, opts);
37 #endif
38 }
39
mallinfo2(void)40 struct mallinfo2 mallinfo2(void)
41 {
42 #ifdef USE_JEMALLOC_DFX_INTF
43 struct mallinfo info = je_mallinfo();
44 struct mallinfo2 res = {
45 .hblks = info.hblks,
46 .hblkhd = info.hblkhd,
47 .usmblks = info.usmblks,
48 .uordblks = info.uordblks,
49 .fordblks = info.fordblks,
50 };
51 return res;
52 #endif
53 return (struct mallinfo2){};
54 }
55
mallinfo(void)56 struct mallinfo mallinfo(void)
57 {
58 struct mallinfo2 mallinfo2_res = mallinfo2();
59 return (struct mallinfo) {
60 .hblks = mallinfo2_res.hblks,
61 .hblkhd = mallinfo2_res.hblkhd,
62 .uordblks = mallinfo2_res.uordblks,
63 .fordblks = mallinfo2_res.fordblks,
64 };
65 }