mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-27 02:56:18 -04:00
[debug] Show info about gzip allocations
Number of callocs from the begining. Number of active allocations. Total size of active allocations.
This commit is contained in:
parent
7185d705de
commit
a2ae13cf06
@ -32,6 +32,9 @@
|
||||
#include "session/session.h"
|
||||
#include "terminal/terminal.h"
|
||||
#include "util/conv.h"
|
||||
#ifdef CONFIG_DEBUG
|
||||
#include "util/memcount.h"
|
||||
#endif
|
||||
#ifdef DEBUG_MEMLEAK
|
||||
#include "util/memdebug.h"
|
||||
#endif
|
||||
@ -265,6 +268,12 @@ get_resource_info(struct terminal *term, void *data)
|
||||
val = get_number_of_temporary_files();
|
||||
add_format_to_string(&info, ": %ld.", val);
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
#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());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MEMLEAK
|
||||
add_char_to_string(&info, '\n');
|
||||
add_to_string(&info, _("Memory allocated", term));
|
||||
|
@ -16,6 +16,11 @@
|
||||
|
||||
#include "encoding/encoding.h"
|
||||
#include "encoding/gzip.h"
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
#include "util/memcount.h"
|
||||
#endif
|
||||
|
||||
#include "util/memory.h"
|
||||
|
||||
/* How many bytes of compressed data to read before decompressing. */
|
||||
@ -60,6 +65,10 @@ deflate_open(int window_size, struct stream_encoded *stream, int fd)
|
||||
/* Initialize all members of *data, except data->buf[], which
|
||||
* will be initialized on demand by deflate_read. */
|
||||
copy_struct(&data->deflate_stream, &null_z_stream);
|
||||
#ifdef CONFIG_DEBUG
|
||||
data->deflate_stream.zalloc = el_gzip_alloc;
|
||||
data->deflate_stream.zfree = el_gzip_free;
|
||||
#endif
|
||||
data->fdread = fd;
|
||||
data->last_read = 0;
|
||||
data->after_first_read = 0;
|
||||
|
@ -7,7 +7,7 @@ SUBDIRS = qs_parse
|
||||
|
||||
OBJS-unless$(CONFIG_SMALL) += fastfind.o
|
||||
OBJS-$(CONFIG_CSS) += scanner.o
|
||||
OBJS-$(CONFIG_DEBUG) += memdebug.o
|
||||
OBJS-$(CONFIG_DEBUG) += memcount.obj memdebug.o
|
||||
OBJS-$(CONFIG_DOM) += scanner.o
|
||||
|
||||
ifeq ($(CONFIG_BITTORRENT),yes)
|
||||
|
64
src/util/memcount.cpp
Normal file
64
src/util/memcount.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "elinks.h"
|
||||
#include "util/memcount.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
||||
#ifdef CONFIG_GZIP
|
||||
|
||||
static std::map<void *, uint64_t> el_gzip_allocs;
|
||||
static uint64_t el_gzip_total_allocs;
|
||||
static uint64_t el_gzip_size;
|
||||
|
||||
void *
|
||||
el_gzip_alloc(void *opaque, unsigned int items, unsigned int size)
|
||||
{
|
||||
uint64_t alloc_size = items * size;
|
||||
void *res = calloc(items, size);
|
||||
|
||||
if (res) {
|
||||
el_gzip_allocs[res] = alloc_size;
|
||||
el_gzip_total_allocs++;
|
||||
el_gzip_size += alloc_size;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
el_gzip_free(void *opaque, void *ptr)
|
||||
{
|
||||
auto el = el_gzip_allocs.find(ptr);
|
||||
|
||||
if (el == el_gzip_allocs.end()) {
|
||||
fprintf(stderr, "gzip %p not found\n", ptr);
|
||||
return;
|
||||
}
|
||||
el_gzip_size -= el->second;
|
||||
el_gzip_allocs.erase(el);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_gzip_total_allocs(void)
|
||||
{
|
||||
return el_gzip_total_allocs;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_gzip_size(void)
|
||||
{
|
||||
return el_gzip_size;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_gzip_active(void)
|
||||
{
|
||||
return el_gzip_allocs.size();
|
||||
}
|
||||
#endif
|
21
src/util/memcount.h
Normal file
21
src/util/memcount.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef EL__UTIL_MEMCOUNT_H
|
||||
#define EL__UTIL_MEMCOUNT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GZIP
|
||||
void *el_gzip_alloc(void *opaque, unsigned int items, unsigned int size);
|
||||
void el_gzip_free(void *opaque, void *ptr);
|
||||
uint64_t get_gzip_total_allocs(void);
|
||||
uint64_t get_gzip_size(void);
|
||||
uint64_t get_gzip_active(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@ if conf_data.get('CONFIG_CSS') or conf_data.get('CONFIG_BITTORRENT')
|
||||
srcs += files('scanner.c')
|
||||
endif
|
||||
if conf_data.get('CONFIG_DEBUG')
|
||||
srcs += files('memdebug.c')
|
||||
srcs += files('memcount.cpp', 'memdebug.c')
|
||||
endif
|
||||
if conf_data.get('CONFIG_DOM')
|
||||
srcs += files('scanner.c')
|
||||
|
Loading…
Reference in New Issue
Block a user