diff --git a/DEPS b/DEPS index 0af9d520..47db5a3d 100644 --- a/DEPS +++ b/DEPS @@ -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', diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index 9799bb0f..3434a22a 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -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; } diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index c0bc42b8..cbef0cc1 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -24,6 +24,7 @@ #include #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; } diff --git a/util/file/file_io.h b/util/file/file_io.h index 55909415..ff20488d 100644 --- a/util/file/file_io.h +++ b/util/file/file_io.h @@ -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_ diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc index ce08a396..30eae539 100644 --- a/util/file/file_io_posix.cc +++ b/util/file/file_io_posix.cc @@ -16,6 +16,7 @@ #include #include +#include #include #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 diff --git a/util/file/file_io_test.cc b/util/file/file_io_test.cc index 27ffd310..b8444d41 100644 --- a/util/file/file_io_test.cc +++ b/util/file/file_io_test.cc @@ -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 diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc index def2a5a2..5144869e 100644 --- a/util/file/file_io_win.cc +++ b/util/file/file_io_win.cc @@ -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