Commit 3998fbc5 authored by shess's avatar shess Committed by Commit bot

[sql] Histograms for I/O calls seen by browser VFS.

Track the common VFS calls which do disk I/O, to help analyze the impact
of any changes to how database connections are used or setup.

BUG=698010

Review-Url: https://codereview.chromium.org/2727103003
Cr-Commit-Position: refs/heads/master@{#457099}
parent 9236e4f3
......@@ -11,6 +11,7 @@
#include "base/debug/leak_annotations.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_piece.h"
#if defined(OS_MACOSX) && !defined(OS_IOS)
......@@ -34,6 +35,54 @@ namespace {
// Idiomatic SQLite would take the wrapped VFS szOsFile and increase it to store
// additional data as a prefix.
// This enum must match the numbering from Sqlite.VfsEvents in histograms.xml.
// Do not reorder or remove items, only add new items before VFS_EVENT_MAX.
enum VfsEventType {
// VFS method xOpen() call.
VFS_OPEN = 0,
// VFS method xDelete() call.
VFS_DELETE,
// VFS method xAccess() call.
VFS_ACCESS,
// VFS method xFullPathname() call.
VFS_FULLPATHNAME,
// I/O method xClose() call, should balance VFS_OPEN.
VFS_IO_CLOSE,
// I/O method xRead() call.
VFS_IO_READ,
// I/O method xWrite() call.
VFS_IO_WRITE,
// I/O method xTruncate() call.
VFS_IO_TRUNCATE,
// I/O method xSync() call.
VFS_IO_SYNC,
// I/O method xFileSize() call.
VFS_IO_FILESIZE,
// I/O method xFetch() call. This is like xRead(), but when using
// memory-mapping.
VFS_IO_FETCH,
// Add new items before this one, always keep this one at the end.
VFS_EVENT_MAX
};
// TODO(shess): If the VFS was parameterized, then results could be binned by
// database. It would require a separate VFS per database, though the variants
// could all use the same VFS functions.
void RecordVfsEvent(VfsEventType vfs_event) {
UMA_HISTOGRAM_ENUMERATION("Sqlite.Vfs_Events", vfs_event, VFS_EVENT_MAX);
}
sqlite3_vfs* GetWrappedVfs(sqlite3_vfs* wrapped_vfs) {
return static_cast<sqlite3_vfs*>(wrapped_vfs->pAppData);
}
......@@ -56,6 +105,8 @@ sqlite3_file* GetWrappedFile(sqlite3_file* wrapper_file) {
int Close(sqlite3_file* sqlite_file)
{
RecordVfsEvent(VFS_IO_CLOSE);
VfsFile* file = AsVfsFile(sqlite_file);
int r = file->wrapped_file->pMethods->xClose(file->wrapped_file);
......@@ -66,6 +117,9 @@ int Close(sqlite3_file* sqlite_file)
int Read(sqlite3_file* sqlite_file, void* buf, int amt, sqlite3_int64 ofs)
{
RecordVfsEvent(VFS_IO_READ);
UMA_HISTOGRAM_COUNTS("Sqlite.Vfs_Read", amt);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xRead(wrapped_file, buf, amt, ofs);
}
......@@ -73,24 +127,33 @@ int Read(sqlite3_file* sqlite_file, void* buf, int amt, sqlite3_int64 ofs)
int Write(sqlite3_file* sqlite_file, const void* buf, int amt,
sqlite3_int64 ofs)
{
RecordVfsEvent(VFS_IO_WRITE);
UMA_HISTOGRAM_COUNTS("Sqlite.Vfs_Write", amt);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xWrite(wrapped_file, buf, amt, ofs);
}
int Truncate(sqlite3_file* sqlite_file, sqlite3_int64 size)
{
RecordVfsEvent(VFS_IO_TRUNCATE);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xTruncate(wrapped_file, size);
}
int Sync(sqlite3_file* sqlite_file, int flags)
{
RecordVfsEvent(VFS_IO_SYNC);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xSync(wrapped_file, flags);
}
int FileSize(sqlite3_file* sqlite_file, sqlite3_int64* size)
{
RecordVfsEvent(VFS_IO_FILESIZE);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xFileSize(wrapped_file, size);
}
......@@ -154,6 +217,9 @@ int ShmUnmap(sqlite3_file *sqlite_file, int del) {
}
int Fetch(sqlite3_file *sqlite_file, sqlite3_int64 off, int amt, void **pp) {
RecordVfsEvent(VFS_IO_FETCH);
UMA_HISTOGRAM_COUNTS("Sqlite.Vfs_Fetch", amt);
sqlite3_file* wrapped_file = GetWrappedFile(sqlite_file);
return wrapped_file->pMethods->xFetch(wrapped_file, off, amt, pp);
}
......@@ -177,6 +243,8 @@ base::ScopedCFTypeRef<CFURLRef> CFURLRefForPath(const char* path){
int Open(sqlite3_vfs* vfs, const char* file_name, sqlite3_file* wrapper_file,
int desired_flags, int* used_flags) {
RecordVfsEvent(VFS_OPEN);
sqlite3_vfs* wrapped_vfs = GetWrappedVfs(vfs);
sqlite3_file* wrapped_file = static_cast<sqlite3_file*>(
......@@ -298,17 +366,23 @@ int Open(sqlite3_vfs* vfs, const char* file_name, sqlite3_file* wrapper_file,
}
int Delete(sqlite3_vfs* vfs, const char* file_name, int sync_dir) {
RecordVfsEvent(VFS_DELETE);
sqlite3_vfs* wrapped_vfs = GetWrappedVfs(vfs);
return wrapped_vfs->xDelete(wrapped_vfs, file_name, sync_dir);
}
int Access(sqlite3_vfs* vfs, const char* file_name, int flag, int* res) {
RecordVfsEvent(VFS_ACCESS);
sqlite3_vfs* wrapped_vfs = GetWrappedVfs(vfs);
return wrapped_vfs->xAccess(wrapped_vfs, file_name, flag, res);
}
int FullPathname(sqlite3_vfs* vfs, const char* relative_path,
int buf_size, char* absolute_path) {
RecordVfsEvent(VFS_FULLPATHNAME);
sqlite3_vfs* wrapped_vfs = GetWrappedVfs(vfs);
return wrapped_vfs->xFullPathname(
wrapped_vfs, relative_path, buf_size, absolute_path);
......
......@@ -67095,6 +67095,20 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<summary>Version of pre-existing database at startup.</summary>
</histogram>
<histogram name="Sqlite.Vfs" units="bytes">
<owner>shess@chromium.org</owner>
<summary>
Buffer sizes passed to browser-process SQLite VFS functions.
</summary>
</histogram>
<histogram name="Sqlite.Vfs_Events" enum="SqliteVfsEvents">
<owner>shess@chromium.org</owner>
<summary>
I/O operations measured by browser-process SQLite VFS wrapper.
</summary>
</histogram>
<histogram name="Sqlite.Web.Error" enum="SqliteErrorCode">
<obsolete>
Moved to Sqlite.Error.Web in M-27.
......@@ -110355,6 +110369,21 @@ from previous Chrome versions.
<int value="5" label="DEPRECATION_RAZE_FAILED">Raze failed.</int>
</enum>
<enum name="SqliteVfsEvents" type="int">
<summary>I/O events from browser-process SQLite VFS wrapper.</summary>
<int value="0" label="VFS_OPEN">Calls to xOpen().</int>
<int value="1" label="VFS_DELETE">Calls to xDelete().</int>
<int value="2" label="VFS_ACCESS">Calls to xAccess().</int>
<int value="3" label="VFS_FULLPATHNAME">Calls to xFullPath().</int>
<int value="4" label="VFS_IO_CLOSE">Calls to xClose().</int>
<int value="5" label="VFS_IO_READ">Calls to xRead().</int>
<int value="6" label="VFS_IO_WRITE">Calls to xWrite().</int>
<int value="7" label="VFS_IO_TRUNCATE">Calls to xTruncate().</int>
<int value="8" label="VFS_IO_SYNC">Calls to xSync().</int>
<int value="9" label="VFS_IO_FILESIZE">Calls to xFileSize().</int>
<int value="10" label="VFS_IO_FETCH">Calls to xFetch().</int>
</enum>
<enum name="SRIResourceIntegrityMismatchEvent" type="int">
<int value="0" label="CHECKING_FOR_INTEGRITY_MISMATCH"/>
<int value="1" label="REFETCH_DUE_TO_INTEGRITY_MISMATCH"/>
......@@ -122201,6 +122230,14 @@ from previous Chrome versions.
<affected-histogram name="Sqlite.Version"/>
</histogram_suffixes>
<histogram_suffixes name="SqliteVfsOperations" separator="_">
<owner>shess@chromium.org</owner>
<suffix name="Fetch" label="fetch"/>
<suffix name="Read" label="read"/>
<suffix name="Write" label="write"/>
<affected-histogram name="Sqlite.Vfs"/>
</histogram_suffixes>
<histogram_suffixes name="SSLFalseStart">
<obsolete>
Removed 2011-06-01.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment