OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sql/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
16 #include "base/debug/dump_without_crashing.h" | 16 #include "base/debug/dump_without_crashing.h" |
| 17 #include "base/feature_list.h" |
17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
19 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
20 #include "base/json/json_file_value_serializer.h" | 21 #include "base/json/json_file_value_serializer.h" |
21 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
22 #include "base/location.h" | 23 #include "base/location.h" |
23 #include "base/logging.h" | 24 #include "base/logging.h" |
24 #include "base/metrics/histogram_macros.h" | 25 #include "base/metrics/histogram_macros.h" |
25 #include "base/metrics/sparse_histogram.h" | 26 #include "base/metrics/sparse_histogram.h" |
26 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 222 } |
222 | 223 |
223 std::string AsUTF8ForSQL(const base::FilePath& path) { | 224 std::string AsUTF8ForSQL(const base::FilePath& path) { |
224 #if defined(OS_WIN) | 225 #if defined(OS_WIN) |
225 return base::WideToUTF8(path.value()); | 226 return base::WideToUTF8(path.value()); |
226 #elif defined(OS_POSIX) | 227 #elif defined(OS_POSIX) |
227 return path.value(); | 228 return path.value(); |
228 #endif | 229 #endif |
229 } | 230 } |
230 | 231 |
| 232 // http://crbug.com/698010 |
| 233 // |
| 234 // The feature enables a SQLite patch which causes SQLite to leverage |
| 235 // SQLITE_FCNTL_CHUNK_SIZE when making auto-vacuum decisions. This should lower |
| 236 // write load (histogram Sqlite.Vfs_Write in vfs_wrapper.cc). Only Android |
| 237 // enables auto-vacuum under Chromium. |
| 238 const base::Feature kSqliteSmartAutoVacuumEnabled{ |
| 239 "SqliteSmartAutoVacuum", base::FEATURE_DISABLED_BY_DEFAULT}; |
| 240 |
231 } // namespace | 241 } // namespace |
232 | 242 |
233 namespace sql { | 243 namespace sql { |
234 | 244 |
235 // static | 245 // static |
236 Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL; | 246 Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL; |
237 | 247 |
238 // static | 248 // static |
239 bool Connection::IsExpectedSqliteError(int error) { | 249 bool Connection::IsExpectedSqliteError(int error) { |
240 if (!current_expecter_cb_) | 250 if (!current_expecter_cb_) |
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 // databases (<20k) while other clients have a broad distribution of sizes | 1854 // databases (<20k) while other clients have a broad distribution of sizes |
1845 // (hundreds of kilobytes to many megabytes). | 1855 // (hundreds of kilobytes to many megabytes). |
1846 sqlite3_file* file = NULL; | 1856 sqlite3_file* file = NULL; |
1847 sqlite3_int64 db_size = 0; | 1857 sqlite3_int64 db_size = 0; |
1848 int rc = GetSqlite3FileAndSize(db_, &file, &db_size); | 1858 int rc = GetSqlite3FileAndSize(db_, &file, &db_size); |
1849 if (rc == SQLITE_OK && db_size > 16 * 1024) { | 1859 if (rc == SQLITE_OK && db_size > 16 * 1024) { |
1850 int chunk_size = 4 * 1024; | 1860 int chunk_size = 4 * 1024; |
1851 if (db_size > 128 * 1024) | 1861 if (db_size > 128 * 1024) |
1852 chunk_size = 32 * 1024; | 1862 chunk_size = 32 * 1024; |
1853 sqlite3_file_control(db_, NULL, SQLITE_FCNTL_CHUNK_SIZE, &chunk_size); | 1863 sqlite3_file_control(db_, NULL, SQLITE_FCNTL_CHUNK_SIZE, &chunk_size); |
| 1864 if (base::FeatureList::IsEnabled(kSqliteSmartAutoVacuumEnabled)) { |
| 1865 int page_size = 0; |
| 1866 { |
| 1867 sql::Statement stmt(GetUniqueStatement("PRAGMA page_size")); |
| 1868 if (stmt.Step()) |
| 1869 page_size = stmt.ColumnInt(0); |
| 1870 if (!page_size) |
| 1871 page_size = 1024; |
| 1872 } |
| 1873 std::string slack_sql = base::StringPrintf( |
| 1874 "PRAGMA auto_vacuum_slack_pages = %d", chunk_size / page_size); |
| 1875 ignore_result(Execute(slack_sql.c_str())); |
| 1876 } |
1854 } | 1877 } |
1855 | 1878 |
1856 // Enable memory-mapped access. The explicit-disable case is because SQLite | 1879 // Enable memory-mapped access. The explicit-disable case is because SQLite |
1857 // can be built to default-enable mmap. GetAppropriateMmapSize() calculates a | 1880 // can be built to default-enable mmap. GetAppropriateMmapSize() calculates a |
1858 // safe range to memory-map based on past regular I/O. This value will be | 1881 // safe range to memory-map based on past regular I/O. This value will be |
1859 // capped by SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and | 1882 // capped by SQLITE_MAX_MMAP_SIZE, which could be different between 32-bit and |
1860 // 64-bit platforms. | 1883 // 64-bit platforms. |
1861 size_t mmap_size = mmap_disabled_ ? 0 : GetAppropriateMmapSize(); | 1884 size_t mmap_size = mmap_disabled_ ? 0 : GetAppropriateMmapSize(); |
1862 std::string mmap_sql = | 1885 std::string mmap_sql = |
1863 base::StringPrintf("PRAGMA mmap_size = %" PRIuS, mmap_size); | 1886 base::StringPrintf("PRAGMA mmap_size = %" PRIuS, mmap_size); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 const std::string& dump_name) { | 2078 const std::string& dump_name) { |
2056 return memory_dump_provider_ && | 2079 return memory_dump_provider_ && |
2057 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); | 2080 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); |
2058 } | 2081 } |
2059 | 2082 |
2060 base::TimeTicks TimeSource::Now() { | 2083 base::TimeTicks TimeSource::Now() { |
2061 return base::TimeTicks::Now(); | 2084 return base::TimeTicks::Now(); |
2062 } | 2085 } |
2063 | 2086 |
2064 } // namespace sql | 2087 } // namespace sql |
OLD | NEW |