IndexedDB: Histogram available disk space on attempt to open database
authordgrogan@chromium.org <dgrogan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2013 04:03:27 +0000 (04:03 +0000)
committerdgrogan@chromium.org <dgrogan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2013 04:03:27 +0000 (04:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112862

Reviewed by Adam Barth.

Source/Platform:

* chromium/public/Platform.h:
(WebKit::Platform::availableDiskSpaceInBytes):
(Platform):

Source/WebCore:

ChromeOS suspects they might be hitting disk corruption when the disks
are nearly full. This patch logs the available space to either the
"success" or the "fail" histogram as appropriate so that the
distributions can be compared.

No new tests - I don't know of a good way to test histograms. Local
printf testing didn't turn up any bugs.

* platform/leveldb/LevelDBDatabase.cpp:
(WebCore::HistogramFreeSpace):
(WebCore):
(WebCore::LevelDBDatabase::open):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146560 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/Platform/ChangeLog
Source/Platform/chromium/public/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/platform/leveldb/LevelDBDatabase.cpp

index 9194d30..c3bf4d9 100644 (file)
@@ -1,3 +1,14 @@
+2013-03-21  David Grogan  <dgrogan@chromium.org>
+
+        IndexedDB: Histogram available disk space on attempt to open database
+        https://bugs.webkit.org/show_bug.cgi?id=112862
+
+        Reviewed by Adam Barth.
+
+        * chromium/public/Platform.h:
+        (WebKit::Platform::availableDiskSpaceInBytes):
+        (Platform):
+
 2013-03-21  Mark Pilgrim  <pilgrim@chromium.org>
 
         [Chromium] Removed unused WEBKIT_USE_NEW_WEBFILESYSTEMTYPE flag
index f2a9113..9f5284c 100644 (file)
@@ -359,6 +359,9 @@ public:
     // Callable from a background WebKit thread.
     virtual void callOnMainThread(void (*func)(void*), void* context) { }
 
+    // Checks the partition/volume where fileName resides.
+    virtual long long availableDiskSpaceInBytes(const WebString& fileName) { return 0; }
+
 
     // Testing -------------------------------------------------------------
 
index 30bbf33..7d9f1cd 100644 (file)
@@ -1,3 +1,23 @@
+2013-03-21  David Grogan  <dgrogan@chromium.org>
+
+        IndexedDB: Histogram available disk space on attempt to open database
+        https://bugs.webkit.org/show_bug.cgi?id=112862
+
+        Reviewed by Adam Barth.
+
+        ChromeOS suspects they might be hitting disk corruption when the disks
+        are nearly full. This patch logs the available space to either the
+        "success" or the "fail" histogram as appropriate so that the
+        distributions can be compared.
+
+        No new tests - I don't know of a good way to test histograms. Local
+        printf testing didn't turn up any bugs.
+
+        * platform/leveldb/LevelDBDatabase.cpp:
+        (WebCore::HistogramFreeSpace):
+        (WebCore):
+        (WebCore::LevelDBDatabase::open):
+
 2013-03-21  Li Yin  <li.yin@intel.com>
 
         FileAPI: Remove deprecation warning when ArrayBuffer is in Blob constructor.
index 7f90f45..fdb2a3c 100644 (file)
@@ -46,6 +46,7 @@
 
 #if PLATFORM(CHROMIUM)
 #include <env_idb.h>
+#include <public/Platform.h>
 #endif
 
 #if !PLATFORM(CHROMIUM)
@@ -142,6 +143,22 @@ bool LevelDBDatabase::destroy(const String& fileName)
     return s.ok();
 }
 
+static void histogramFreeSpace(const char* type, String fileName)
+{
+#if PLATFORM(CHROMIUM)
+    String name = "WebCore.IndexedDB.LevelDB.Open" + String(type) + "FreeDiskSpace";
+    long long freeDiskSpaceInKBytes = WebKit::Platform::current()->availableDiskSpaceInBytes(fileName) / 1024;
+    if (freeDiskSpaceInKBytes < 0) {
+        HistogramSupport::histogramEnumeration("WebCore.IndexedDB.LevelDB.FreeDiskSpaceFailure", 1, 1);
+        return;
+    }
+    int clampedDiskSpaceKBytes = freeDiskSpaceInKBytes > INT_MAX ? INT_MAX : freeDiskSpaceInKBytes;
+    const uint64_t histogramMax = static_cast<uint64_t>(1e9);
+    COMPILE_ASSERT(histogramMax <= INT_MAX, histogramMaxTooBig);
+    HistogramSupport::histogramCustomCounts(name.utf8().data(), clampedDiskSpaceKBytes, 1, histogramMax, 11/*buckets*/);
+#endif
+}
+
 PassOwnPtr<LevelDBDatabase> LevelDBDatabase::open(const String& fileName, const LevelDBComparator* comparator)
 {
     OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter(comparator));
@@ -166,10 +183,14 @@ PassOwnPtr<LevelDBDatabase> LevelDBDatabase::open(const String& fileName, const
             levelDBError = LevelDBIOError;
         HistogramSupport::histogramEnumeration("WebCore.IndexedDB.LevelDBOpenErrors", levelDBError, LevelDBMaxError);
 
+        histogramFreeSpace("Failure", fileName);
+
         LOG_ERROR("Failed to open LevelDB database from %s: %s", fileName.ascii().data(), s.ToString().c_str());
         return nullptr;
     }
 
+    histogramFreeSpace("Success", fileName);
+
     OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase);
     result->m_db = adoptPtr(db);
     result->m_comparatorAdapter = comparatorAdapter.release();