a

Dependencies:   mbed-http

Fork of http-example by sandbox

Revision:
17:97b1dd566b07
Parent:
15:65a49b573ba5
Child:
20:d851bc648f9e
--- a/source/main-http.cpp	Mon Sep 04 16:32:38 2017 +0100
+++ b/source/main-http.cpp	Mon Sep 04 17:01:11 2017 +0100
@@ -5,6 +5,7 @@
 #include "mbed.h"
 #include "easy-connect.h"
 #include "http_request.h"
+#include "mbed_stats.h"
 
 Serial pc(USBTX, USBRX);
 
@@ -20,6 +21,12 @@
 
 int main() {
     pc.baud(115200);
+
+    mbed_stats_heap_t heap_stats;
+
+    mbed_stats_heap_get(&heap_stats);
+    printf("[1] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // Connect to the network (see mbed_app.json for the connectivity method used)
     NetworkInterface* network = easy_connect(true);
     if (!network) {
@@ -27,6 +34,9 @@
         return 1;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[2] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // Do a GET request to httpbin.org
     {
         // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
@@ -45,6 +55,9 @@
         delete get_req;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[3] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     // POST request to httpbin.org
     {
         HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
@@ -61,9 +74,15 @@
         printf("\n----- HTTP POST response -----\n");
         dump_response(post_res);
 
+        mbed_stats_heap_get(&heap_stats);
+        printf("[4] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
         delete post_req;
     }
 
+    mbed_stats_heap_get(&heap_stats);
+    printf("[5] Heap: %lu / %lu, max=%lu\n", heap_stats.current_size, heap_stats.reserved_size, heap_stats.max_size);
+
     Thread::wait(osWaitForever);
 }