Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MQTT
Revision 23:5111e398e651, committed 2019-04-12
- Comitter:
- ccli8
- Date:
- Fri Apr 12 16:23:50 2019 +0800
- Parent:
- 22:8a5abc6c2b68
- Child:
- 24:97cdb9465331
- Commit message:
- Add stack statistics
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed_app.json | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 29 11:35:08 2019 +0800
+++ b/main.cpp Fri Apr 12 16:23:50 2019 +0800
@@ -18,8 +18,13 @@
/* MyTLSSocket = Mbed TLS over TCPSocket */
#include "MyTLSSocket.h"
+#if (MBED_HEAP_STATS_ENABLED) || (MBED_STACK_STATS_ENABLED)
/* Measure memory footprint */
#include "mbed_stats.h"
+/* Fix up the compilation on AMRCC for PRIu32 */
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#endif
#if AWS_IOT_MQTT_TEST
/* MQTT-specific header files */
@@ -349,9 +354,9 @@
printf("MQTT disconnecting");
if ((mqtt_rc = _mqtt_client->disconnect()) != 0) {
- printf("\rMQTT disconnects failed %d\n", mqtt_rc);
+ printf("\rMQTT disconnects failed %d\n\n", mqtt_rc);
}
- printf("\rMQTT disconnects OK\n");
+ printf("\rMQTT disconnects OK\n\n");
_tlssocket->close();
}
@@ -696,6 +701,37 @@
#endif // End of AWS_IOT_HTTPS_TEST
+#if (MBED_HEAP_STATS_ENABLED)
+void print_heap_stats()
+{
+ mbed_stats_heap_t stats;
+ mbed_stats_heap_get(&stats);
+ printf("** MBED HEAP STATS **\n");
+ printf("**** current_size: %" PRIu32 "\n", stats.current_size);
+ printf("**** max_size : %" PRIu32 "\n", stats.max_size);
+ printf("*****************************\n\n");
+}
+#endif // MBED_HEAP_STATS_ENABLED
+
+#if (MBED_STACK_STATS_ENABLED)
+void print_stack_statistics()
+{
+ printf("** MBED THREAD STACK STATS **\n");
+ int cnt = osThreadGetCount();
+ mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));
+
+ if (stats) {
+ cnt = mbed_stats_stack_get_each(stats, cnt);
+ for (int i = 0; i < cnt; i++) {
+ printf("Thread: 0x%" PRIx32 ", Stack size: %" PRIu32 ", Max stack: %" PRIu32 "\r\n", stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
+ }
+
+ free(stats);
+ }
+ printf("*****************************\n\n");
+}
+#endif // MBED_STACK_STATS_ENABLED
+
int main() {
/* The default 9600 bps is too slow to print full TLS debug info and could
@@ -733,9 +769,12 @@
delete https_test;
#endif // End of AWS_IOT_HTTPS_TEST
- /* Heap usage */
- mbed_stats_heap_t heap_stats;
- mbed_stats_heap_get(&heap_stats);
- printf("\nCurrent heap size: %lu\n", heap_stats.current_size);
- printf("Max heap size: %lu\n\n", heap_stats.max_size);
+#if (MBED_HEAP_STATS_ENABLED)
+ print_heap_stats();
+#endif
+
+#if (MBED_STACK_STATS_ENABLED)
+ print_stack_statistics();
+#endif
+
}
--- a/mbed_app.json Mon Apr 29 11:35:08 2019 +0800
+++ b/mbed_app.json Fri Apr 12 16:23:50 2019 +0800
@@ -8,6 +8,7 @@
"platform.stdio-baud-rate" : 115200,
"platform.stdio-convert-newlines" : true,
"platform.heap-stats-enabled" : 1,
+ "platform.stack-stats-enabled" : 1,
"mbed-trace.enable" : null,
"nsapi.default-wifi-security" : "WPA_WPA2",
"nsapi.default-wifi-ssid" : "\"SSID\"",