Reduce the number of signal to send 10/293210/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 23 May 2023 01:07:05 +0000 (10:07 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 23 May 2023 06:07:50 +0000 (15:07 +0900)
It is a waste to send a signal for every single step.

Change-Id: I4e708ea3af39e6d5867473d1d2ad368cb426cd5d
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/installer/app_installer.cc

index 0162b2e..56ef9e4 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <unistd.h>
 
+#include <algorithm>
+#include <cmath>
 #include <cstdio>
 #include <fstream>
 #include <TTraceWrapper.h>
@@ -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<double>(kSignalCount);
+  int interval = std::max(1, static_cast<int>(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_;