Plugin: monitor download speed 13/191913/1
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 8 Oct 2018 00:57:07 +0000 (09:57 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Fri, 19 Oct 2018 04:40:56 +0000 (13:40 +0900)
Change-Id: I4091b0f0772d501cac948d5bb353a612ec174c5f
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
src/plugin/http_util.c

index d2944b3d41d099bbb57def323fa74d1d10070894..498fa1ed35a9ac9ba08a919509a318029b835002 100644 (file)
@@ -155,6 +155,7 @@ static void *_print_download_progress(void *download_path)
 {
        FILE *fp = NULL;
        int retry = 0;
+       int cur = 0;
        char buf[256];
 
        do {
@@ -185,8 +186,11 @@ static void *_print_download_progress(void *download_path)
                }
 
                double progress = ((double)size / binary_size);
+
                if (progress <= 1) {
                        char bar[GAUGE_LENGTH + 3];
+                       double speed = 0;
+                       char speed_str[16];
 
                        snprintf(bar, sizeof(bar), "[");
                        int i = 1;
@@ -196,9 +200,21 @@ static void *_print_download_progress(void *download_path)
                                snprintf(bar + strlen(bar), sizeof(bar) - 1, ".");
                        snprintf(bar + strlen(bar), sizeof(bar) - 1, "]");
 
-                       _D("%s | %d / %d (%d %%)",
+                       speed = size - cur;
+                       cur = size;
+
+                       if (speed > 0 && speed < 1000)
+                               snprintf(speed_str, sizeof(speed_str), "%d B/s", (int)speed);
+                       else if (speed >= 1000 && speed < 1000000)
+                               snprintf(speed_str, sizeof(speed_str), "%.1f KB/s", speed / 1000);
+                       else if (speed >= 1000000)
+                               snprintf(speed_str, sizeof(speed_str), "%.1f MB/s", speed / 1000000);
+                       else
+                               snprintf(speed_str, sizeof(speed_str), "%d B/s", 0);
+
+                       _D("%s | %d / %d (%d %%) - %s",
                                        bar, size, binary_size,
-                                       (int)(progress * 100));
+                                       (int)(progress * 100), speed_str);
                }
 
                if (progress >= 1) {