Add more clib2 stats

JSON formatted data can now be saved with ARexx "SLABSTATS stats.json"
This commit is contained in:
Chris Young 2016-11-27 17:10:03 +00:00
parent 4fb38f574a
commit 0bc32aa654
3 changed files with 47 additions and 7 deletions

View File

@ -118,7 +118,7 @@ STATIC struct ARexxCmd Commands[] =
{"ACTIVE", RX_ACTIVE, rx_active, "T=TAB/S", 0, NULL, 0, 0, NULL },
{"CLOSE", RX_CLOSE, rx_close, "W=WINDOW/K/N,T=TAB/K/N", 0, NULL, 0, 0, NULL },
{"HOTLIST", RX_HOTLIST, rx_hotlist, "A=ACTION/A", 0, NULL, 0, 0, NULL },
{"SLABSTATS", RX_SLABSTATS, rx_slabstats, NULL, 0, NULL, 0, 0, NULL },
{"SLABSTATS", RX_SLABSTATS, rx_slabstats, "FILE", 0, NULL, 0, 0, NULL },
{ NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL }
};
@ -674,7 +674,14 @@ RXHOOKF(rx_hotlist)
RXHOOKF(rx_slabstats)
{
#ifndef __amigaos4__
ami_memory_slab_dump();
BPTR fh = 0;
if(cmd->ac_ArgList[0] != NULL) {
fh = Open((char *)cmd->ac_ArgList[0], MODE_NEWFILE);
}
ami_memory_slab_dump(fh);
if(fh != 0) Close(fh);
#endif
}

View File

@ -17,6 +17,7 @@
*/
#ifndef __amigaos4__
#include <proto/dos.h>
#include <proto/exec.h>
#include <exec/interrupts.h>
#include <stdlib.h>
@ -46,7 +47,7 @@ void *ami_memory_clear_alloc(size_t size, UBYTE value)
}
/* clib2 slab allocator stats */
static int ami_memory_slab_callback(const struct __slab_usage_information * sui)
static int ami_memory_slab_usage_cb(const struct __slab_usage_information * sui)
{
if(sui->sui_slab_index <= 1) {
LOG("clib2 slab usage:");
@ -70,11 +71,43 @@ static int ami_memory_slab_callback(const struct __slab_usage_information * sui)
return 0;
}
void ami_memory_slab_dump(void)
static int ami_memory_slab_alloc_cb(const struct __slab_allocation_information *sai)
{
__get_slab_usage(ami_memory_slab_callback);
if(sai->sai_allocation_index <= 1) {
LOG("clib2 allocation usage:");
LOG(" Number of allocations which are not managed by slabs: %ld",
sai->sai_num_single_allocations);
LOG(" Total number of bytes allocated for memory not managed by slabs: %ld",
sai->sai_total_single_allocation_size);
}
LOG("Alloc %d", sai->sai_allocation_index);
LOG(" Size of this allocation, as requested: %ld", sai->sai_allocation_size);
LOG(" Total size of this allocation, including management data: %ld",
sai->sai_total_allocation_size);
return 0;
}
static int ami_memory_slab_stats_cb(void *user_data, const char *line, size_t line_length)
{
BPTR fh = (BPTR)user_data;
long err = FPuts(fh, line);
if(err != 0) {
return -1;
} else {
return 0;
}
}
void ami_memory_slab_dump(BPTR fh)
{
__get_slab_usage(ami_memory_slab_usage_cb);
__get_slab_allocations(ami_memory_slab_alloc_cb);
__get_slab_stats(fh, ami_memory_slab_stats_cb);
}
/* Low memory handler */
static void ami_memory_low_mem_handler(void *p)
{
if(low_mem_status == PURGE_STEP1) {
@ -115,7 +148,7 @@ struct Interrupt *ami_memory_init(void)
struct Interrupt *memhandler = malloc(sizeof(struct Interrupt));
if(memhandler == NULL) return NULL; // we're screwed
memhandler->is_Node.ln_Pri = -100; // low down as will be slow
memhandler->is_Node.ln_Pri = -127; // low down as will be slow
memhandler->is_Node.ln_Name = "NetSurf low memory handler";
memhandler->is_Data = NULL;
memhandler->is_Code = (APTR)&ami_memory_handler;

View File

@ -59,7 +59,7 @@ void *ami_memory_clear_alloc(size_t size, UBYTE value);
/* clib2 slab allocator */
#ifndef __amigaos4__
void ami_memory_slab_dump(void);
void ami_memory_slab_dump(BPTR fh);
struct Interrupt *ami_memory_init(void);
void ami_memory_fini(struct Interrupt *memhandler);
#endif