From 19f664281b4b8b113240a47577e8759761ce6e33 Mon Sep 17 00:00:00 2001 From: "Jason J. Gullickson" Date: Sat, 3 Jan 2015 10:37:24 -0600 Subject: [PATCH] generate and log basic system stats each time metadata is read or stored to disk --- jsfs2.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/jsfs2.js b/jsfs2.js index 7f4f010..c56924b 100644 --- a/jsfs2.js +++ b/jsfs2.js @@ -34,6 +34,9 @@ function save_metadata(){ log.message(log.INFO, "metadata saved to disk"); } }); + + var stats = system_stats(); + log.message(log.INFO, stats.file_count + " files stored in " + stats.block_count + " blocks"); } function load_metadata(){ @@ -43,6 +46,28 @@ function load_metadata(){ } catch(ex) { log.message(log.WARN, "unable to load metadata from disk: " + ex); } + + var stats = system_stats(); + log.message(log.INFO, stats.file_count + " files stored in " + stats.block_count + " blocks"); +} + +function system_stats(){ + + var stats = {}; + stats.file_count = 0; + stats.block_count = 0; + + for(var file in stored_files){ + if(stored_files.hasOwnProperty(file)){ + // count blocks + stats.block_count = stats.block_count + stored_files[file].blocks.length; + + // increment file count + stats.file_count++; + } + } + + return stats; } // simple encrypt-decrypt functions