/*\r
- * FreeRTOS Kernel V10.1.1\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a copy of\r
* this software and associated documentation files (the "Software"), to deal in\r
/* Create a couple of list links to mark the start and end of the list. */\r
static BlockLink_t xStart, *pxEnd = NULL;\r
\r
-/* Keeps track of the number of free bytes remaining, but says nothing about\r
-fragmentation. */\r
+/* Keeps track of the number of calls to allocate and free memory as well as the\r
+number of free bytes remaining, but says nothing about fragmentation. */\r
static size_t xFreeBytesRemaining = 0U;\r
static size_t xMinimumEverFreeBytesRemaining = 0U;\r
+static size_t xNumberOfSuccessfulAllocations = 0;\r
+static size_t xNumberOfSuccessfulFrees = 0;\r
\r
/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize\r
member of an BlockLink_t structure is set then the block belongs to the\r
by the application and has no "next" block. */\r
pxBlock->xBlockSize |= xBlockAllocatedBit;\r
pxBlock->pxNextFreeBlock = NULL;\r
+ xNumberOfSuccessfulAllocations++;\r
}\r
else\r
{\r
xFreeBytesRemaining += pxLink->xBlockSize;\r
traceFREE( pv, pxLink->xBlockSize );\r
prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );\r
+ xNumberOfSuccessfulFrees++;\r
}\r
( void ) xTaskResumeAll();\r
}\r
/* Work out the position of the top bit in a size_t variable. */\r
xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
+{\r
+BlockLink_t *pxBlock;\r
+size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */\r
+\r
+ vTaskSuspendAll();\r
+ {\r
+ pxBlock = xStart.pxNextFreeBlock;\r
+\r
+ /* pxBlock will be NULL if the heap has not been initialised. The heap\r
+ is initialised automatically when the first allocation is made. */\r
+ if( pxBlock != NULL )\r
+ {\r
+ do\r
+ {\r
+ /* Increment the number of blocks and record the largest block seen\r
+ so far. */\r
+ xBlocks++;\r
+\r
+ if( pxBlock->xBlockSize > xMaxSize )\r
+ {\r
+ xMaxSize = pxBlock->xBlockSize;\r
+ }\r
+\r
+ /* Heap five will have a zero sized block at the end of each\r
+ each region - the block is only used to link to the next\r
+ heap region so it not a real block. */\r
+ if( pxBlock->xBlockSize != 0 )\r
+ {\r
+ if( pxBlock->xBlockSize < xMinSize )\r
+ {\r
+ xMinSize = pxBlock->xBlockSize;\r
+ }\r
+ }\r
+\r
+ /* Move to the next block in the chain until the last block is\r
+ reached. */\r
+ pxBlock = pxBlock->pxNextFreeBlock;\r
+ } while( pxBlock != pxEnd );\r
+ }\r
+ }\r
+ xTaskResumeAll();\r
+\r
+ pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;\r
+ pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;\r
+ pxHeapStats->xNumberOfFreeBlocks = xBlocks;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;\r
+ pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;\r
+ pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;\r
+ pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+}\r
\r