apps/examples/stat: Only should memory if a leak is detected.

This commit is contained in:
Gregory Nutt 2017-02-13 15:24:58 -06:00
parent c3c8de6b70
commit 1b297d057e

View File

@ -58,15 +58,20 @@ static struct mallinfo g_mmafter;
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static void showusage(struct mallinfo *mmbefore, struct mallinfo *mmafter) static void showusage(FAR struct mallinfo *mmbefore,
FAR struct mallinfo *mmafter, FAR const char *msg)
{ {
printf("VARIABLE BEFORE AFTER\n"); if (mmbefore->uordblks > mmafter->uordblks)
printf("======== ======== ========\n"); {
printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena); printf("\n%s:\n", msg);
printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks); printf("VARIABLE BEFORE AFTER\n");
printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk); printf("======== ======== ========\n");
printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks); printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks); printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
}
} }
static void stepusage(void) static void stepusage(void)
@ -81,8 +86,7 @@ static void stepusage(void)
/* Show the change from the previous loop */ /* Show the change from the previous loop */
printf("\nStep memory usage:\n"); showusage(&g_mmprevious, &g_mmafter, "Step memory leak");
showusage(&g_mmprevious, &g_mmafter);
/* Set up for the next test */ /* Set up for the next test */
@ -100,8 +104,7 @@ static void endusage(void)
#else #else
(void)mallinfo(&g_mmafter); (void)mallinfo(&g_mmafter);
#endif #endif
printf("\nFinal memory usage:\n"); showusage(&g_mmbefore, &g_mmafter, "End-of-test memory leak");
showusage(&g_mmbefore, &g_mmafter);
} }
static void dump_stat(FAR struct stat *buf) static void dump_stat(FAR struct stat *buf)