
My take on Pico_Robustness_Test
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
Fork of Pico_Robustness_Test by
Revision 1:97b1710fd9c3, committed 2013-07-25
- Comitter:
- tass
- Date:
- Thu Jul 25 05:44:19 2013 +0000
- Parent:
- 0:8ac2e5a7f731
- Child:
- 2:6da40f9e8301
- Commit message:
- Added memory statistics.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jul 24 05:26:23 2013 +0000 +++ b/main.cpp Thu Jul 25 05:44:19 2013 +0000 @@ -1,4 +1,5 @@ #include "mbed.h" +#include <stdarg.h> #include "EthernetInterface.h" #define msgdbg(...) @@ -6,8 +7,8 @@ //#define msgdbg printf -#define SENDING_RETRIES 5u -#define READING_RETRIES 5u +#define SENDING_RETRIES 3u +#define READING_RETRIES 3u #define DHCP_RETRIES 10u #define BUFFER_SIZE 256 @@ -41,6 +42,7 @@ {NXP_HOST_REQUEST,NXP_HOST,0,0,0x7FFFFFFF,0} }; +void inline printMemoryStats(void); void printStatistics(void) { printf("\nTotal Time : %f seconds\n",(float)totalTime/1000.0f); @@ -52,9 +54,67 @@ printf("Avg duration : %d ms\n",webStatistics[i].avgDuration); printf("Total snapshots : %d\n\n",webStatistics[i].snapshots); } + printMemoryStats(); +} + +struct MemoryUsage +{ + uint32_t curFreeRam; + uint32_t minFreeRam; + uint32_t maxFreeRam; + uint32_t avgFreeRam; + uint32_t stackPointer; + uint32_t cntSamples; +}; + +struct MemoryUsage memoryStats = {0,0xFFFFFFFF,0,0,0}; + +int fakePrintf(void* pvHeapInfo, char const* pFormatString, ...) +{ + struct MemoryUsage * memStat = (struct MemoryUsage *)pvHeapInfo; + static const char* freeRamFormat = "%d bytes in"; + va_list valist; + if(memcmp(pFormatString,freeRamFormat,strlen(freeRamFormat)) == 0) + { + va_start(valist, pFormatString); + unsigned long freeSize = va_arg(valist, unsigned long); + memStat->curFreeRam = freeSize; + if(memStat->minFreeRam > freeSize) + memStat->minFreeRam = freeSize; + + if(memStat->maxFreeRam < freeSize) + memStat->maxFreeRam = freeSize; + + memStat->avgFreeRam = ((memStat->avgFreeRam * memStat->cntSamples) + freeSize)/(++memStat->cntSamples); + } + else + { + // ignore format + } + return 0; } +void inline printMemoryStats(void) +{ + if(memoryStats.cntSamples == 1) + printf("\n\n***** Initial Memory Report *****\n"); + else + printf("\n\n********* Memory Report *********\n"); + + printf("Current free memory : %d bytes\n",memoryStats.curFreeRam); + printf("Maximum free memory : %d bytes\n",memoryStats.maxFreeRam); + printf("Minimum free memory : %d bytes\n",memoryStats.minFreeRam); + printf("Average free memory : %d bytes\n",memoryStats.avgFreeRam); + printf("****************************\n"); +} + +void inline memoryStamp(void) +{ + __heapstats((__heapprt)fakePrintf, &memoryStats); +} + + int main() { int retries = 0; @@ -98,6 +158,7 @@ continue; } + client.set_blocking(false,1500); retries = 0; // sending request @@ -145,6 +206,7 @@ printf("Received : %d bytes\n",received); webStatistics[i].avgDuration = ((webStatistics[i].avgDuration *(webStatistics[i].snapshots++) ) + time)/webStatistics[i].snapshots; totalTime += time; + memoryStamp(); } printStatistics();