bmaptool: print useful information in sace of MemoryError
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 21 Feb 2013 09:56:25 +0000 (11:56 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 21 Feb 2013 10:12:29 +0000 (12:12 +0200)
Catch the MemoryError exception which means that the script ran out of memory
and print useful debugging information in this case (/proc/meminfo and
/proc/self/status).

Change-Id: Ie52b8426867366d5a5110f91f8731c8c9b3b7f54
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptool

index 90cb0ec..308a7f5 100755 (executable)
--- a/bmaptool
+++ b/bmaptool
@@ -40,6 +40,7 @@ import os
 import stat
 import time
 import logging
+import traceback
 from bmaptools import BmapCreate, BmapCopy, BmapHelpers, TransRead
 
 def copy_command_open_blkdev(path, log):
@@ -366,7 +367,23 @@ def main():
     else:
         loglevel = logging.INFO
 
-    args.func(args, setup_logger(loglevel))
+    log = setup_logger(loglevel)
+
+    try:
+        args.func(args, log)
+    except MemoryError:
+        log.error("Out of memory!")
+        traceback.print_exc()
+
+        log.info("The contents of /proc/meminfo:")
+        with open('/proc/meminfo', 'rt') as file_obj:
+            for line in file_obj:
+                print line,
+
+        log.info("The contents of /proc/self/status:")
+        with open('/proc/self/status', 'rt') as file_obj:
+            for line in file_obj:
+                print line,
 
 if __name__ == "__main__":
     sys.exit(main())