OLD | NEW |
---|---|
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. See the AUTHORS file for names of contributors. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
4 | 4 |
5 #include "third_party/leveldatabase/env_chromium.h" | 5 #include "third_party/leveldatabase/env_chromium.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #endif | 10 #endif |
11 | 11 |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/stringprintf.h" | |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "third_party/leveldatabase/chromium_logger.h" | 21 #include "third_party/leveldatabase/chromium_logger.h" |
21 #include "third_party/re2/re2/re2.h" | 22 #include "third_party/re2/re2/re2.h" |
22 | 23 |
23 using base::FilePath; | 24 using base::FilePath; |
24 using leveldb::FileLock; | 25 using leveldb::FileLock; |
25 using leveldb::Slice; | 26 using leveldb::Slice; |
26 using leveldb::Status; | 27 using leveldb::Status; |
27 | 28 |
28 namespace leveldb_env { | 29 namespace leveldb_env { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 if (make_backup_ && file_type_ == kTable) | 320 if (make_backup_ && file_type_ == kTable) |
320 uma_logger_->RecordBackupResult(ChromiumEnv::MakeBackup(filename_)); | 321 uma_logger_->RecordBackupResult(ChromiumEnv::MakeBackup(filename_)); |
321 | 322 |
322 return Status::OK(); | 323 return Status::OK(); |
323 } | 324 } |
324 | 325 |
325 class IDBEnv : public ChromiumEnv { | 326 class IDBEnv : public ChromiumEnv { |
326 public: | 327 public: |
327 IDBEnv() : ChromiumEnv() { | 328 IDBEnv() : ChromiumEnv() { |
328 name_ = "LevelDBEnv.IDB"; | 329 name_ = "LevelDBEnv.IDB"; |
330 uma_ioerror_base_name_ = name_ + ".IOError.PFE"; | |
329 make_backup_ = true; | 331 make_backup_ = true; |
330 } | 332 } |
331 }; | 333 }; |
332 | 334 |
333 base::LazyInstance<IDBEnv>::Leaky idb_env = LAZY_INSTANCE_INITIALIZER; | 335 base::LazyInstance<IDBEnv>::Leaky idb_env = LAZY_INSTANCE_INITIALIZER; |
334 | 336 |
335 base::LazyInstance<ChromiumEnv>::Leaky default_env = LAZY_INSTANCE_INITIALIZER; | 337 base::LazyInstance<ChromiumEnv>::Leaky default_env = LAZY_INSTANCE_INITIALIZER; |
336 | 338 |
337 } // unnamed namespace | 339 } // unnamed namespace |
338 | 340 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 original_table_name.ReplaceExtension(backup_table_extension); | 524 original_table_name.ReplaceExtension(backup_table_extension); |
523 return base::CopyFile(original_table_name, backup_table_name); | 525 return base::CopyFile(original_table_name, backup_table_name); |
524 } | 526 } |
525 | 527 |
526 ChromiumEnv::ChromiumEnv() | 528 ChromiumEnv::ChromiumEnv() |
527 : name_("LevelDBEnv"), | 529 : name_("LevelDBEnv"), |
528 make_backup_(false), | 530 make_backup_(false), |
529 bgsignal_(&mu_), | 531 bgsignal_(&mu_), |
530 started_bgthread_(false), | 532 started_bgthread_(false), |
531 kMaxRetryTimeMillis(1000) { | 533 kMaxRetryTimeMillis(1000) { |
534 uma_ioerror_base_name_ = name_ + ".IOError.PFE"; | |
dgrogan
2015/01/21 01:47:56
maybe use bFE to indicate base::File::Error instea
cmumford
2015/02/13 22:15:52
I started with that originally, but eventually got
| |
532 } | 535 } |
533 | 536 |
534 ChromiumEnv::~ChromiumEnv() { | 537 ChromiumEnv::~ChromiumEnv() { |
535 // In chromium, ChromiumEnv is leaked. It'd be nice to add NOTREACHED here to | 538 // In chromium, ChromiumEnv is leaked. It'd be nice to add NOTREACHED here to |
536 // ensure that behavior isn't accidentally changed, but there's an instance in | 539 // ensure that behavior isn't accidentally changed, but there's an instance in |
537 // a unit test that is deleted. | 540 // a unit test that is deleted. |
538 } | 541 } |
539 | 542 |
540 bool ChromiumEnv::FileExists(const std::string& fname) { | 543 bool ChromiumEnv::FileExists(const std::string& fname) { |
541 return base::PathExists(FilePath::FromUTF8Unsafe(fname)); | 544 return base::PathExists(FilePath::FromUTF8Unsafe(fname)); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 | 927 |
925 void ChromiumEnv::RecordBackupResult(bool result) const { | 928 void ChromiumEnv::RecordBackupResult(bool result) const { |
926 std::string uma_name(name_); | 929 std::string uma_name(name_); |
927 uma_name.append(".TableBackup"); | 930 uma_name.append(".TableBackup"); |
928 base::BooleanHistogram::FactoryGet( | 931 base::BooleanHistogram::FactoryGet( |
929 uma_name, base::Histogram::kUmaTargetedHistogramFlag)->AddBoolean(result); | 932 uma_name, base::Histogram::kUmaTargetedHistogramFlag)->AddBoolean(result); |
930 } | 933 } |
931 | 934 |
932 base::HistogramBase* ChromiumEnv::GetOSErrorHistogram(MethodID method, | 935 base::HistogramBase* ChromiumEnv::GetOSErrorHistogram(MethodID method, |
933 int limit) const { | 936 int limit) const { |
934 std::string uma_name(name_); | 937 std::string uma_name; |
935 // TODO(dgrogan): This is probably not the best way to concatenate strings. | 938 base::StringAppendF(&uma_name, "%s.%s", uma_ioerror_base_name_.c_str(), |
936 uma_name.append(".IOError.").append(MethodIDToString(method)); | 939 MethodIDToString(method)); |
937 return base::LinearHistogram::FactoryGet(uma_name, 1, limit, limit + 1, | 940 return base::LinearHistogram::FactoryGet(uma_name, 1, limit, limit + 1, |
938 base::Histogram::kUmaTargetedHistogramFlag); | 941 base::Histogram::kUmaTargetedHistogramFlag); |
939 } | 942 } |
940 | 943 |
941 base::HistogramBase* ChromiumEnv::GetMethodIOErrorHistogram() const { | 944 base::HistogramBase* ChromiumEnv::GetMethodIOErrorHistogram() const { |
942 std::string uma_name(name_); | 945 return base::LinearHistogram::FactoryGet( |
943 uma_name.append(".IOError"); | 946 uma_ioerror_base_name_, 1, kNumEntries, kNumEntries + 1, |
944 return base::LinearHistogram::FactoryGet(uma_name, 1, kNumEntries, | 947 base::Histogram::kUmaTargetedHistogramFlag); |
945 kNumEntries + 1, base::Histogram::kUmaTargetedHistogramFlag); | |
946 } | 948 } |
947 | 949 |
948 base::HistogramBase* ChromiumEnv::GetMaxFDHistogram( | 950 base::HistogramBase* ChromiumEnv::GetMaxFDHistogram( |
949 const std::string& type) const { | 951 const std::string& type) const { |
950 std::string uma_name(name_); | 952 std::string uma_name(name_); |
951 uma_name.append(".MaxFDs.").append(type); | 953 uma_name.append(".MaxFDs.").append(type); |
952 // These numbers make each bucket twice as large as the previous bucket. | 954 // These numbers make each bucket twice as large as the previous bucket. |
953 const int kFirstEntry = 1; | 955 const int kFirstEntry = 1; |
954 const int kLastEntry = 65536; | 956 const int kLastEntry = 65536; |
955 const int kNumBuckets = 18; | 957 const int kNumBuckets = 18; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1084 | 1086 |
1085 Env* IDBEnv() { | 1087 Env* IDBEnv() { |
1086 return leveldb_env::idb_env.Pointer(); | 1088 return leveldb_env::idb_env.Pointer(); |
1087 } | 1089 } |
1088 | 1090 |
1089 Env* Env::Default() { | 1091 Env* Env::Default() { |
1090 return leveldb_env::default_env.Pointer(); | 1092 return leveldb_env::default_env.Pointer(); |
1091 } | 1093 } |
1092 | 1094 |
1093 } // namespace leveldb | 1095 } // namespace leveldb |
OLD | NEW |