From 05227d99e0c66d6236190a9c37f060559cb58493 Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Fri, 20 Mar 2020 22:39:23 -0700 Subject: [PATCH] [adb] file sync performance on Windows Print not more often than once a 100ms - it is smooth enough and speeds up transfer even more on Windows, where a single line output may take up to 5ms. An added benefit is getting rid of some extra heap allocation and string formatting when in the end the identical message filtering would've dropped the line anyway. This is also significantly more expensive on Windows. Bug: 151900478 Test: manual, push/pull a file and a directory Change-Id: I9038729e8a01d5f93fd301beaeb8a086f5039b77 --- adb/client/file_sync_client.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/adb/client/file_sync_client.cpp b/adb/client/file_sync_client.cpp index 94bd8f543..f29ca9288 100644 --- a/adb/client/file_sync_client.cpp +++ b/adb/client/file_sync_client.cpp @@ -53,6 +53,8 @@ #include #include +using namespace std::literals; + typedef void(sync_ls_cb)(unsigned mode, uint64_t size, uint64_t time, const char* name); struct syncsendbuf { @@ -112,8 +114,12 @@ struct TransferLedger { uint64_t bytes_transferred; uint64_t bytes_expected; bool expect_multiple_files; - std::string last_progress_str; + private: + std::string last_progress_str; + std::chrono::steady_clock::time_point last_progress_time; + + public: TransferLedger() { Reset(); } @@ -128,12 +134,13 @@ struct TransferLedger { } void Reset() { - last_progress_str.clear(); start_time = std::chrono::steady_clock::now(); files_transferred = 0; files_skipped = 0; bytes_transferred = 0; bytes_expected = 0; + last_progress_str.clear(); + last_progress_time = {}; } std::string TransferRate() { @@ -153,6 +160,12 @@ struct TransferLedger { void ReportProgress(LinePrinter& lp, const std::string& file, uint64_t file_copied_bytes, uint64_t file_total_bytes) { + static constexpr auto kProgressReportInterval = 100ms; + + auto now = std::chrono::steady_clock::now(); + if (now < last_progress_time + kProgressReportInterval) { + return; + } char overall_percentage_str[5] = "?"; if (bytes_expected != 0 && bytes_transferred <= bytes_expected) { int overall_percentage = static_cast(bytes_transferred * 100 / bytes_expected); @@ -186,6 +199,7 @@ struct TransferLedger { if (output != last_progress_str) { lp.Print(output, LinePrinter::LineType::INFO); last_progress_str = std::move(output); + last_progress_time = now; } }