diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-05 20:01:43 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-05 20:01:43 +0000 |
commit | 1f8899bbb98173dc72daba93b77a80aa7162c5d5 (patch) | |
tree | cd1dad6b6851e791f4a551c8e95b870496d610a8 /apps/examples/nxffs | |
parent | fe8430b28928dd36a9d881b4f02ce56d91dec6a0 (diff) | |
download | px4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.gz px4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.tar.bz2 px4-nuttx-1f8899bbb98173dc72daba93b77a80aa7162c5d5.zip |
Add NXFFS ioctls
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3566 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/examples/nxffs')
-rw-r--r-- | apps/examples/nxffs/nxffs_main.c | 125 |
1 files changed, 122 insertions, 3 deletions
diff --git a/apps/examples/nxffs/nxffs_main.c b/apps/examples/nxffs/nxffs_main.c index b2a6846c0..c94b3cb80 100644 --- a/apps/examples/nxffs/nxffs_main.c +++ b/apps/examples/nxffs/nxffs_main.c @@ -142,11 +142,74 @@ static const char g_mountdir[] = CONFIG_EXAMPLES_NXFFS_MOUNTPT "/"; static int g_nfiles; static int g_ndeleted; +static struct mallinfo g_mmbefore; +static struct mallinfo g_mmprevious; +static struct mallinfo g_mmafter; + /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** + * Name: nxffs_memusage + ****************************************************************************/ + +static void nxffs_showmemusage(struct mallinfo *mmbefore, + struct mallinfo *mmafter) +{ + message("VARIABLE BEFORE AFTER\n"); + message("======== ======== ========\n"); + message("arena %8x %8x\n", mmbefore->arena, mmafter->arena); + message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks); + message("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk); + message("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks); + message("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks); +} + +/**************************************************************************** + * Name: nxffs_loopmemusage + ****************************************************************************/ + +static void nxffs_loopmemusage(void) +{ + /* Get the current memory usage */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmafter = mallinfo(); +#else + (void)mallinfo(&g_mmafter); +#endif + + /* Show the change from the previous loop */ + + message("\nEnd of loop memory usage:\n"); + nxffs_showmemusage(&g_mmprevious, &g_mmafter); + + /* Set up for the next test */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmprevious = g_mmafter; +#else + memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo)); +#endif +} + +/**************************************************************************** + * Name: nxffs_endmemusage + ****************************************************************************/ + +static void nxffs_endmemusage(void) +{ +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmafter = mallinfo(); +#else + (void)mallinfo(&g_mmafter); +#endif + message("\nFinal memory usage:\n"); + nxffs_showmemusage(&g_mmbefore, &g_mmafter); +} + +/**************************************************************************** * Name: nxffs_randchar ****************************************************************************/ @@ -265,7 +328,7 @@ static inline int nxffs_wrfile(FAR struct nxffs_filedesc_s *file) return ERROR; } - /* Write a random amount of data dat the file */ + /* Write a random amount of data to the file */ for (offset = 0; offset < file->len; ) { @@ -611,6 +674,44 @@ static int nxffs_delfiles(void) } /**************************************************************************** + * Name: nxffs_delallfiles + ****************************************************************************/ + +static int nxffs_delallfiles(void) +{ + FAR struct nxffs_filedesc_s *file; + int ret; + int i; + + for (i = 0; i < CONFIG_EXAMPLES_NXFFS_MAXOPEN; i++) + { + file = &g_files[i]; + if (file->name) + { + ret = unlink(file->name); + if (ret < 0) + { + message("ERROR: Unlink %d failed: %d\n", i+1, errno); + message(" File name: %s\n", file->name); + message(" File size: %d\n", file->len); + message(" File index: %d\n", i); + } + else + { +#if CONFIG_EXAMPLES_NXFFS_VERBOSE != 0 + message(" Deleted file %s\n", file->name); +#endif + nxffs_freefile(file); + } + } + } + + g_nfiles = 0; + g_ndeleted = 0; + return OK; +} + +/**************************************************************************** * Name: nxffs_directory ****************************************************************************/ @@ -703,6 +804,16 @@ int user_start(int argc, char *argv[]) exit(3); } + /* Set up memory monitoring */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + g_mmbefore = mallinfo(); + g_mmprevious = g_mmbefore; +#else + (void)mallinfo(&g_mmbefore); + memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); +#endif + /* Loop a few times ... file the file system with some random, files, * delete some files randomly, fill the file system with more random file, * delete, etc. This beats the FLASH very hard! @@ -719,7 +830,7 @@ int user_start(int argc, char *argv[]) * (hopefully that the file system is full) */ - message("=== FILLING %d =============================\n", i); + message("\n=== FILLING %d =============================\n", i); ret = nxffs_fillfs(); message("Filled file system\n"); message(" Number of files: %d\n", g_nfiles); @@ -750,7 +861,7 @@ int user_start(int argc, char *argv[]) /* Delete some files */ - message("=== DELETING %d ============================\n", i); + message("\n=== DELETING %d ============================\n", i); ret = nxffs_delfiles(); if (ret < 0) { @@ -788,9 +899,17 @@ int user_start(int argc, char *argv[]) #endif } + /* Show memory usage */ + + nxffs_loopmemusage(); msgflush(); } + /* Delete all files then show memory usage again */ + + nxffs_delallfiles(); + nxffs_endmemusage(); + msgflush(); return 0; } |