/* SELECT statements */
#define SELECT_FOR_PERIOD "select binpath, hw_net_protocol_type, " \
"is_roaming, sum(received) as received, " \
- "sum(sent) as sent, imsi, ground 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 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, time_stamp - time_stamp % ? as time_stamp, imsi, " \
- "ground " \
+ "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, " \
- "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 ?) " \
- "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);
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);
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);
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);
static int __is_iftype_defined(const stc_iface_type_e iftype)
{
- __STC_LOG_FUNC_ENTER__;
- __STC_LOG_FUNC_EXIT__;
return iftype < STC_IFACE_LAST_ELEM &&
iftype > STC_IFACE_UNKNOWN &&
iftype != STC_IFACE_ALL;
static sqlite3_stmt *__select_statement(const char *app_id,
const table_statistics_select_rule *rule)
{
- __STC_LOG_FUNC_ENTER__;
const int stm_index = __is_iftype_defined(rule->iftype) |
((strlen(app_id) > 0) ? 0 : 2) | (rule->granularity ? 4 : 0);
STC_LOGD("stm index %d", stm_index);
- __STC_LOG_FUNC_EXIT__;
return *details_stms[stm_index];
}
+//LCOV_EXCL_START
stc_error_e table_statistics_reset_first_n_entries(int num)
{
__STC_LOG_FUNC_ENTER__;
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.
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.");
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 */
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.hw_net_protocol_type = sqlite3_column_int(stmt, 1);
data.roaming = sqlite3_column_int(stmt, 2);
- data.ground = sqlite3_column_int(stmt, 6);
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);
+
if (rule->granularity) {
- interval.from = sqlite3_column_int64(stmt, 7);
+ interval.from = sqlite3_column_int64(stmt, 9);
interval.to = interval.from + rule->granularity;
}
if (info_cb(&data, user_data) == STC_CANCEL)
- rc = SQLITE_DONE;/* emulate end of data */
- __STC_LOG_FUNC_EXIT__;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_DONE:
- __STC_LOG_FUNC_EXIT__;
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
+ break; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
return error_code;
}
-stc_error_e table_statistics_per_app(const char *app_id,
+API stc_error_e table_statistics_per_app(const char *app_id,
table_statistics_select_rule *rule,
table_statistics_info_cb info_cb,
void *user_data)
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.
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 */
- __STC_LOG_FUNC_EXIT__;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_DONE:
- __STC_LOG_FUNC_EXIT__;
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
+ break; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
return error_code;
}
-stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
+API stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
stc_db_app_stats *stat,
time_t last_touch_time)
{
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;
+ long long int rcv;
+ long long int snd;
if (!stat->rcv_count && !stat->snd_count) {
error_code = STC_ERROR_INVALID_PARAMETER;
SQLITE_STATIC));
DB_ACTION(sqlite3_bind_int(stmt, 2, stat->rcv_count));
DB_ACTION(sqlite3_bind_int(stmt, 3, stat->snd_count));
- DB_ACTION(sqlite3_bind_int64(stmt, 4,
- (sqlite3_int64)(last_touch_time)));
+ DB_ACTION(sqlite3_bind_int64(stmt, 4, (sqlite3_int64)last_touch_time));
DB_ACTION(sqlite3_bind_int(stmt, 5, (int)(stat_key->iftype)));
DB_ACTION(sqlite3_bind_int(stmt, 6, (int)(stat->is_roaming)));
DB_ACTION(sqlite3_bind_int(stmt, 7, (int)hw_net_protocol_type));
- DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname, -1,
- SQLITE_STATIC));
+ DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname ? stat_key->ifname : "",
+ -1, SQLITE_STATIC));
DB_ACTION(sqlite3_bind_text(stmt, 9,
- stat_key->imsi ? stat_key->imsi : "" , -1,
- SQLITE_STATIC));
+ stat_key->subscriber_id ? stat_key->subscriber_id : "" ,
+ -1, SQLITE_STATIC));
DB_ACTION(sqlite3_bind_int(stmt, 10, (int)stat->ground));
/*we want to reuse tree*/
+ rcv = stat->rcv_count;
+ snd = stat->snd_count;
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_STAT_LOG)
+ STC_LOGD("App stat recorded [\033[0;34m%s\033[0;m] "
+ "rcv[%lld] snd[%lld]", stat->app_id, rcv, snd);
handle_error:
sqlite3_reset(stmt);
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));