Example #1
0
/*
 * event timer handle use to output data
 * 
 */
void ev_time_handle(int fd, short event, void *argv)
{
    hash_table_walk(flow_tbl);

    struct event *evtime = argv;
    struct timeval tv;

    evutil_timerclear(&tv);
    tv.tv_sec = OUTPUT_TIME_INTERVAL;
    event_add(evtime, &tv);
}
Example #2
0
void uhost_cache_destroy()
{
	hash_table_walk(uhost_cache_ht, uhost_cache_delete, NULL);
	hash_table_delete(uhost_cache_ht);
}
Example #3
0
int main(int argc, char **argv)
{
	if (argc != 3) {
		DP("Usage: %s <svc_conf> <svc_name>", argv[0]);
		return -1;
	}
	
	char *svc_conf = argv[1];
	char *svc_name = argv[2];

	uint32_t load_count;
	uint32_t svc_gameid;
	if (load_svc_gameid_map(svc_conf, &load_count) == -1) {
		DP("Failed to load_svc_gameid_map");
		return -1;
	}

	if (load_count == 0) {
		DP("Not any svcinfo in svc.conf");
		return -1;
	}
	svc_gameid = get_svc_gameid(svc_name);
	if (svc_gameid == 0) {
		DP("Unsupported svc(%s) in svc_conf: %s", svc_name, svc_conf);
		return -1;
	}

	if (init_uid_nodes_htab(svc_gameid) == -1) {
		DP("Failed to init_uid_nodes_htab");
		return -1;
	}

	if (init_single_watch_shm(svc_gameid) == -1) {
		DP("Failed to init_single_watch_shm");
		return -1;
	}

	uint32_t row = 0;
	uint32_t col = 0;

	int scan = 0;
	struct uid_node_t *uid_node;
	while (1) {
		if (scan++ >= AC_CLEAN_UID_NODE_SCAN_LIMIT) {
			scan = 0;
			usleep(8000);
		}

		struct row_stat_t *row_stat = &(stat->uid_htab.row_stat[row]);

		uid_node = (struct uid_node_t *)hash_table_walk(uid_nodes_htab, &row, &col);
		if (!uid_node) {
			/* 完成一遍扫描, 退出循环 */
			break;
		}

		if (uid_node->uid == empty_key) {
			stat->uid_htab.empty_cnt++;
			row_stat->empty_cnt++;
		} else {
			if (row > stat->uid_htab.max_row) {
				stat->uid_htab.max_row = row;
			}
			stat->uid_htab.used_cnt++;
			row_stat->used_cnt++;
		}
	}

	int lvl, idx;
	int sleep_count = 0;
	struct single_watch_t *sw = NULL;
	for (lvl = 0; lvl < SW_MAX_LVL; lvl++) {
		for (idx = 0; idx < sw_lvl_nnode_list[lvl]; idx++) {
			if (sleep_count++ >= AC_CLEAN_UID_NODE_SCAN_LIMIT) {
				sleep_count = 0;
				usleep(10000);
			}

			sw = GET_SW_NODE(lvl, idx);
			if (sw->uid) {
				stat->lvln_used[lvl]++;
			}
		}
	}

	/* show stat info */
	int i = 0;
	DP("==================[SHM STAT INFO]==================");
	DP("\n------------------[uid-hash-table]-----------------");
	DP("\tmax_row: %u\n\tempty_cnt: %d\n\tused_cnt: %d",
			stat->uid_htab.max_row,
			stat->uid_htab.empty_cnt,
			stat->uid_htab.used_cnt);

	DP("\n-------------[uid-hash-table-row-info]-----------");
	for (i = 0; i < g_row_num; i++) {
		DP("\trow: %u, empty: %d, used: %d", i,
				stat->uid_htab.row_stat[i].empty_cnt,
				stat->uid_htab.row_stat[i].used_cnt);
	}

	DP("\n----------------[sw-lvln-table]------------------");
	for (i = 0; i < SW_MAX_LVL; i++) {
		DP("\tlvl: %d, used: %d (total: %d, spec: %d, lvl_node_size: %u, lvl_size: %u)", i,
				stat->lvln_used[i], sw_lvl_nnode_list[i], sw_lvl_spec_list[i],
				sw_lvl_node_size_list[i], sw_lvl_size_list[i]);
	}
	DP("\n==================[SHM STAT END]===================");

	return 0;
}