mirror of
https://github.com/rkd77/elinks.git
synced 2025-04-18 00:47:36 -04:00
[libsixel] memcount
This commit is contained in:
parent
f55e9dd33e
commit
2c47b22bc4
@ -275,6 +275,9 @@ get_resource_info(struct terminal *term, void *data)
|
|||||||
#ifdef CONFIG_GZIP
|
#ifdef CONFIG_GZIP
|
||||||
add_format_to_string(&info, "\nGzip: used times: %ld active: %ld, size: %ld", 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
|
||||||
|
#ifdef CONFIG_LIBSIXEL
|
||||||
|
add_format_to_string(&info, "\nSixel: used times: %ld active: %ld, size: %ld", get_sixel_total_allocs(), get_sixel_active(), get_sixel_size());
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_MEMLEAK
|
#ifdef DEBUG_MEMLEAK
|
||||||
|
@ -41,6 +41,10 @@
|
|||||||
#include "terminal/sixel.h"
|
#include "terminal/sixel.h"
|
||||||
#include "terminal/terminal.h"
|
#include "terminal/terminal.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
#include "util/memcount.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* encode settings object */
|
/* encode settings object */
|
||||||
struct sixel_decoder {
|
struct sixel_decoder {
|
||||||
unsigned int ref;
|
unsigned int ref;
|
||||||
@ -93,6 +97,20 @@ struct sixel_encoder {
|
|||||||
void *dither_cache;
|
void *dither_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
static sixel_allocator_t *el_sixel_allocator;
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_allocator(void)
|
||||||
|
{
|
||||||
|
static int initialized = 0;
|
||||||
|
if (!initialized) {
|
||||||
|
sixel_allocator_new(&el_sixel_allocator, el_sixel_malloc, el_sixel_calloc, el_sixel_realloc, el_sixel_free);
|
||||||
|
initialized = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* palette type */
|
/* palette type */
|
||||||
#define SIXEL_COLOR_OPTION_DEFAULT 0 /* use default settings */
|
#define SIXEL_COLOR_OPTION_DEFAULT 0 /* use default settings */
|
||||||
#define SIXEL_COLOR_OPTION_MONOCHROME 1 /* use monochrome palette */
|
#define SIXEL_COLOR_OPTION_MONOCHROME 1 /* use monochrome palette */
|
||||||
@ -832,8 +850,12 @@ add_image_to_document(struct document *doc, struct string *pixels, int lineno)
|
|||||||
mem_free(im);
|
mem_free(im);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
init_allocator();
|
||||||
|
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||||
|
#else
|
||||||
status = sixel_decoder_new(&decoder, NULL);
|
status = sixel_decoder_new(&decoder, NULL);
|
||||||
|
#endif
|
||||||
if (SIXEL_FAILED(status)) {
|
if (SIXEL_FAILED(status)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -884,6 +906,7 @@ end:
|
|||||||
return ile;
|
return ile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct image *
|
struct image *
|
||||||
copy_frame(struct image *src, int box_width, int box_height, int cell_width, int cell_height, int dx, int dy)
|
copy_frame(struct image *src, int box_width, int box_height, int cell_width, int cell_height, int dx, int dy)
|
||||||
{
|
{
|
||||||
@ -909,7 +932,12 @@ copy_frame(struct image *src, int box_width, int box_height, int cell_width, int
|
|||||||
mem_free(dest);
|
mem_free(dest);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
init_allocator();
|
||||||
|
status = sixel_decoder_new(&decoder, el_sixel_allocator);
|
||||||
|
#else
|
||||||
status = sixel_decoder_new(&decoder, NULL);
|
status = sixel_decoder_new(&decoder, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (SIXEL_FAILED(status)) {
|
if (SIXEL_FAILED(status)) {
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -66,6 +66,7 @@ get_brotli_active(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_GZIP
|
#ifdef CONFIG_GZIP
|
||||||
|
|
||||||
static std::map<void *, uint64_t> el_gzip_allocs;
|
static std::map<void *, uint64_t> el_gzip_allocs;
|
||||||
@ -118,3 +119,92 @@ get_gzip_active(void)
|
|||||||
return el_gzip_allocs.size();
|
return el_gzip_allocs.size();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBSIXEL
|
||||||
|
|
||||||
|
static std::map<void *, uint64_t> el_sixel_allocs;
|
||||||
|
static uint64_t el_sixel_total_allocs;
|
||||||
|
static uint64_t el_sixel_size;
|
||||||
|
|
||||||
|
/* call custom malloc() */
|
||||||
|
void *
|
||||||
|
el_sixel_malloc(
|
||||||
|
size_t /* in */ size) /* allocation size */
|
||||||
|
{
|
||||||
|
void *res = malloc(size);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
el_sixel_allocs[res] = size;
|
||||||
|
el_sixel_total_allocs++;
|
||||||
|
el_sixel_size += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* call custom calloc() */
|
||||||
|
void *
|
||||||
|
el_sixel_calloc(
|
||||||
|
size_t /* in */ nelm, /* allocation size */
|
||||||
|
size_t /* in */ elsize) /* allocation size */
|
||||||
|
{
|
||||||
|
uint64_t alloc_size = nelm * elsize;
|
||||||
|
void *res = calloc(nelm, elsize);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
el_sixel_allocs[res] = alloc_size;
|
||||||
|
el_sixel_total_allocs++;
|
||||||
|
el_sixel_size += alloc_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* call custom realloc() */
|
||||||
|
void *
|
||||||
|
el_sixel_realloc(
|
||||||
|
void /* in */ *p, /* existing buffer to be re-allocated */
|
||||||
|
size_t /* in */ n) /* re-allocation size */
|
||||||
|
{
|
||||||
|
el_sixel_free(p);
|
||||||
|
return el_sixel_malloc(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* call custom free() */
|
||||||
|
void
|
||||||
|
el_sixel_free(
|
||||||
|
void /* in */ *p) /* existing buffer to be freed */
|
||||||
|
{
|
||||||
|
if (!p) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto el = el_sixel_allocs.find(p);
|
||||||
|
|
||||||
|
if (el == el_sixel_allocs.end()) {
|
||||||
|
fprintf(stderr, "sixel %p not found\n", p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el_sixel_size -= el->second;
|
||||||
|
el_sixel_allocs.erase(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_sixel_total_allocs(void)
|
||||||
|
{
|
||||||
|
return el_sixel_total_allocs;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_sixel_size(void)
|
||||||
|
{
|
||||||
|
return el_sixel_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
get_sixel_active(void)
|
||||||
|
{
|
||||||
|
return el_sixel_allocs.size();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef EL__UTIL_MEMCOUNT_H
|
#ifndef EL__UTIL_MEMCOUNT_H
|
||||||
#define EL__UTIL_MEMCOUNT_H
|
#define EL__UTIL_MEMCOUNT_H
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBSIXEL
|
||||||
|
#include <sixel.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -21,6 +25,16 @@ uint64_t get_gzip_size(void);
|
|||||||
uint64_t get_gzip_active(void);
|
uint64_t get_gzip_active(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_LIBSIXEL
|
||||||
|
void *el_sixel_malloc(size_t size);
|
||||||
|
void *el_sixel_calloc(size_t nelm, size_t elsize);
|
||||||
|
void *el_sixel_realloc(void *p, size_t n);
|
||||||
|
void el_sixel_free(void *p);
|
||||||
|
uint64_t get_sixel_total_allocs(void);
|
||||||
|
uint64_t get_sixel_size(void);
|
||||||
|
uint64_t get_sixel_active(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user