mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
[zstd] Added memcount (only for statically linked zstd)
This commit is contained in:
parent
17b288c935
commit
3834c52686
@ -366,7 +366,11 @@ if conf_data.get('CONFIG_BROTLI')
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if conf_data.get('CONFIG_ZSTD')
|
if conf_data.get('CONFIG_ZSTD')
|
||||||
zstddeps = dependency('libzstd', static: st)
|
zstatic = st
|
||||||
|
if conf_data.get('CONFIG_DEBUG')
|
||||||
|
zstatic = true
|
||||||
|
endif
|
||||||
|
zstddeps = dependency('libzstd', static: zstatic)
|
||||||
deps += zstddeps
|
deps += zstddeps
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -273,6 +273,9 @@ get_resource_info(struct terminal *term, void *data)
|
|||||||
#ifdef CONFIG_GZIP
|
#ifdef CONFIG_GZIP
|
||||||
add_format_to_string(&info, "\nGzip: calls: %ld active: %ld, size: %ld", get_gzip_total_allocs(), get_gzip_active(), get_gzip_size());
|
add_format_to_string(&info, "\nGzip: calls: %ld active: %ld, size: %ld", get_gzip_total_allocs(), get_gzip_active(), get_gzip_size());
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_ZSTD
|
||||||
|
add_format_to_string(&info, "\nZstd: calls: %ld active: %ld, size: %ld", get_zstd_total_allocs(), get_zstd_active(), get_zstd_size());
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_LIBCURL
|
#ifdef CONFIG_LIBCURL
|
||||||
add_format_to_string(&info, "\nCurl: calls: %ld active: %ld, size: %ld", get_curl_total_allocs(), get_curl_active(), get_curl_size());
|
add_format_to_string(&info, "\nCurl: calls: %ld active: %ld, size: %ld", get_curl_total_allocs(), get_curl_active(), get_curl_size());
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
|
#endif
|
||||||
#include <zstd.h>
|
#include <zstd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -17,6 +21,7 @@
|
|||||||
|
|
||||||
#include "encoding/zstd.h"
|
#include "encoding/zstd.h"
|
||||||
#include "encoding/encoding.h"
|
#include "encoding/encoding.h"
|
||||||
|
#include "util/memcount.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
/* How many bytes of compressed data to read before decompressing.
|
/* How many bytes of compressed data to read before decompressing.
|
||||||
@ -44,7 +49,11 @@ zstd_open(struct stream_encoded *stream, int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
data->fdread = fd;
|
data->fdread = fd;
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
data->zstd_stream = ZSTD_createDCtx_advanced(el_zstd_mf);
|
||||||
|
#else
|
||||||
data->zstd_stream = ZSTD_createDCtx();
|
data->zstd_stream = ZSTD_createDCtx();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!data->zstd_stream) {
|
if (!data->zstd_stream) {
|
||||||
mem_free(data);
|
mem_free(data);
|
||||||
|
@ -561,3 +561,65 @@ get_quickjs_active(void)
|
|||||||
return el_quickjs_allocs.size();
|
return el_quickjs_allocs.size();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ZSTD
|
||||||
|
static std::map<void *, uint64_t> el_zstd_allocs;
|
||||||
|
static uint64_t el_zstd_total_allocs;
|
||||||
|
static uint64_t el_zstd_size;
|
||||||
|
|
||||||
|
static void *
|
||||||
|
el_zstd_malloc(void *s, size_t size)
|
||||||
|
{
|
||||||
|
void *res = malloc(size);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
el_zstd_allocs[res] = size;
|
||||||
|
el_zstd_total_allocs++;
|
||||||
|
el_zstd_size += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
el_zstd_free(void *s, void *ptr)
|
||||||
|
{
|
||||||
|
if (!ptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto el = el_zstd_allocs.find(ptr);
|
||||||
|
|
||||||
|
if (el == el_zstd_allocs.end()) {
|
||||||
|
fprintf(stderr, "zstd free %p not found\n", ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el_zstd_size -= el->second;
|
||||||
|
el_zstd_allocs.erase(el);
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZSTD_customMem el_zstd_mf = {
|
||||||
|
el_zstd_malloc,
|
||||||
|
el_zstd_free,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_zstd_total_allocs(void)
|
||||||
|
{
|
||||||
|
return el_zstd_total_allocs;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_zstd_size(void)
|
||||||
|
{
|
||||||
|
return el_zstd_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_zstd_active(void)
|
||||||
|
{
|
||||||
|
return el_zstd_allocs.size();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#include <quickjs/quickjs.h>
|
#include <quickjs/quickjs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ZSTD
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
|
#include <zstd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -66,6 +71,13 @@ uint64_t get_quickjs_size(void);
|
|||||||
uint64_t get_quickjs_active(void);
|
uint64_t get_quickjs_active(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ZSTD
|
||||||
|
extern ZSTD_customMem el_zstd_mf;
|
||||||
|
uint64_t get_zstd_total_allocs(void);
|
||||||
|
uint64_t get_zstd_size(void);
|
||||||
|
uint64_t get_zstd_active(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user