diff options
author | dgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-03 17:14:17 +0000 |
---|---|---|
committer | dgrogan@chromium.org <dgrogan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-03 17:14:17 +0000 |
commit | 2516355ad7f3609214a049e0740c7bc4847eea30 (patch) | |
tree | 6357786b64b136fc2b19b8fa1dac2bf7125d7b57 /third_party/leveldatabase/env_chromium.cc | |
parent | 29aba2a8a0353bdc092c9c05db40185b1ca36f7e (diff) | |
download | chromium_src-2516355ad7f3609214a049e0740c7bc4847eea30.zip chromium_src-2516355ad7f3609214a049e0740c7bc4847eea30.tar.gz chromium_src-2516355ad7f3609214a049e0740c7bc4847eea30.tar.bz2 |
Histogram system's open file limit from LevelDB.
Some IDB users are running into the open file limit on Mac and CrOS.
BUG=197371
R=isherman@chromium.org, jsbell@chromium.org
Review URL: https://codereview.chromium.org/14198005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198134 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/leveldatabase/env_chromium.cc')
-rw-r--r-- | third_party/leveldatabase/env_chromium.cc | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc index 35a37a4..b14fc01 100644 --- a/third_party/leveldatabase/env_chromium.cc +++ b/third_party/leveldatabase/env_chromium.cc @@ -34,8 +34,10 @@ #include "base/win/win_util.h" #endif -#if !defined(OS_WIN) +#if defined(OS_POSIX) #include <fcntl.h> +#include <sys/resource.h> +#include <sys/time.h> #endif namespace { @@ -397,6 +399,15 @@ class ChromiumEnv : public Env, public UMALogger { } } + void RecordOpenFilesLimit(const std::string& type) { +#if defined(OS_POSIX) + struct rlimit nofile; + if (getrlimit(RLIMIT_NOFILE, &nofile)) + return; + GetMaxFDHistogram(type)->Add(nofile.rlim_cur); +#endif + } + virtual Status NewRandomAccessFile(const std::string& fname, RandomAccessFile** result) { int flags = ::base::PLATFORM_FILE_READ | ::base::PLATFORM_FILE_OPEN; @@ -404,13 +415,18 @@ class ChromiumEnv : public Env, public UMALogger { ::base::PlatformFileError error_code; ::base::PlatformFile file = ::base::CreatePlatformFile( CreateFilePath(fname), flags, &created, &error_code); - if (error_code != ::base::PLATFORM_FILE_OK) { - *result = NULL; - RecordOSError(kNewRandomAccessFile, error_code); - return Status::IOError(fname, PlatformFileErrorString(error_code)); + if (error_code == ::base::PLATFORM_FILE_OK) { + *result = new ChromiumRandomAccessFile(fname, file, this); + RecordOpenFilesLimit("Success"); + return Status::OK(); } - *result = new ChromiumRandomAccessFile(fname, file, this); - return Status::OK(); + if (error_code == ::base::PLATFORM_FILE_ERROR_TOO_MANY_OPENED) + RecordOpenFilesLimit("TooManyOpened"); + else + RecordOpenFilesLimit("OtherError"); + *result = NULL; + RecordOSError(kNewRandomAccessFile, error_code); + return Status::IOError(fname, PlatformFileErrorString(error_code)); } virtual Status NewWritableFile(const std::string& fname, @@ -675,6 +691,7 @@ class ChromiumEnv : public Env, public UMALogger { base::HistogramBase* GetOSErrorHistogram(MethodID method, int limit) const; base::HistogramBase* GetRetryTimeHistogram(MethodID method) const; base::HistogramBase* GetMethodIOErrorHistogram() const; + base::HistogramBase* GetMaxFDHistogram(const std::string& type); base::FilePath test_directory_; size_t page_size_; @@ -727,6 +744,19 @@ base::HistogramBase* ChromiumEnv::GetMethodIOErrorHistogram() const { kNumEntries + 1, base::Histogram::kUmaTargetedHistogramFlag); } +base::HistogramBase* ChromiumEnv::GetMaxFDHistogram( + const std::string& type) { + std::string uma_name(name_); + uma_name.append(".MaxFDs.").append(type); + // These numbers make each bucket twice as large as the previous bucket. + const int kFirstEntry = 1; + const int kLastEntry = 65536; + const int kNumBuckets = 18; + return base::Histogram::FactoryGet( + uma_name, kFirstEntry, kLastEntry, kNumBuckets, + base::Histogram::kUmaTargetedHistogramFlag); +} + class Thread : public ::base::PlatformThread::Delegate { public: Thread(void (*function)(void* arg), void* arg) |