refine media-scanner CPU occupy over 90% all the time 82/166282/1 submit/tizen_4.0/20180109.065038
authorchen89.chen <chen89.chen@samsung.com>
Tue, 9 Jan 2018 06:49:13 +0000 (14:49 +0800)
committerhj kim <backto.kim@samsung.com>
Tue, 9 Jan 2018 06:44:59 +0000 (15:44 +0900)
Change-Id: Ie9196e68c2578d0be3788f8a21f6cbbe7fc48752

src/scanner-v2/include/media-scanner-common-v2.h [changed mode: 0644->0755]
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c

old mode 100644 (file)
new mode 100755 (executable)
index ff5303f..780512a
@@ -25,6 +25,8 @@
 #include "stdbool.h"
 #include "media-common-system.h"
 
+#define SCAN_SLEEP_TIME 2000
+
 int msc_set_power_status(bool status);
 int msc_get_power_status(bool *status);
 int msc_set_disc_stg_scan_status(bool status);
index c4704ac..e517ba6 100755 (executable)
@@ -151,6 +151,7 @@ int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage
                        MS_SAFE_FREE(db_data);
                        db_data = NULL;
                }
+               usleep(SCAN_SLEEP_TIME);
        }
 
        if (extract_count > 0)
@@ -314,6 +315,7 @@ NEXT:
 
                /*disconnect form media db*/
                if (handle) ms_disconnect_db(&handle);
+               usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
 _POWEROFF:
@@ -486,6 +488,7 @@ NEXT:
                MS_SAFE_FREE(extract_data);
 
                MS_DBG_WARN("STORAGE EXTRACT END[%d]", ret);
+               usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
 _POWEROFF:
index 75e3943..63a24f5 100755 (executable)
@@ -441,18 +441,21 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
 
                                if (d->d_name[0] == '.') {
                                        bpos += d->d_reclen;
+                                       usleep(SCAN_SLEEP_TIME);
                                        continue;
                                }
 
                                if (strcmp(d->d_name, trash) == 0) {
                                        MS_DBG_ERR("trash directory");
                                        bpos += d->d_reclen;
+                                       usleep(SCAN_SLEEP_TIME);
                                        continue;
                                }
 
                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, d->d_name) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_strappend failed");
                                        bpos += d->d_reclen;
+                                       usleep(SCAN_SLEEP_TIME);
                                        continue;
                                }
 
@@ -469,6 +472,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                if (d->d_type == DT_REG) {
                                        if (!ms_check_support_media_type(handle, path)) {
                                                bpos += d->d_reclen;
+                                               usleep(SCAN_SLEEP_TIME);
                                                continue;
                                        }
 
@@ -480,6 +484,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                                        MS_DBG_ERR("I/O ERROR COUNT[%d]", io_err_folder++);
 
                                                bpos += d->d_reclen;
+                                               usleep(SCAN_SLEEP_TIME);
                                                continue;
                                        } else {
                                                ++scan_count;
@@ -527,12 +532,14 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                                if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                        MS_DBG_ERR("insert folder failed");
                                                        bpos += d->d_reclen;
+                                                       usleep(SCAN_SLEEP_TIME);
                                                        continue;
                                                }
                                        }
                                }
 
                                bpos += d->d_reclen;
+                               usleep(SCAN_SLEEP_TIME);
                        }
                        /*update modifiec type for the internal storage*/
                        if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
@@ -541,6 +548,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
                                else
                                        ms_update_folder_time(handle, storage_id, current_path, uid);
                        }
+                       usleep(SCAN_SLEEP_TIME);
                }
 
                ms_insert_folder_end(handle, uid);
@@ -553,6 +561,7 @@ static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, cons
 
                MS_SAFE_FREE(current_path);
                __msc_set_dir_scan_cur_path(NULL);
+               usleep(SCAN_SLEEP_TIME);
        }
 
        goto END_SCAN;
@@ -745,12 +754,14 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                                if (strcmp(d->d_name, trash) == 0) {
                                        MS_DBG_ERR("trash directory");
                                        bpos += d->d_reclen;
+                                       usleep(SCAN_SLEEP_TIME);
                                        continue;
                                }
 
                                if (ms_strappend(path, sizeof(path), "%s/%s", current_path, d->d_name) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_strappend failed");
                                        bpos += d->d_reclen;
+                                       usleep(SCAN_SLEEP_TIME);
                                        continue;
                                }
 
@@ -768,6 +779,7 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                                        /* check media type */
                                        if (!ms_check_support_media_type(handle, path)) {
                                                bpos += d->d_reclen;
+                                               usleep(SCAN_SLEEP_TIME);
                                                continue;
                                        }
 
@@ -779,6 +791,7 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                                                        MS_DBG_ERR("I/O ERROR COUNT[%d]", io_err_storage++);
 
                                                bpos += d->d_reclen;
+                                               usleep(SCAN_SLEEP_TIME);
                                                continue;
                                        } else {
                                                ++scan_count;
@@ -800,7 +813,9 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                                }
 
                                bpos += d->d_reclen;
+                               usleep(SCAN_SLEEP_TIME);
                        }
+                       usleep(SCAN_SLEEP_TIME);
                }
 
                ms_insert_folder_end(handle, uid);
@@ -840,6 +855,7 @@ NEXT_SCAN:
                                        break;
                        }
                }
+               usleep(SCAN_SLEEP_TIME);
        }
 
        if (strstr(new_start_path, MEDIA_ROOT_PATH_USB) != NULL) {
@@ -1307,6 +1323,7 @@ NEXT:
 
                /*disconnect form media db*/
                if (handle) ms_disconnect_db(&handle);
+               usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
 _POWEROFF:
@@ -1476,6 +1493,7 @@ NEXT:
                MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
 
                io_err_storage = 0;
+               usleep(SCAN_SLEEP_TIME);
        }                       /*thread while*/
 
 _POWEROFF: