|
1 | 1 | /*
|
2 |
| - * FreeRTOS Kernel V10.2.0 |
3 |
| - * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | + * FreeRTOS Kernel V10.3.0 |
| 3 | + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
4 | 4 | *
|
5 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6 | 6 | * this software and associated documentation files (the "Software"), to deal in
|
@@ -116,10 +116,12 @@ static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t )
|
116 | 116 | /* Create a couple of list links to mark the start and end of the list. */
|
117 | 117 | static BlockLink_t xStart, *pxEnd = NULL;
|
118 | 118 |
|
119 |
| -/* Keeps track of the number of free bytes remaining, but says nothing about |
120 |
| -fragmentation. */ |
| 119 | +/* Keeps track of the number of calls to allocate and free memory as well as the |
| 120 | +number of free bytes remaining, but says nothing about fragmentation. */ |
121 | 121 | static size_t xFreeBytesRemaining = 0U;
|
122 | 122 | static size_t xMinimumEverFreeBytesRemaining = 0U;
|
| 123 | +static size_t xNumberOfSuccessfulAllocations = 0; |
| 124 | +static size_t xNumberOfSuccessfulFrees = 0; |
123 | 125 |
|
124 | 126 | /* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
|
125 | 127 | member of an BlockLink_t structure is set then the block belongs to the
|
@@ -231,6 +233,7 @@ void *pvReturn = NULL;
|
231 | 233 | by the application and has no "next" block. */
|
232 | 234 | pxBlock->xBlockSize |= xBlockAllocatedBit;
|
233 | 235 | pxBlock->pxNextFreeBlock = NULL;
|
| 236 | + xNumberOfSuccessfulAllocations++; |
234 | 237 | }
|
235 | 238 | else
|
236 | 239 | {
|
@@ -301,6 +304,7 @@ BlockLink_t *pxLink;
|
301 | 304 | xFreeBytesRemaining += pxLink->xBlockSize;
|
302 | 305 | traceFREE( pv, pxLink->xBlockSize );
|
303 | 306 | prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
|
| 307 | + xNumberOfSuccessfulFrees++; |
304 | 308 | }
|
305 | 309 | ( void ) xTaskResumeAll();
|
306 | 310 | }
|
@@ -482,4 +486,62 @@ const HeapRegion_t *pxHeapRegion;
|
482 | 486 | /* Work out the position of the top bit in a size_t variable. */
|
483 | 487 | xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );
|
484 | 488 | }
|
| 489 | +/*-----------------------------------------------------------*/ |
| 490 | + |
| 491 | +void vPortGetHeapStats( HeapStats_t *pxHeapStats ) |
| 492 | +{ |
| 493 | +BlockLink_t *pxBlock; |
| 494 | +size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */ |
| 495 | + |
| 496 | + vTaskSuspendAll(); |
| 497 | + { |
| 498 | + pxBlock = xStart.pxNextFreeBlock; |
| 499 | + |
| 500 | + /* pxBlock will be NULL if the heap has not been initialised. The heap |
| 501 | + is initialised automatically when the first allocation is made. */ |
| 502 | + if( pxBlock != NULL ) |
| 503 | + { |
| 504 | + do |
| 505 | + { |
| 506 | + /* Increment the number of blocks and record the largest block seen |
| 507 | + so far. */ |
| 508 | + xBlocks++; |
| 509 | + |
| 510 | + if( pxBlock->xBlockSize > xMaxSize ) |
| 511 | + { |
| 512 | + xMaxSize = pxBlock->xBlockSize; |
| 513 | + } |
| 514 | + |
| 515 | + /* Heap five will have a zero sized block at the end of each |
| 516 | + each region - the block is only used to link to the next |
| 517 | + heap region so it not a real block. */ |
| 518 | + if( pxBlock->xBlockSize != 0 ) |
| 519 | + { |
| 520 | + if( pxBlock->xBlockSize < xMinSize ) |
| 521 | + { |
| 522 | + xMinSize = pxBlock->xBlockSize; |
| 523 | + } |
| 524 | + } |
| 525 | + |
| 526 | + /* Move to the next block in the chain until the last block is |
| 527 | + reached. */ |
| 528 | + pxBlock = pxBlock->pxNextFreeBlock; |
| 529 | + } while( pxBlock != pxEnd ); |
| 530 | + } |
| 531 | + } |
| 532 | + xTaskResumeAll(); |
| 533 | + |
| 534 | + pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize; |
| 535 | + pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize; |
| 536 | + pxHeapStats->xNumberOfFreeBlocks = xBlocks; |
| 537 | + |
| 538 | + taskENTER_CRITICAL(); |
| 539 | + { |
| 540 | + pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining; |
| 541 | + pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations; |
| 542 | + pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees; |
| 543 | + pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining; |
| 544 | + } |
| 545 | + taskEXIT_CRITICAL(); |
| 546 | +} |
485 | 547 |
|
0 commit comments