mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/shell: cleanup the heap command approach
Replaces the special heap command approach of the lpc_common module with a more general heap command approach. Module lpc_common was already removed with PR #2118. PR #2118 integrated cpu/lpc_common code in cpu/lpc2387. With PR #3530 special heap handling for cpu/lpc2387 was replaced by newlib memory management which uses _sbrk_r to allocate chunks from the heap. _sbrk_r uses _sheap and _eheap symbols that are defined in lpc2387.ld and can be used together with mallinfo function for heap statistics.
This commit is contained in:
parent
80264c08de
commit
140987fc3a
@ -27,6 +27,7 @@
|
||||
#include <unistd.h>
|
||||
#include <reent.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -122,6 +123,24 @@ void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print heap statistics
|
||||
*
|
||||
* If the CPU does not provide its own heap handling and heap_stats function,
|
||||
* but instead uses the newlib_syscall_default function, this function outputs
|
||||
* the heap statistics. If the CPU provides its own heap_stats function, it
|
||||
* should define HAVE_HEAP_STATS in its cpu_conf.h file.
|
||||
*/
|
||||
#ifndef HAVE_HEAP_STATS
|
||||
__attribute__((weak)) void heap_stats(void)
|
||||
{
|
||||
struct mallinfo minfo = mallinfo();
|
||||
long int heap_size = &_eheap - &_sheap;
|
||||
printf("heap: %ld (used %d, free %ld) [bytes]\n",
|
||||
heap_size, minfo.uordblks, heap_size - minfo.uordblks);
|
||||
}
|
||||
#endif /* HAVE_HEAP_STATS */
|
||||
|
||||
#endif /*__mips__*/
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,9 @@ endif
|
||||
ifneq (,$(filter ps,$(USEMODULE)))
|
||||
SRC += sc_ps.c
|
||||
endif
|
||||
ifneq (,$(filter heap_cmd,$(USEMODULE)))
|
||||
SRC += sc_heap.c
|
||||
endif
|
||||
ifneq (,$(filter sht1x,$(USEMODULE)))
|
||||
SRC += sc_sht1x.c
|
||||
endif
|
||||
|
@ -18,14 +18,24 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "cpu_conf.h"
|
||||
|
||||
#if defined(MODULE_NEWLIB_SYSCALLS_DEFAULT) || defined (HAVE_HEAP_STATS)
|
||||
extern void heap_stats(void);
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
int _heap_handler(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
#if defined(MODULE_NEWLIB_SYSCALLS_DEFAULT) || defined (HAVE_HEAP_STATS)
|
||||
heap_stats();
|
||||
|
||||
return 0;
|
||||
#else
|
||||
printf("heap statistics are not supported for %s cpu\n", RIOT_CPU);
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ extern int _reboot_handler(int argc, char **argv);
|
||||
extern int _id_handler(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_LPC_COMMON
|
||||
#ifdef MODULE_HEAP_CMD
|
||||
extern int _heap_handler(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
@ -162,8 +162,8 @@ const shell_command_t _shell_command_list[] = {
|
||||
#ifdef MODULE_CONFIG
|
||||
{"id", "Gets or sets the node's id.", _id_handler},
|
||||
#endif
|
||||
#ifdef MODULE_LPC_COMMON
|
||||
{"heap", "Shows the heap state for the LPC2387 on the command shell.", _heap_handler},
|
||||
#ifdef MODULE_HEAP_CMD
|
||||
{"heap", "Prints heap statistics.", _heap_handler},
|
||||
#endif
|
||||
#ifdef MODULE_PS
|
||||
{"ps", "Prints information about running threads.", _ps_handler},
|
||||
|
Loading…
Reference in New Issue
Block a user