1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[brotli] Added debug info

This commit is contained in:
Witold Filipczyk 2023-10-23 20:12:38 +02:00
parent a2ae13cf06
commit f55e9dd33e
4 changed files with 76 additions and 1 deletions

View File

@ -269,8 +269,11 @@ get_resource_info(struct terminal *term, void *data)
add_format_to_string(&info, ": %ld.", val);
#ifdef CONFIG_DEBUG
#ifdef CONFIG_BROTLI
add_format_to_string(&info, "\nBrotli: used times: %ld active: %ld, size: %ld", get_brotli_total_allocs(), get_brotli_active(), get_brotli_size());
#endif
#ifdef CONFIG_GZIP
add_format_to_string(&info, "\nGzip: %ld used times: %ld active: %ld, size: %ld\n", get_gzip_total_allocs(), get_gzip_active(), get_gzip_size());
add_format_to_string(&info, "\nGzip: used times: %ld active: %ld, size: %ld", get_gzip_total_allocs(), get_gzip_active(), get_gzip_size());
#endif
#endif

View File

@ -18,6 +18,10 @@
#include "encoding/brotli.h"
#include "encoding/encoding.h"
#include "util/math.h"
#ifdef CONFIG_DEBUG
#include "util/memcount.h"
#endif
#include "util/memory.h"
#define ELINKS_BROTLI_BUFFER_LENGTH 4096
@ -51,7 +55,11 @@ brotli_open(struct stream_encoded *stream, int fd)
if (!data) {
return -1;
}
#ifdef CONFIG_DEBUG
data->state = BrotliDecoderCreateInstance(el_brotli_alloc, el_brotli_free, NULL);
#else
data->state = BrotliDecoderCreateInstance(NULL, NULL, NULL);
#endif
if (!data->state) {
mem_free(data);

View File

@ -10,6 +10,62 @@
#include <cstdlib>
#include <map>
#ifdef CONFIG_BROTLI
static std::map<void *, uint64_t> el_brotli_allocs;
static uint64_t el_brotli_total_allocs;
static uint64_t el_brotli_size;
void *
el_brotli_alloc(void *opaque, size_t size)
{
void *res = malloc(size);
if (res) {
el_brotli_allocs[res] = size;
el_brotli_total_allocs++;
el_brotli_size += size;
}
return res;
}
void
el_brotli_free(void *opaque, void *ptr)
{
if (!ptr) {
return;
}
auto el = el_brotli_allocs.find(ptr);
if (el == el_brotli_allocs.end()) {
fprintf(stderr, "brotli %p not found\n", ptr);
return;
}
el_brotli_size -= el->second;
el_brotli_allocs.erase(el);
}
uint64_t
get_brotli_total_allocs(void)
{
return el_brotli_total_allocs;
}
uint64_t
get_brotli_size(void)
{
return el_brotli_size;
}
uint64_t
get_brotli_active(void)
{
return el_brotli_allocs.size();
}
#endif
#ifdef CONFIG_GZIP
static std::map<void *, uint64_t> el_gzip_allocs;

View File

@ -5,6 +5,14 @@
extern "C" {
#endif
#ifdef CONFIG_BROTLI
void *el_brotli_alloc(void *opaque, size_t size);
void el_brotli_free(void *opaque, void *ptr);
uint64_t get_brotli_total_allocs(void);
uint64_t get_brotli_size(void);
uint64_t get_brotli_active(void);
#endif
#ifdef CONFIG_GZIP
void *el_gzip_alloc(void *opaque, unsigned int items, unsigned int size);
void el_gzip_free(void *opaque, void *ptr);