LVGLPlusPlus
C++ library on top of the lovely LVGL project.
Loading...
Searching...
No Matches
espSystats Class Reference

Data gather and report on ESP32 system stats - mostly memory heap. More...

#include <lvppUtils.h>

Public Member Functions

 espSystats ()
 
void takeSample (const char *sampName)
 Take a data sample immediately and memorialize it with the name passed in the argument.
 
void takeSampleAndPrintResults (const char *sampName)
 Take a sample (via takeSample()) and then print (in non-tabular form) the results.
 
std::string takeSampleAndGetResults (const char *sampName)
 Take a sample and return the results as a std::string.
 
void printStaticStats ()
 Prints the non-record-based statistics only.
 
std::string getStaticStats ()
 Get the non-record-based statistics only and return them in a std::string. See printStaticStats() for more detail.
 
void printFullReport ()
 This is the main event for results along with getFullReport(). This prints the static stats as well as a full table of all records taken via the *Sample() functions.
 
std::string getFullReport ()
 Same functionality as printFullReport() but returns the result in std::string instead of printing the results out.
 

Protected Member Functions

void recordSample (const char *sampName)
 Internal worker-bee which actually takes the sample and places it in a record.
 

Protected Attributes

uint32_t cpuFreqMHz
 The processor frequency at the time of instantiation.
 
uint32_t sketchFreeSpace
 Number of bytes remaining in the sketch/program area.
 
uint32_t sketchSize
 Number of bytes taken by the current sketch/program.
 
std::vector< espRec_tsamples
 std::vector which stores each sample in the order taken.
 

Detailed Description

Data gather and report on ESP32 system stats - mostly memory heap.

For quite a while I've used the ESP.* utility functions once in a while to print out key heap and sketch metrics when I'm scratching my head about free space and such. This class advances that notion by allowing the user to call ESPSystats.takeSample() and pass an argument which describes the point in the lifecycle in descriptive terms. These 'takeSample' items are collected by the class and are available at any time to be printed by simply calling ESPSystats.printFullReport(). The resulting output gives the user a table of memory and other stat information in chronological order from each takeSample() completed. It is a super handy way to understand what objects or portions of your code are impacting usage. An example of the output from printFullReport() follows:

ESP32 STATS: CPU Speed(MHz): 160, Sketch Size: 874400, Sketch Free Space: 436320
----------------------------------------------------------------------------
| HEAPSIZ | FREE    | LARGEST | MIN     | SAMPLE NAME                      |
----------------------------------------------------------------------------
| 312060  | 286928  | 110580  | 281356  | SETUP-pre-tft                    |
| 311996  | 286628  | 110580  | 281056  | SETUP-pre-lvgl                   |
| 310940  | 282516  | 110580  | 276908  | SETUP-post-lvgl                  |
| 310940  | 282412  | 110580  | 276684  | SETUP-pre-widgets                |
| 310068  | 191452  | 69620   | 185880  | Splash-start                     |
| 306908  | 173676  | 64500   | 173580  | SETUP-end                        |
| 306892  | 173708  | 64500   | 171492  | Splash-end                       |
----------------------------------------------------------------------------

Note: Class is functional on ESP32, but on a simulated environment simply prints (via printf()) a note that such stats are unavailable.

Constructor & Destructor Documentation

◆ espSystats()

espSystats::espSystats ( )

Member Function Documentation

◆ getFullReport()

std::string espSystats::getFullReport ( )

Same functionality as printFullReport() but returns the result in std::string instead of printing the results out.

Returns
std::string Full report returned as a std::string object.

◆ getStaticStats()

std::string espSystats::getStaticStats ( )

Get the non-record-based statistics only and return them in a std::string. See printStaticStats() for more detail.

Returns
std::string Rather than printing, return results in a std::string to the caller.

◆ printFullReport()

void espSystats::printFullReport ( )

This is the main event for results along with getFullReport(). This prints the static stats as well as a full table of all records taken via the *Sample() functions.

The typical usage pattern is to utilize takeSample() from multiple places in your project - especially during startup where objects are created and graphics are set up into memory. Then, at a point when startup is relatively stable, this function is called to get a single final report to view.

This function can be called multiple times, however there is no facility to clear out prior records. Any newly taken samples will be appended to the report in subsequent calls for a full report.

A sample output report follows:

ESP32 STATS: CPU Speed(MHz): 160, Sketch Size: 874400, Sketch Free Space: 436320
----------------------------------------------------------------------------
| HEAPSIZ | FREE    | LARGEST | MIN     | SAMPLE NAME                      |
----------------------------------------------------------------------------
| 312060  | 286928  | 110580  | 281356  | SETUP-pre-tft                    |
| 311996  | 286628  | 110580  | 281056  | SETUP-pre-lvgl                   |
| 310940  | 282516  | 110580  | 276908  | SETUP-post-lvgl                  |
| 310940  | 282412  | 110580  | 276684  | SETUP-pre-widgets                |
| 310068  | 191452  | 69620   | 185880  | Splash-start                     |
| 306908  | 173676  | 64500   | 173580  | SETUP-end                        |
| 306892  | 173708  | 64500   | 171492  | Splash-end                       |
----------------------------------------------------------------------------

◆ printStaticStats()

void espSystats::printStaticStats ( )

Prints the non-record-based statistics only.

There are a few items which do not change on a per-sample basis. These are captured at instantiation time and are available to be printed here. These are: cpuFreqMHz, sketchFreeSpace, and sketchSize.

◆ recordSample()

void espSystats::recordSample ( const char *  sampName)
protected

Internal worker-bee which actually takes the sample and places it in a record.

Parameters
sampNameA simple name to mark in descriptive terms when the sample was taken in the lifecycle of the program calling it.

◆ takeSample()

void espSystats::takeSample ( const char *  sampName)

Take a data sample immediately and memorialize it with the name passed in the argument.

Parameters
sampNameA simple name to mark in descriptive terms when the sample was taken in the lifecycle of the program calling it.

◆ takeSampleAndGetResults()

std::string espSystats::takeSampleAndGetResults ( const char *  sampName)

Take a sample and return the results as a std::string.

Parameters
sampNameA simple name to mark in descriptive terms when the sample was taken in the lifecycle of the program calling it.
Returns
std::string Rather than printing the results - return the results as a std::string.

◆ takeSampleAndPrintResults()

void espSystats::takeSampleAndPrintResults ( const char *  sampName)

Take a sample (via takeSample()) and then print (in non-tabular form) the results.

Parameters
sampNameA simple name to mark in descriptive terms when the sample was taken in the lifecycle of the program calling it.

Member Data Documentation

◆ cpuFreqMHz

uint32_t espSystats::cpuFreqMHz
protected

The processor frequency at the time of instantiation.

◆ samples

std::vector<espRec_t> espSystats::samples
protected

std::vector which stores each sample in the order taken.

◆ sketchFreeSpace

uint32_t espSystats::sketchFreeSpace
protected

Number of bytes remaining in the sketch/program area.

◆ sketchSize

uint32_t espSystats::sketchSize
protected

Number of bytes taken by the current sketch/program.


The documentation for this class was generated from the following files: