Adding function to get used bytes.

This commit is contained in:
Geoffrey Challen 2016-03-10 11:29:38 -05:00
parent 2188853039
commit d322a01342
2 changed files with 19 additions and 7 deletions

View File

@ -130,6 +130,7 @@ void *kmalloc(size_t size);
void kfree(void *ptr); void kfree(void *ptr);
void kheap_printstats(void); void kheap_printstats(void);
void kheap_printused(void); void kheap_printused(void);
unsigned long kheap_getused(void);
void kheap_nextgeneration(void); void kheap_nextgeneration(void);
void kheap_dump(void); void kheap_dump(void);
void kheap_dumpall(void); void kheap_dumpall(void);

View File

@ -819,17 +819,17 @@ kheap_printstats(void)
spinlock_release(&kmalloc_spinlock); spinlock_release(&kmalloc_spinlock);
} }
/* /*
* Print number of used heap bytes. * Return the number of used bytes.
*/ */
void
kheap_printused(void) unsigned long
{ kheap_getused(void) {
struct pageref *pr; struct pageref *pr;
unsigned long total = 0; unsigned long total = 0;
char total_string[32];
/* print the whole thing with interrupts off */ /* compute with interrupts off */
spinlock_acquire(&kmalloc_spinlock); spinlock_acquire(&kmalloc_spinlock);
for (pr = allbase; pr != NULL; pr = pr->next_all) { for (pr = allbase; pr != NULL; pr = pr->next_all) {
total += subpage_stats(pr, true); total += subpage_stats(pr, true);
@ -837,7 +837,18 @@ kheap_printused(void)
total += coremap_used_bytes(); total += coremap_used_bytes();
spinlock_release(&kmalloc_spinlock); spinlock_release(&kmalloc_spinlock);
snprintf(total_string, sizeof(total_string), "%lu", total); return total;
}
/*
* Print number of used bytes.
*/
void
kheap_printused(void)
{
char total_string[32];
snprintf(total_string, sizeof(total_string), "%lu", kheap_getused());
secprintf(SECRET, total_string, "khu"); secprintf(SECRET, total_string, "khu");
} }