From 79e0bbb3d773037371ff83563aba8ebdb20190e8 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 17 Nov 2010 09:49:39 +0000 Subject: Log the total number of bytes uploaded to the server for each file. --- bin/bbackupd/BackupClientDirectoryRecord.cpp | 14 ++++++++++++-- bin/bbackupd/BackupDaemon.h | 6 ++++-- bin/bbackupd/BackupDaemonInterface.h | 2 +- lib/backupclient/BackupStoreFile.cpp | 8 +++++--- lib/backupclient/BackupStoreFile.h | 7 +++++-- lib/backupclient/BackupStoreFileEncodeStream.cpp | 2 ++ lib/backupclient/BackupStoreFileEncodeStream.h | 2 ++ 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp index 84c17dab..a555085f 100644 --- a/bin/bbackupd/BackupClientDirectoryRecord.cpp +++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp @@ -17,9 +17,10 @@ #include #include -#include "BackupClientDirectoryRecord.h" #include "autogen_BackupProtocolClient.h" +#include "BackupClientDirectoryRecord.h" #include "BackupClientContext.h" +#include "BackupStoreFileEncodeStream.h" #include "IOStream.h" #include "MemBlockStream.h" #include "CommonException.h" @@ -1513,6 +1514,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( // Info int64_t objID = 0; bool doNormalUpload = true; + int64_t uploadedSize = -1; // Use a try block to catch store full errors try @@ -1543,6 +1545,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( rContext.ManageDiffProcess(); bool isCompletelyDifferent = false; + std::auto_ptr patchStream( BackupStoreFile::EncodeFileDiff( rFilename.c_str(), @@ -1566,6 +1569,10 @@ int64_t BackupClientDirectoryRecord::UploadFile( // Don't attempt to upload it again! doNormalUpload = false; + + // Capture number of bytes sent + uploadedSize = ((BackupStoreFileEncodeStream &) + *patchStream).GetTotalBytesSent(); } } @@ -1591,6 +1598,9 @@ int64_t BackupClientDirectoryRecord::UploadFile( // Get object ID from the result objID = stored->GetObjectID(); + + uploadedSize = ((BackupStoreFileEncodeStream &) + *upload).GetTotalBytesSent(); } } catch(BoxException &e) @@ -1625,7 +1635,7 @@ int64_t BackupClientDirectoryRecord::UploadFile( throw; } - rNotifier.NotifyFileUploaded(this, rFilename, FileSize); + rNotifier.NotifyFileUploaded(this, rFilename, FileSize, uploadedSize); // Return the new object ID of this file return objID; diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h index b41c6508..be37cd11 100644 --- a/bin/bbackupd/BackupDaemon.h +++ b/bin/bbackupd/BackupDaemon.h @@ -457,11 +457,13 @@ public: virtual void NotifyFileUploaded( const BackupClientDirectoryRecord* pDirRecord, const std::string& rLocalPath, - int64_t FileSize) + int64_t FileSize, int64_t UploadedSize) { if (mLogAllFileAccess) { - BOX_NOTICE("Uploaded file: " << rLocalPath); + BOX_NOTICE("Uploaded file: " << rLocalPath << ", " + "total size = " << FileSize << ", " + "uploaded size = " << UploadedSize); } } virtual void NotifyFileSynchronised( diff --git a/bin/bbackupd/BackupDaemonInterface.h b/bin/bbackupd/BackupDaemonInterface.h index 2a2d8d4b..b603273c 100644 --- a/bin/bbackupd/BackupDaemonInterface.h +++ b/bin/bbackupd/BackupDaemonInterface.h @@ -129,7 +129,7 @@ class ProgressNotifier virtual void NotifyFileUploaded( const BackupClientDirectoryRecord* pDirRecord, const std::string& rLocalPath, - int64_t FileSize) = 0; + int64_t FileSize, int64_t UploadedSize) = 0; virtual void NotifyFileSynchronised( const BackupClientDirectoryRecord* pDirRecord, const std::string& rLocalPath, diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 4bd75f96..44d96d0c 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -73,9 +73,11 @@ BackupStoreFileStats BackupStoreFile::msStats = {0,0,0}; // Created: 2003/08/28 // // -------------------------------------------------------------------------- -std::auto_ptr BackupStoreFile::EncodeFile(const char *Filename, - int64_t ContainerID, const BackupStoreFilename &rStoreFilename, - int64_t *pModificationTime, ReadLoggingStream::Logger* pLogger, +std::auto_ptr BackupStoreFile::EncodeFile( + const char *Filename, int64_t ContainerID, + const BackupStoreFilename &rStoreFilename, + int64_t *pModificationTime, + ReadLoggingStream::Logger* pLogger, RunStatusProvider* pRunStatusProvider) { // Create the stream diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h index f4c60919..f5bc1924 100644 --- a/lib/backupclient/BackupStoreFile.h +++ b/lib/backupclient/BackupStoreFile.h @@ -118,11 +118,14 @@ public: // Main interface - static std::auto_ptr EncodeFile(const char *Filename, + static std::auto_ptr EncodeFile + ( + const char *Filename, int64_t ContainerID, const BackupStoreFilename &rStoreFilename, int64_t *pModificationTime = 0, ReadLoggingStream::Logger* pLogger = NULL, - RunStatusProvider* pRunStatusProvider = NULL); + RunStatusProvider* pRunStatusProvider = NULL + ); static std::auto_ptr EncodeFileDiff ( const char *Filename, int64_t ContainerID, diff --git a/lib/backupclient/BackupStoreFileEncodeStream.cpp b/lib/backupclient/BackupStoreFileEncodeStream.cpp index 54c2463d..e9d773f0 100644 --- a/lib/backupclient/BackupStoreFileEncodeStream.cpp +++ b/lib/backupclient/BackupStoreFileEncodeStream.cpp @@ -55,6 +55,7 @@ BackupStoreFileEncodeStream::BackupStoreFileEncodeStream() mPositionInCurrentBlock(0), mBlockSize(BACKUP_FILE_MIN_BLOCK_SIZE), mLastBlockSize(0), + mTotalBytesSent(0), mpRawBuffer(0), mAllocatedBufferSize(0), mEntryIVBase(0) @@ -463,6 +464,7 @@ int BackupStoreFileEncodeStream::Read(void *pBuffer, int NBytes, int Timeout) // Add encoded size to stats BackupStoreFile::msStats.mTotalFileStreamSize += (NBytes - bytesToRead); + mTotalBytesSent += (NBytes - bytesToRead); // Return size of data to caller return NBytes - bytesToRead; diff --git a/lib/backupclient/BackupStoreFileEncodeStream.h b/lib/backupclient/BackupStoreFileEncodeStream.h index c5fa780a..023994af 100644 --- a/lib/backupclient/BackupStoreFileEncodeStream.h +++ b/lib/backupclient/BackupStoreFileEncodeStream.h @@ -85,6 +85,7 @@ public: virtual void Write(const void *pBuffer, int NBytes); virtual bool StreamDataLeft(); virtual bool StreamClosed(); + int64_t GetTotalBytesSent() { return mTotalBytesSent; } private: enum @@ -121,6 +122,7 @@ private: int32_t mPositionInCurrentBlock; // for reading out int32_t mBlockSize; // Basic block size of most of the blocks in the file int32_t mLastBlockSize; // the size (unencoded) of the last block in the file + int64_t mTotalBytesSent; // Buffers uint8_t *mpRawBuffer; // buffer for raw data BackupStoreFile::EncodingBuffer mEncodedBuffer; -- cgit v1.2.3