mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-24 08:45:10 +03:00
* umm_malloc manual merge with upstream * Fix divide by zero, case when heap is 100% allocated. * Removed extra line. * Fixed block count for debug build. This resolves OOM events for debug build. Correct overstepping array when freeing. * Handle another corner case in example HeapMetric.ino. Comment corrections. * Revert - ESP.getMaxFreeBlockSize() is back to indicating the size of a contiguous block of memory before the umm_malloc overhead is removed. * Stale code cleanup and comment improvements
57 lines
1.8 KiB
C++
57 lines
1.8 KiB
C++
/*
|
|
Esp.cpp - ESP8266-specific APIs
|
|
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
|
|
This file is part of the esp8266 core for Arduino environment.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#include "umm_malloc/umm_malloc.h"
|
|
#include "umm_malloc/umm_malloc_cfg.h"
|
|
#include "coredecls.h"
|
|
#include "Esp.h"
|
|
|
|
void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
|
|
{
|
|
// L2 / Euclidian norm of free block sizes.
|
|
// Having getFreeHeap()=sum(hole-size), fragmentation is given by
|
|
// 100 * (1 - sqrt(sum(hole-size²)) / sum(hole-size))
|
|
|
|
umm_info(NULL, false);
|
|
uint8_t block_size = umm_block_size();
|
|
if (hfree)
|
|
*hfree = ummHeapInfo.freeBlocks * block_size;
|
|
if (hmax)
|
|
*hmax = (uint16_t)ummHeapInfo.maxFreeContiguousBlocks * block_size;
|
|
if (hfrag) {
|
|
if (ummHeapInfo.freeBlocks) {
|
|
*hfrag = 100 - (sqrt32(ummHeapInfo.freeBlocksSquared) * 100) / ummHeapInfo.freeBlocks;
|
|
} else {
|
|
*hfrag = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
uint8_t EspClass::getHeapFragmentation()
|
|
{
|
|
#ifdef UMM_INLINE_METRICS
|
|
return (uint8_t)umm_fragmentation_metric();
|
|
#else
|
|
uint8_t hfrag;
|
|
getHeapStats(nullptr, nullptr, &hfrag);
|
|
return hfrag;
|
|
#endif
|
|
}
|