Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
added memory profiling #632
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Dec 15, 2020
1 parent 4087a4f commit 06be035
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 113 deletions.
2 changes: 1 addition & 1 deletion lib/uuid-console/src/uuid/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ class Shell : public std::enable_shared_from_this<Shell>, public uuid::log::Hand
* @since 0.1.0
*/
size_t vprintf(const __FlashStringHelper * format, va_list ap);
void set_command_str(const __FlashStringHelper * str);
void set_command_str(const __FlashStringHelper * str);

static const uuid::log::Logger logger_; /*!< uuid::log::Logger instance for shells. @since 0.1.0 */
static std::set<std::shared_ptr<Shell>> shells_; /*!< Registered running shells to be executed. @since 0.1.0 */
Expand Down
2 changes: 0 additions & 2 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,9 @@ void Console::load_standard_commands(unsigned int context) {
Test::run_test(shell, arguments.front());
}
});
#if defined(EMSESP_STANDALONE)
EMSESPShell::commands->add_command(context, CommandFlags::USER, flash_string_vector{F("t")}, [](Shell & shell, const std::vector<std::string> & arguments) {
Test::run_test(shell, "default");
});
#endif
#endif

EMSESPShell::commands->add_command(
Expand Down
227 changes: 121 additions & 106 deletions src/devices/boiler.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/emsdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ class EMSdevice {
};
const std::vector<DeviceValue> devicevalues() const;

void init_devicevalues(uint8_t size) {
devicevalues_.reserve(size);
}

private:
uint8_t unique_id_;
uint8_t device_type_ = DeviceType::SYSTEM;
Expand Down
20 changes: 19 additions & 1 deletion src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,24 @@ void EMSESP::show_devices(uuid::console::Shell & shell) {
emsdevice->show_telegram_handlers(shell);
// emsdevice->show_mqtt_handlers(shell);
shell.println();

#if defined(EMSESP_DEBUG)
// TODO debug stuff - count size of objects
size_t total_s = 0;
uint8_t count = 0;
for (const auto & dv : emsdevice->devicevalues()) {
size_t s = sizeof(dv);
if (dv.full_name) {
shell.printfln("[%s] %d", uuid::read_flash_string(dv.full_name).c_str(), s);
} else {
shell.printfln("[%s]* %d", uuid::read_flash_string(dv.short_name).c_str(), s);
}
total_s += s;
count++;
}
shell.printfln("Total size of %d elements: %d", count, total_s);
shell.println();
#endif
}
}
}
Expand Down Expand Up @@ -785,7 +803,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
// find the name and flags in our database
for (const auto & device : device_library_) {
if (device.product_id == product_id) {
emsdevice->name(uuid::read_flash_string(device.name));
emsdevice->name(std::move(uuid::read_flash_string(device.name)));
emsdevice->add_flags(device.flags);
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ void System::start() {
#endif
}

#if defined(EMSESP_DEBUG)
show_mem("Startup");
#endif

// print boot message
EMSESP::esp8266React.getWiFiSettingsService()->read(
[&](WiFiSettings & wifiSettings) { LOG_INFO(F("System %s booted (EMS-ESP version %s)"), wifiSettings.hostname.c_str(), EMSESP_APP_VERSION); });
Expand Down Expand Up @@ -300,7 +304,19 @@ void System::loop() {
void System::show_mem(const char * note) {
#if defined(ESP8266)
#if defined(EMSESP_DEBUG)
LOG_INFO(F("(%s) Free heap: %d%% (%lu), frag:%u%%"), note, free_mem(), (unsigned long)ESP.getFreeHeap(), ESP.getHeapFragmentation());
static uint32_t old_free_heap = 0;
static uint8_t old_heap_frag = 0;
uint32_t free_heap = ESP.getFreeHeap();
uint8_t heap_frag = ESP.getHeapFragmentation();
LOG_INFO(F("(%s) Free heap: %d%% (%lu) (~%lu), frag:%d%% (~%d)"),
note,
free_mem(),
free_heap,
(uint32_t)abs(free_heap - old_free_heap),
heap_frag,
(uint8_t)abs(heap_frag - old_heap_frag));
old_free_heap = free_heap;
old_heap_frag = heap_frag;
#endif
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace emsesp {
// #define EMSESP_TEST_DEFAULT "solar"
// #define EMSESP_TEST_DEFAULT "mixer"
// #define EMSESP_TEST_DEFAULT "web"
#define EMSESP_TEST_DEFAULT "general"
// #define EMSESP_TEST_DEFAULT "boiler"
// #define EMSESP_TEST_DEFAULT "general"
#define EMSESP_TEST_DEFAULT "boiler"

class Test {
public:
Expand Down

0 comments on commit 06be035

Please sign in to comment.