Test first integration of UMA plumbing

Add a first example of a UMA entry to have it available to try to plumb
through to Chromium.

Adds LoggingFileSizeByHandle() to util/file/file_io.* to retrieve the
size of on disk file to report to UMA.

Also rolls DEPS for mini_chromium to include:
b5ec9ce Add stub versions of histogram_macros.h

R=mark@chromium.org
BUG=crashpad:100

Change-Id: Ib8e96ad4b7d715b46d2c71810c95c92965a89821
Reviewed-on: https://chromium-review.googlesource.com/338821
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Scott Graham 2016-09-01 17:01:31 -07:00
parent c6f88d164e
commit 5f42313ed5
7 changed files with 56 additions and 1 deletions

2
DEPS
View File

@ -25,7 +25,7 @@ deps = {
'93cc6e2c23e4d5ebd179f388e67aa907d0dfd43d',
'crashpad/third_party/mini_chromium/mini_chromium':
Var('chromium_git') + '/chromium/mini_chromium@' +
'87f575d65c4700accac3b546ede66116c438ced1',
'b5ec9ce232a3a9d97e438ee38e27d65b5efbe1de',
'buildtools':
Var('chromium_git') + '/chromium/buildtools.git@' +
'f8fc76ea5ce4a60cda2fa5d7df3d4a62935b3113',

View File

@ -26,6 +26,7 @@
#include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/metrics/histogram_macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/scoped_generic.h"
#include "base/strings/string_piece.h"
@ -358,6 +359,9 @@ CrashReportDatabaseMac::FinishedWritingCrashReport(NewReport* report,
return kFileSystemError;
}
UMA_HISTOGRAM_MEMORY_KB("Crashpad.CrashReportSizeKB",
LoggingFileSizeByHandle(handle.get()) / 1024);
return kNoError;
}

View File

@ -24,6 +24,7 @@
#include <utility>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
@ -677,6 +678,10 @@ OperationStatus CrashReportDatabaseWin::FinishedWritingCrashReport(
time(nullptr),
ReportState::kPending));
*uuid = scoped_report->uuid;
UMA_HISTOGRAM_MEMORY_KB("Crashpad.CrashReportSizeKB",
LoggingFileSizeByHandle(handle.get()) / 1024);
return kNoError;
}

View File

@ -342,6 +342,15 @@ bool LoggingCloseFile(FileHandle file);
//! terminate without returning.
void CheckedCloseFile(FileHandle file);
//! \brief Determines the size of a file.
//!
//! \param[in] file The handle to the file for which the size should be
//! retrived.
//!
//! \return The size of the file. If an error occurs when attempting to
//! determine its size, returns `-1` with an error logged.
FileOffset LoggingFileSizeByHandle(FileHandle file);
} // namespace crashpad
#endif // CRASHPAD_UTIL_FILE_FILE_IO_H_

View File

@ -16,6 +16,7 @@
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <unistd.h>
#include "base/files/file_path.h"
@ -187,4 +188,13 @@ bool LoggingCloseFile(FileHandle file) {
return rv == 0;
}
FileOffset LoggingFileSizeByHandle(FileHandle file) {
struct stat st;
if (fstat(file, &st) != 0) {
PLOG(ERROR) << "fstat";
return -1;
}
return st.st_size;
}
} // namespace crashpad

View File

@ -306,6 +306,24 @@ TEST(FileIO, SharedVsExclusives) {
LockingTest(FileLocking::kShared, FileLocking::kExclusive);
}
TEST(FileIO, FileSizeByHandle) {
EXPECT_EQ(-1, LoggingFileSizeByHandle(kInvalidFileHandle));
ScopedTempDir temp_dir;
base::FilePath file_path =
temp_dir.path().Append(FILE_PATH_LITERAL("file_size"));
ScopedFileHandle file_handle(LoggingOpenFileForWrite(
file_path, FileWriteMode::kCreateOrFail, FilePermissions::kOwnerOnly));
ASSERT_NE(kInvalidFileHandle, file_handle.get());
EXPECT_EQ(0, LoggingFileSizeByHandle(file_handle.get()));
const char data[] = "zippyzap";
ASSERT_TRUE(LoggingWriteFile(file_handle.get(), &data, sizeof(data)));
EXPECT_EQ(9, LoggingFileSizeByHandle(file_handle.get()));
}
} // namespace
} // namespace test
} // namespace crashpad

View File

@ -236,4 +236,13 @@ bool LoggingCloseFile(FileHandle file) {
return !!rv;
}
FileOffset LoggingFileSizeByHandle(FileHandle file) {
LARGE_INTEGER file_size;
if (!GetFileSizeEx(file, &file_size)) {
PLOG(ERROR) << "GetFileSizeEx";
return -1;
}
return file_size.QuadPart;
}
} // namespace crashpad