diff --git a/.gitignore b/.gitignore index fec3f9926..c0027a2ce 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ docs/build/ \.pio/ docs/source/_build/ + +venv/ + +.idea/ diff --git a/memanalyzer.py b/memanalyzer.py index b5f9527b4..dd4d2872a 100755 --- a/memanalyzer.py +++ b/memanalyzer.py @@ -23,7 +23,7 @@ import os TOTAL_IRAM = 32786; TOTAL_DRAM = 81920; -env="dev_ESP8266_4096" +env="memanalyze_ESP8266" sections = OrderedDict([ ("data", "Initialized Data (RAM)"), @@ -83,57 +83,24 @@ def analyse_memory(elfFile): # print("Free IRam : %d" % usedIRAM) return(ret) -# reenable all plugins and libs -def enable_all(): - - for plugin in glob.glob(".src/*"): - os.rename(plugin, "src/"+os.path.basename(plugin)) - - for lib in glob.glob(".lib/*"): - os.rename(lib, "lib/"+os.path.basename(lib)) - -def disable_plugin(plugin): - os.rename(plugin, ".src/"+os.path.basename(plugin)) - -def enable_plugin(plugin): - os.rename(".src/"+os.path.basename(plugin), plugin) - -def disable_lib(lib): - os.rename(lib, ".lib/"+os.path.basename(lib)) - -def enable_lib(lib): - os.rename(".lib/"+os.path.basename(lib), lib) try: - - if not os.path.exists(".src"): - os.mkdir(".src") - - if not os.path.exists(".lib"): - os.mkdir(".lib") - - ################### start - if len(sys.argv) < 1: + if len(sys.argv) <= 1: print("Usage: \n\t%s%s " % sys.argv[0]) sys.exit(1) + # e.g. + # ~/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump + # c:/Users/gijs/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-objdump.exe objectDumpBin = sys.argv[1] - enable_all() - - #get list of all plugins - plugins=glob.glob("src/_[CPN]*.ino") + plugins=glob.glob("src/_[CPN][0-9][0-9][0-9]*.ino") plugins.sort() - #get list of all libs - libs=glob.glob("lib/*") - libs.remove("lib/pubsubclient") - libs.sort() - #which plugins to test? if len(sys.argv)>2: plugins=sys.argv[2:] @@ -144,8 +111,8 @@ try: print("Analysing ESPEasy memory usage for env {} ...\n".format(env)) #### disable all plugins and to get base size - for plugin in plugins: - disable_plugin(plugin) + #for plugin in plugins: + # disable_plugin(plugin) # for lib in libs: @@ -156,7 +123,7 @@ try: # #two times, sometimes it changes a few bytes somehow # SEEMS TO BE NOT USEFULL # subprocess.check_call("platformio run --silent --environment dev_4096", shell=True) - base=analyse_memory(".pioenvs/"+env+"/firmware.elf") + base=analyse_memory(".pio/build/"+env+"/firmware.elf") output_format="{:<30}|{:<11}|{:<11}|{:<11}|{:<11}|{:<11}" @@ -180,35 +147,15 @@ try: )) - # note: unused libs never use any memory, so dont have to test this - # ##### test per lib - # results={} - # for lib in libs: - # enable_lib(lib) - # subprocess.check_call("platformio run --silent --environment dev_ESP8266_4096", shell=True) - # results[lib]=analyse_memory(".pioenvs/dev_ESP8266_4096/firmware.elf") - # disable_lib(lib) - # - # print(output_format.format( - # lib, - # results[lib]['text']-base['text'], - # results[lib]['data']-base['data'], - # results[lib]['rodata']-base['rodata'], - # results[lib]['bss']-base['bss'], - # results[lib]['irom0_text']-base['irom0_text'], - # )) - - - - - ##### test per plugin results={} for plugin in plugins: - enable_plugin(plugin) - subprocess.check_call("platformio run --silent --environment "+env, shell=True) - results[plugin]=analyse_memory(".pioenvs/"+env+"/firmware.elf") - disable_plugin(plugin) + pluginname=plugin[plugin.find('_'):] + usesflag="-DUSES{}".format(pluginname[:5]) + my_env = os.environ.copy() + my_env["PLATFORMIO_BUILD_FLAGS"] = usesflag + subprocess.check_call("platformio run --silent --environment {}".format(env), shell=True, env=my_env) + results[plugin]=analyse_memory(".pio/build/"+env+"/firmware.elf") print(output_format.format( plugin, @@ -219,14 +166,8 @@ try: results[plugin]['irom0_text']-base['irom0_text'], )) - - - ##### test with all test_plugins at once - for plugin in plugins: - enable_plugin(plugin) - subprocess.check_call("platformio run --silent --environment "+env, shell=True) - total=analyse_memory(".pioenvs/"+env+"/firmware.elf") + total=analyse_memory(".pio/build/"+env+"/firmware.elf") print(output_format.format( "ALL PLUGINS", @@ -247,11 +188,8 @@ try: )) except: - enable_all() raise -enable_all() - print("\n") diff --git a/platformio.ini b/platformio.ini index ee3521787..363c95213 100644 --- a/platformio.ini +++ b/platformio.ini @@ -206,9 +206,9 @@ build_flags = -DMQTT_MAX_PACKET_SIZE=1024 [common] board_build.f_cpu = 80000000L -build_flags = ${debug_flags.build_flags} ${mqtt_flags.build_flags} ${minimal_size.build_flags} +build_flags = ${debug_flags.build_flags} ${mqtt_flags.build_flags} -DHTTPCLIENT_1_1_COMPATIBLE=0 build_unflags = -DDEBUG_ESP_PORT -lib_deps = +lib_deps = https://github.com/TD-er/ESPEasySerial.git lib_ignore = ESP32_ping, ESP32WebServer, IRremoteESP8266, HeatpumpIR lib_ldf_mode = chain lib_archive = false @@ -401,6 +401,19 @@ build_flags = ${esp8266_4M.build_flags} ${normal_252.build_flags} extra_scripts = pre:pre_extra_script.py +; Special env for memory analysis +; This may generate builds which cannot be run, so do not upload to a node. +[env:memanalyze_ESP8266] +platform = ${normal_252.platform} +board = ${esp8266_4M.board} +board_build.f_cpu = ${esp8266_4M.board_build.f_cpu} +board_build.flash_mode = ${esp8266_4M.board_build.flash_mode} +build_unflags = ${esp8266_4M.build_unflags} +build_flags = ${esp8266_4M.build_flags} ${normal_252.build_flags} -DPLUGIN_BUILD_CUSTOM -w + +extra_scripts = pre:pre_memanalyze.py + + ;;; ESP32 pre-alpha test build ; ****; ****; ****; ****; ****; ****; ****; ****; ****;;;;; ; Very limited build for ESP32, to start testing regular building for ESP32. ; diff --git a/pre_memanalyze.py b/pre_memanalyze.py new file mode 100644 index 000000000..7cbdfc2d7 --- /dev/null +++ b/pre_memanalyze.py @@ -0,0 +1,21 @@ +Import("env") + +# access to global construction environment +#print env + +# Dump construction environment (for debug purpose) +#print env.Dump() + +# append extra flags to global build environment +# which later will be used to build: +# - project source code +# - frameworks +# - dependent libraries +env.Append(CPPDEFINES=[ + "PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22y", + "CONTROLLER_SET_NONE", + "NOTIFIER_SET_NONE", + "PLUGIN_SET_NONE", + + ("WEBSERVER_RULES_DEBUG", "0") +]) diff --git a/src/WebServer_fwddecl.h b/src/WebServer_fwddecl.h index 95fbad6fd..fda1cc059 100644 --- a/src/WebServer_fwddecl.h +++ b/src/WebServer_fwddecl.h @@ -1,6 +1,7 @@ #ifndef WEBSERVER_FWD_DECL_H #define WEBSERVER_FWD_DECL_H +#include "limits.h" #include "StringProviderTypes.h"