LVGLPlusPlus
C++ library on top of the lovely LVGL project.
Loading...
Searching...
No Matches
lvppUtils.h
Go to the documentation of this file.
1// Copyright 2023 Robert M. Wolff (bob dot wolff 68 at gmail dot com)
2//
3// Redistribution and use in source and binary forms, with or without modification,
4// are permitted provided that the following conditions are met:
5//
6// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
8//
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation and/or
11// other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its contributors
14// may be used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27//
28#pragma once
29
30#ifdef ESP_PLATFORM
31#include "Arduino.h"
32#endif
33
34#include <vector>
35#include <string>
36#include <sstream>
37#include <iomanip>
38
44constexpr uint16_t MAX_SAMPLENAME = 32;
45
51typedef struct espRec {
52 uint32_t heapFree;
53 uint32_t heapSize;
58
92public:
93 espSystats();
100 void takeSample(const char* sampName); // Records current stats.
107 void takeSampleAndPrintResults(const char* sampName);
115 std::string takeSampleAndGetResults(const char* sampName);
124 void printStaticStats();
131 std::string getStaticStats();
161 void printFullReport();
168 std::string getFullReport();
169protected:
176 void recordSample(const char* sampName);
177 uint32_t cpuFreqMHz;
179 uint32_t sketchSize;
180 std::vector<espRec_t> samples;
181};
182
Data gather and report on ESP32 system stats - mostly memory heap.
Definition: lvppUtils.h:91
void printStaticStats()
Prints the non-record-based statistics only.
Definition: lvppUtils.cpp:99
void takeSampleAndPrintResults(const char *sampName)
Take a sample (via takeSample()) and then print (in non-tabular form) the results.
Definition: lvppUtils.cpp:77
std::string getStaticStats()
Get the non-record-based statistics only and return them in a std::string. See printStaticStats() for...
Definition: lvppUtils.cpp:104
void takeSample(const char *sampName)
Take a data sample immediately and memorialize it with the name passed in the argument.
Definition: lvppUtils.cpp:73
uint32_t sketchFreeSpace
Number of bytes remaining in the sketch/program area.
Definition: lvppUtils.h:178
uint32_t cpuFreqMHz
The processor frequency at the time of instantiation.
Definition: lvppUtils.h:177
std::vector< espRec_t > samples
std::vector which stores each sample in the order taken.
Definition: lvppUtils.h:180
std::string takeSampleAndGetResults(const char *sampName)
Take a sample and return the results as a std::string.
Definition: lvppUtils.cpp:82
uint32_t sketchSize
Number of bytes taken by the current sketch/program.
Definition: lvppUtils.h:179
void printFullReport()
This is the main event for results along with getFullReport(). This prints the static stats as well a...
Definition: lvppUtils.cpp:116
std::string getFullReport()
Same functionality as printFullReport() but returns the result in std::string instead of printing the...
Definition: lvppUtils.cpp:121
void recordSample(const char *sampName)
Internal worker-bee which actually takes the sample and places it in a record.
Definition: lvppUtils.cpp:150
espSystats()
Definition: lvppUtils.cpp:63
constexpr uint16_t MAX_SAMPLENAME
Definition: lvppUtils.h:44
espSystats ESPSystats
Globally available instance of the object to follow most Arduino-based library patterns.
Definition: lvppUtils.cpp:39
struct espRec espRec_t
Struct which holds the data taken in each sample for espSystats class. A typedef of espRec_t is creat...
Struct which holds the data taken in each sample for espSystats class. A typedef of espRec_t is creat...
Definition: lvppUtils.h:51
uint32_t heapLowWaterMark
Definition: lvppUtils.h:55
char sampleName[MAX_SAMPLENAME+1]
Definition: lvppUtils.h:56
uint32_t heapSize
Definition: lvppUtils.h:53
uint32_t heapLargestBlock
Definition: lvppUtils.h:54
uint32_t heapFree
Definition: lvppUtils.h:52