From 922463e7690dfc1bd0e2810bc6cdfc1abd731634 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 23 May 2023 10:07:05 +0900 Subject: [PATCH] Reduce the number of signal to send It is a waste to send a signal for every single step. Change-Id: I4e708ea3af39e6d5867473d1d2ad368cb426cd5d Signed-off-by: Sangyoon Jang --- src/common/installer/app_installer.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/installer/app_installer.cc b/src/common/installer/app_installer.cc index 0162b2e..56ef9e4 100644 --- a/src/common/installer/app_installer.cc +++ b/src/common/installer/app_installer.cc @@ -5,6 +5,8 @@ #include +#include +#include #include #include #include @@ -109,6 +111,7 @@ const char kLogFileName[] = LOGDIR"/app-installers.log"; const char kHistoryFileName[] = LOGDIR"/installation-history.log"; const int kLogRotationSize = 1024 * 256; // 256KB const int kLogMaximumRotation = 3; +const int kSignalCount = 10; } @@ -233,6 +236,8 @@ AppInstaller::Result AppInstaller::Process() { unsigned total_steps = steps_.size(); unsigned current_step = 1; + double div = total_steps / static_cast(kSignalCount); + int interval = std::max(1, static_cast(std::round(div))); for (it_ = steps_.begin(); it_ != steps_.end(); ++it_, ++current_step) { status_ = SafeExecute(*it_, &Step::precheck, "precheck"); @@ -249,7 +254,9 @@ AppInstaller::Result AppInstaller::Process() { if (!context_->pkgid.get().empty()) history_logger_.LogHistoryStart(context_->pkgid.get(), GetPackageVersion(), context_->request_type.get()); - SendProgress(current_step * kProgressRange / total_steps); + + if (current_step == total_steps || current_step % interval == 0) + SendProgress(current_step * kProgressRange / total_steps); } return result_; -- 2.7.4