Fix: Properly calculate db size for SystemInfo

So far the calculated size for the tagDB in the frontend was
purely based on the size of each of its static entries.
However the data pointer as well as the json based config string
can occupy additional memory which is not accounted for.

We are therefore introducing a helper function to properly
calculate the DBs size.

Signed-off-by: Mimoja <git@mimoja.de>
This commit is contained in:
Mimoja
2023-07-04 19:03:23 +02:00
parent 63463435cd
commit fd22bc0378
2 changed files with 13 additions and 3 deletions

View File

@@ -94,7 +94,7 @@ function connect() {
processTags(msg.tags);
}
if (msg.sys) {
$('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes &#x2507; db size: ' + msg.sys.dbsize + ' bytes &#x2507; db record count: ' + msg.sys.recordcount + ' &#x2507; filesystem free: ' + convertSize(msg.sys.littlefsfree);
$('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes &#x2507; db size: ' + convertSize(msg.sys.dbsize) + " ("+ msg.sys.dbsize + ' bytes) &#x2507; db record count: ' + msg.sys.recordcount + ' &#x2507; filesystem free: ' + convertSize(msg.sys.littlefsfree);
if (msg.sys.apstate) {
$("#apstatecolor").style.color = apstate[msg.sys.apstate].color;
$("#apstate").innerHTML = apstate[msg.sys.apstate].state;

View File

@@ -127,15 +127,25 @@ void wsErr(String text) {
if (wsMutex) xSemaphoreGive(wsMutex);
}
size_t dbSize(){
size_t size = tagDB.size() * sizeof(tagRecord);
for(auto &tag : tagDB) {
if (tag->data)
size += tag->len;
size += tag->modeConfigJson.length();
}
return size;
}
void wsSendSysteminfo() {
DynamicJsonDocument doc(150);
DynamicJsonDocument doc(250);
JsonObject sys = doc.createNestedObject("sys");
time_t now;
time(&now);
sys["currtime"] = now;
sys["heap"] = ESP.getFreeHeap();
sys["recordcount"] = tagDB.size();
sys["dbsize"] = tagDB.size() * sizeof(tagRecord);
sys["dbsize"] = dbSize();
sys["littlefsfree"] = Storage.freeSpace();
sys["apstate"] = apInfo.state;
sys["runstate"] = config.runStatus;