print meminfo every 10 seconds when Debug level = 2

This commit is contained in:
hathach committed 2017-03-03 15:43:42 +07:00
1 parent 4c9316d0b6
commit c30b7f13ac
3 files changed
+61 -2

No files matched your search

+49
View File
@@ -90,6 +90,7 @@ int dbgHeapUsed(void)
return (mallinfo()).uordblks;
}
#if 0
static void printCenter(const char* str, int width)
{
int lpad = (width-strlen(str))/2;
@@ -150,6 +151,54 @@ void dbgMemInfo(void)
Serial.println(buf);
rtos_free(buf);
}
#else
static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint32_t used)
{
char buffer[30];
if ( used )
{
sprintf(buffer, "%lu / %lu (%02lu%%)", used, top-bottom, (used*100)/ (top-bottom));
}else
{
sprintf(buffer, "%lu", top-bottom);
}
Serial.printf("| %-10s: %-19s |\n", name, buffer);
}
void dbgMemInfo(void)
{
Serial.printf (" _________________________________\n");
Serial.println("| |");
// Pritn SRAM used for Stack executed by S132 and ISR
printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), 0);
// Print Heap usage overall (including memory malloced to tasks)
printMemRegion("Heap", ((uint32_t) __HeapLimit), ((uint32_t) __HeapBase), dbgHeapUsed());
// DATA + BSS
printMemRegion("Data & Bss", ((uint32_t) __bss_end__), ((uint32_t) __data_start__), 0);
// Print SRAM Used by SoftDevice
printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0);
Serial.printf("|_________________________________|\n");
Serial.println();
// Print Task list
uint32_t tasknum = uxTaskGetNumberOfTasks();
char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task
vTaskList(buf);
Serial.println("Task State Prio StackLeft Num");
Serial.println("-----------------------------------");
Serial.println(buf);
rtos_free(buf);
}
#endif
/*------------------------------------------------------------------*/
+11 -1
View File
@@ -16,6 +16,8 @@
#define ARDUINO_MAIN
#include "Arduino.h"
#define MEMINFO_INTERVAL 10000
// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
@@ -35,7 +37,15 @@ static void loop_task(void* arg)
{
loop();
// if (serialEventRun) serialEventRun();
#if CFG_DEBUG > 1 // Full Debug
static uint32_t meminfo_ms = 0;
if (meminfo_ms + MEMINFO_INTERVAL < millis())
{
meminfo_ms += millis();
Serial.printf("Memory Info (print every %d seconds)\n", MEMINFO_INTERVAL/1000);
dbgMemInfo();
}
#endif
// To compatible with most code where loop is not rtos-aware
vTaskDelay(1); //taskYIELD();
+1 -1
View File
@@ -1,5 +1,5 @@
name=Adafruit BLE Libraries for Bluefruit52
version=0.1.0
version=0.2.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules