Organize log for print tree
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-statistics.c
index d28ec86..436c55d 100755 (executable)
 /* SELECT statements */
 #define SELECT_FOR_PERIOD "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname from statistics " \
        "where time_stamp between ? and ? " \
-       "group by binpath, is_roaming, imsi order by received desc"
+       "group by binpath, is_roaming, subscriber_id order by received desc"
 
 #define SELECT_FOR_PERIOD_IFACE "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname from statistics " \
        "where time_stamp between ? and ? " \
-       "and iftype=? group by binpath, is_roaming, imsi order by received desc"
+       "and iftype=? group by binpath, is_roaming, subscriber_id order by received desc"
 
 #define SELECT_CHUNKS "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname, " \
-       "time_stamp - time_stamp % ? as time_stamp " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname, " \
+       "time_stamp - time_stamp % ? as timestamp " \
        "from statistics where time_stamp between ? and ? " \
-       "group by binpath, time_stamp, imsi order by time_stamp"
+       "group by binpath, timestamp, subscriber_id order by timestamp"
 
 #define SELECT_CHUNKS_IFACE "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname, " \
-       "time_stamp - time_stamp % ? as time_stamp " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname, " \
+       "time_stamp - time_stamp % ? as timestamp " \
        "from statistics where time_stamp between ? and ? and iftype=?" \
-       "group by binpath, time_stamp, imsi order by time_stamp"
+       "group by binpath, timestamp, subscriber_id order by timestamp"
 
 #define SELECT_APP_DETAILS "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where time_stamp between ? and ? and binpath=? " \
-       "group by binpath, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "group by binpath, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming " \
-       "order by time_stamp, binpath, iftype, ifname, imsi, " \
+       "order by time_stamp, binpath, iftype, ifname, subscriber_id, " \
        "hw_net_protocol_type, is_roaming"
 
 #define SELECT_APP_DETAILS_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where time_stamp between ? and ? and binpath=? and iftype=?" \
-       "group by hw_net_protocol_type, is_roaming, iftype, ifname, imsi " \
+       "group by hw_net_protocol_type, is_roaming, iftype, ifname, subscriber_id " \
        "order by time_stamp, hw_net_protocol_type, is_roaming, iftype, " \
-       "ifname, imsi"
+       "ifname, subscriber_id"
 
 #define SELECT_CHUNKS_APP "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics " \
        "group by iftype, ifname, time_stamp, hw_net_protocol_type, is_roaming  " \
        "order by time_stamp, iftype, ifname, hw_net_protocol_type, is_roaming"
 
 #define SELECT_CHUNKS_APP_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? and binpath = ? " \
        "and iftype = ? " \
        "group by time_stamp, hw_net_protocol_type, is_roaming, " \
-       "iftype, ifname, imsi " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "iftype, ifname, subscriber_id " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_TOTAL "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
-       " where (time_stamp between ? and ?) and binpath != 'TOTAL_DATACALL' " \
-       "and binpath != 'TOTAL_WIFI' and binpath != 'TOTAL_BLUETOOTH' " \
-       "group by iftype, ifname, imsi, hw_net_protocol_type, is_roaming " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "ifname, subscriber_id, ground from statistics " \
+       "where (time_stamp between ? and ?) " \
+       "and binpath NOT LIKE 'TOTAL_%' " \
+       "group by iftype, ifname, subscriber_id, hw_net_protocol_type, is_roaming " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_TOTAL_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
-       " where (time_stamp between ? and ?) " \
-       "and iftype=? " \
+       "ifname, subscriber_id, ground from statistics " \
+       "where (time_stamp between ? and ?) and iftype=? " \
+       "and binpath NOT LIKE 'TOTAL_%' " \
        "group by hw_net_protocol_type, is_roaming, " \
-       "iftype, ifname, imsi " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "iftype, ifname, subscriber_id " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_CHUNKS_TOTAL "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? " \
-       "group by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "and binpath NOT LIKE 'TOTAL_%' " \
+       "group by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_CHUNKS_TOTAL_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? " \
        "and iftype = ? " \
-       "group by time_stamp, hw_net_protocol_type, is_roaming, iftype, ifname, imsi " \
+       "and binpath NOT LIKE 'TOTAL_%' " \
+       "group by time_stamp, hw_net_protocol_type, is_roaming, iftype, ifname, subscriber_id " \
        "order by time_stamp, hw_net_protocol_type, is_roaming, iftype, " \
-       "ifname, imsi"
+       "ifname, subscriber_id"
 
 /* INSERT statement */
 #define INSERT_VALUES "insert into statistics " \
        "(binpath, received, sent, time_stamp, " \
        "iftype, is_roaming, hw_net_protocol_type, " \
-       "ifname, imsi, ground) " \
+       "ifname, subscriber_id, ground) " \
        "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
 
 static void __finalize_delete(void);
@@ -221,8 +223,8 @@ static int __prepare_delete(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_DELETE(delete_query[0], DELETE_ALL);
@@ -254,8 +256,8 @@ static int __prepare_select(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_SELECT(select_for_period, SELECT_FOR_PERIOD);
@@ -303,8 +305,8 @@ static int __prepare_insert(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_INSERT(update_statistics_query, INSERT_VALUES);
@@ -358,6 +360,7 @@ static sqlite3_stmt *__select_statement(const char *app_id,
        return *details_stms[stm_index];
 }
 
+//LCOV_EXCL_START
 stc_error_e table_statistics_reset_first_n_entries(int num)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -379,18 +382,19 @@ handle_error:
        sqlite3_reset(delete_query[4]);
        return error_code;
 }
+//LCOV_EXCL_STOP
 
 stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule)
 {
        __STC_LOG_FUNC_ENTER__;
        sqlite3_stmt *stmt;
        stc_error_e error_code = STC_ERROR_NONE;
-       int pos = 1;/* running through positions where to
+       int pos = 1; /* running through positions where to
                       bind parameters in the query */
 
        if (!rule || !rule->interval) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_INVALID_PARAMETER;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
        /* pick a statement depending on parameters.
@@ -411,10 +415,10 @@ stc_error_e table_statistics_reset(const table_statistics_reset_rule *rule)
        DB_ACTION(sqlite3_bind_int64(stmt, pos++, rule->interval->to));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
-               STC_LOGE("Failed to drop collected statistics.");
-               error_code = STC_ERROR_DB_FAILED;
-               __STC_LOG_FUNC_EXIT__;
-               goto handle_error;
+               STC_LOGE("Failed to drop collected statistics."); //LCOV_EXCL_LINE
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
        }
 
        STC_LOGD("Entry deleted successfully.");
@@ -439,8 +443,8 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
        memset(&data, 0, sizeof(data));
 
        if (!rule || !info_cb) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_INVALID_PARAMETER;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
        /* pick a statement depending on parameters */
@@ -472,7 +476,7 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
                        data.roaming = sqlite3_column_int(stmt, 2);
                        data.cnt.in_bytes = sqlite3_column_int64(stmt, 3);
                        data.cnt.out_bytes = sqlite3_column_int64(stmt, 4);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 5);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 5);
                        data.ground = sqlite3_column_int(stmt, 6);
                        data.iftype = sqlite3_column_int(stmt, 7);
                        data.ifname = (char *)sqlite3_column_text(stmt, 8);
@@ -483,7 +487,7 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
                        }
 
                        if (info_cb(&data, user_data) == STC_CANCEL)
-                               rc = SQLITE_DONE;/* emulate end of data */
+                               rc = SQLITE_DONE; //LCOV_EXCL_LINE
                        __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_DONE:
@@ -491,9 +495,9 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
                        break;
                case SQLITE_ERROR:
                default:
-                       error_code = STC_ERROR_DB_FAILED;
-                       __STC_LOG_FUNC_EXIT__;
-                       break;
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+                       break; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
 
@@ -513,15 +517,15 @@ stc_error_e table_statistics_per_app(const char *app_id,
        sqlite3_stmt *stmt;
        stc_error_e error_code = STC_ERROR_NONE;
        int rc;
-       int pos = 1;/* running through positions
+       int pos = 1; /* running through positions
                       where to bind parameters in the query */
        stc_db_tm_interval_s interval;
 
        memset(&data, 0, sizeof(data));
 
        if (!rule || !info_cb) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_INVALID_PARAMETER;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
        /* pick a statement depending on parameters.
@@ -555,15 +559,16 @@ stc_error_e table_statistics_per_app(const char *app_id,
                        data.cnt.in_bytes = sqlite3_column_int64(stmt, 3);
                        data.cnt.out_bytes = sqlite3_column_int64(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
+                       data.ground = sqlite3_column_int(stmt, 7);
 
                        if (rule->granularity) {
-                               interval.from = sqlite3_column_int64(stmt, 7);
+                               interval.from = sqlite3_column_int64(stmt, 8);
                                interval.to = interval.from + rule->granularity;
                        }
 
                        if (info_cb(&data, user_data) == STC_CANCEL)
-                               rc = SQLITE_DONE; /* emulate end of data */
+                               rc = SQLITE_DONE; //LCOV_EXCL_LINE
                        __STC_LOG_FUNC_EXIT__;
                        break;
                case SQLITE_DONE:
@@ -571,9 +576,9 @@ stc_error_e table_statistics_per_app(const char *app_id,
                        break;
                case SQLITE_ERROR:
                default:
-                       error_code = STC_ERROR_DB_FAILED;
-                       __STC_LOG_FUNC_EXIT__;
-                       break;
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+                       break; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
 
@@ -589,7 +594,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = update_statistics_query;
-       stc_hw_net_protocol_type_e hw_net_protocol_type = STC_PROTOCOL_NONE;
+       stc_hw_net_protocol_type_e hw_net_protocol_type = STC_PROTOCOL_UNKNOWN;
 
        if (!stat->rcv_count && !stat->snd_count) {
                error_code = STC_ERROR_INVALID_PARAMETER;
@@ -608,7 +613,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
        DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname, -1,
                                    SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_text(stmt, 9,
-                                   stat_key->imsi ? stat_key->imsi : "" , -1,
+                                   stat_key->subscriber_id ? stat_key->subscriber_id : "" , -1,
                                    SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_int(stmt, 10, (int)stat->ground));
 
@@ -616,14 +621,15 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
        stat->rcv_count = 0;
        stat->snd_count = 0;
        if (sqlite3_step(stmt) != SQLITE_DONE) {
-               STC_LOGE("Failed to record appstat. %s",
+               STC_LOGE("Failed to record appstat. %s", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
-               error_code = STC_ERROR_DB_FAILED;
-               __STC_LOG_FUNC_EXIT__;
-               goto handle_error;
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
        }
 
-       STC_LOGD("App stat recorded [%s]", stat->app_id);
+       if (STC_DEBUG_LOG)
+               STC_LOGD("App stat recorded [%s]", stat->app_id);
 
 handle_error:
        sqlite3_reset(stmt);
@@ -666,8 +672,8 @@ stc_error_e table_statistics_prepare(sqlite3 *db)
        stc_error_e error_code = STC_ERROR_NONE;
 
        if (db == NULL) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_DB_FAILED;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
        DB_ACTION(__prepare_delete(db));