diff options
| author | levlam <levlam@telegram.org> | 2022-02-10 23:01:28 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2022-02-10 23:01:28 +0300 |
| commit | b8ab910b81475b27545b8469234a7cfea517ed27 (patch) | |
| tree | 7cce16a65638aadd8dc2434081a976a806940d52 /memprof | |
| parent | 3d8e5e00e45a1599be8bfa8c29a4d7f6f8e1c4b4 (diff) | |
Various improvements.
Diffstat (limited to 'memprof')
| -rw-r--r-- | memprof/memprof.cpp | 3 | ||||
| -rw-r--r-- | memprof/memprof_stat.cpp | 15 | ||||
| -rw-r--r-- | memprof/memprof_stat.h | 7 |
3 files changed, 19 insertions, 6 deletions
diff --git a/memprof/memprof.cpp b/memprof/memprof.cpp index d45d5e9b9..c1ef1d3d1 100644 --- a/memprof/memprof.cpp +++ b/memprof/memprof.cpp @@ -265,12 +265,14 @@ void free(void *data_void) { #endif return free_old(info); } + void *calloc(std::size_t size_a, std::size_t size_b) { auto size = size_a * size_b; void *res = malloc_with_frame(size, get_backtrace()); std::memset(res, 0, size); return res; } + void *realloc(void *ptr, std::size_t size) { if (ptr == nullptr) { return malloc_with_frame(size, get_backtrace()); @@ -282,6 +284,7 @@ void *realloc(void *ptr, std::size_t size) { free(ptr); return new_ptr; } + void *memalign(std::size_t aligment, std::size_t size) { my_assert(false && "Memalign is unsupported"); return nullptr; diff --git a/memprof/memprof_stat.cpp b/memprof/memprof_stat.cpp index 59c352afd..00d371431 100644 --- a/memprof/memprof_stat.cpp +++ b/memprof/memprof_stat.cpp @@ -4,7 +4,7 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include "memprof_stat.h" +#include "memprof/memprof_stat.h" #include "td/utils/port/platform.h" @@ -15,7 +15,6 @@ #include <cstdint> #include <cstdlib> #include <cstring> -#include <functional> #include <new> #include <utility> #include <vector> @@ -37,7 +36,8 @@ struct malloc_info { std::int32_t size; }; -std::atomic<uint64_t> total_memory_used; +static std::atomic<std::size_t> total_memory_used; + void register_xalloc(malloc_info *info, std::int32_t diff) { my_assert(info->size >= 0); // TODO: this is very slow in case of several threads. @@ -106,12 +106,14 @@ void free(void *data_void) { #endif return free_old(info); } + void *calloc(std::size_t size_a, std::size_t size_b) { auto size = size_a * size_b; void *res = do_malloc(size); std::memset(res, 0, size); return res; } + void *realloc(void *ptr, std::size_t size) { if (ptr == nullptr) { return do_malloc(size); @@ -123,15 +125,16 @@ void *realloc(void *ptr, std::size_t size) { free(ptr); return new_ptr; } + void *memalign(std::size_t alignment, std::size_t size) { auto res = malloc(size); - my_assert(reinterpret_cast<uint64_t>(res) % alignment == 0); + my_assert(reinterpret_cast<std::uintptr_t>(res) % alignment == 0); return res; } int posix_memalign(void **memptr, size_t alignment, size_t size) { auto res = malloc(size); - my_assert(reinterpret_cast<uint64_t>(res) % alignment == 0); + my_assert(reinterpret_cast<std::uintptr_t>(res) % alignment == 0); *memptr = res; return 0; } @@ -158,6 +161,6 @@ bool is_memprof_on() { return false; } std::size_t get_used_memory_size() { - return false; + return 0; } #endif diff --git a/memprof/memprof_stat.h b/memprof/memprof_stat.h index d12f9c127..5bc045e25 100644 --- a/memprof/memprof_stat.h +++ b/memprof/memprof_stat.h @@ -1,6 +1,13 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// #pragma once #include <cstddef> bool is_memprof_on(); + std::size_t get_used_memory_size(); |
