Skip to content

Commit

Permalink
improved performance when expanding a module
Browse files Browse the repository at this point in the history
  • Loading branch information
allinurl committed Sep 4, 2013
1 parent 4dd7194 commit 59e2231
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 67 deletions.
119 changes: 117 additions & 2 deletions gdashboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,30 @@ delete_sub_list (GSubList * sub_list)
free (sub_list);
}

/* free allocated memory for holder */
/* free memory allocated in holder for specific module */
void
free_holder_by_module (GHolder ** holder, GModule module)
{
if ((*holder) == NULL)
return;

GSubList *sub_list;
int j;
for (j = 0; j < (*holder)[module].holder_size; j++) {
sub_list = (*holder)[module].items[j].sub_list;
/* free the sub list */
if (sub_list != NULL)
delete_sub_list (sub_list);
if ((*holder)[module].items[j].data != NULL)
free ((*holder)[module].items[j].data);
}
free ((*holder)[module].items);
(*holder)[module].holder_size = 0;
(*holder)[module].idx = 0;
(*holder)[module].sub_items_size = 0;
}

/* free memory allocated in holder */
void
free_holder (GHolder ** holder)
{
Expand Down Expand Up @@ -239,7 +262,7 @@ new_grawdata_item (unsigned int size)
return item;
}

/* free allocated memory for raw data */
/* free memory allocated in raw data */
void
free_raw_data (GRawData * raw_data)
{
Expand Down Expand Up @@ -1234,6 +1257,98 @@ sort_sub_list (GHolder * h, GSort sort)
}
}

GHashTable *
get_ht_by_module (GModule module)
{
GHashTable *ht;

switch (module) {
case VISITORS:
ht = ht_unique_vis;
break;
case REQUESTS:
ht = ht_requests;
break;
case REQUESTS_STATIC:
ht = ht_requests_static;
break;
case NOT_FOUND:
ht = ht_not_found_requests;
break;
case HOSTS:
ht = ht_hosts;
break;
case OS:
ht = ht_os;
break;
case BROWSERS:
ht = ht_browsers;
break;
case REFERRERS:
ht = ht_referrers;
break;
case REFERRING_SITES:
ht = ht_referring_sites;
break;
case KEYPHRASES:
ht = ht_keyphrases;
break;
case STATUS_CODES:
ht = ht_status_code;
break;
default:
return NULL;
}

return ht;
}

unsigned int
get_ht_size_by_module (GModule module)
{
GHashTable *ht;

switch (module) {
case VISITORS:
ht = ht_unique_vis;
break;
case REQUESTS:
ht = ht_requests;
break;
case REQUESTS_STATIC:
ht = ht_requests_static;
break;
case NOT_FOUND:
ht = ht_not_found_requests;
break;
case HOSTS:
ht = ht_hosts;
break;
case OS:
ht = ht_os;
break;
case BROWSERS:
ht = ht_browsers;
break;
case REFERRERS:
ht = ht_referrers;
break;
case REFERRING_SITES:
ht = ht_referring_sites;
break;
case KEYPHRASES:
ht = ht_keyphrases;
break;
case STATUS_CODES:
ht = ht_status_code;
break;
default:
return 0;
}

return g_hash_table_size (ht);
}

/* load raw hash table's data into holder */
void
load_data_to_holder (GRawData * raw_data, GHolder * h, GModule module,
Expand Down
20 changes: 11 additions & 9 deletions gdashboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ typedef struct GHolderItem_

typedef struct GHolder_
{
GHolderItem *items; /* 1st level data */
GModule module; /* current module */
int idx; /* 1st level index */
int holder_size; /* total items on ht */
int sub_items_size;
GHolderItem *items; /* data */
GModule module; /* current module */
int idx; /* first level index */
int holder_size; /* total num of items (first level) */
int sub_items_size; /* total number of sub items */
} GHolder;

typedef struct GRawDataItem_
Expand All @@ -156,10 +156,10 @@ typedef struct GRawDataItem_

typedef struct GRawData_
{
GRawDataItem *items; /* 1st level data */
GModule module; /* current module */
int idx; /* 1st level index */
int size; /* total items on ht */
GRawDataItem *items; /* data */
GModule module; /* current module */
int idx; /* first level index */
int size; /* total num of items on ht */
} GRawData;

float get_percentage (unsigned long long total, unsigned long long hit);
Expand All @@ -178,6 +178,8 @@ void free_holder_by_module (GHolder ** holder, GModule module);
void free_holder (GHolder ** holder);
void load_data_to_dash (GHolder * h, GDash * dash, GModule module, GScrolling * scrolling);
void load_data_to_holder (GRawData * raw_data, GHolder * h, GModule module, GSort sort);
GHashTable *get_ht_by_module (GModule module);
unsigned int get_ht_size_by_module (GModule module);
void load_host_to_holder (GHolder * h, char *ip);
void reset_find ();
void reset_scroll_offsets (GScrolling * scrolling);
Expand Down
78 changes: 23 additions & 55 deletions goaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static GScrolling scrolling = {
0, /* expanded flag */
};
/* *INDENT-ON* */
/* frees the memory allocated by the GHashTable */
/* free memory allocated by g_hash_table_new_full() function */
static void
free_key_value (gpointer old_key, GO_UNUSED gpointer old_value,
GO_UNUSED gpointer user_data)
Expand Down Expand Up @@ -163,56 +163,36 @@ house_keeping (GLog * logger, GDash * dash)

/* allocate memory for an instance of holder */
static void
allocate_holder (void)
allocate_holder_by_module (GHolder * h, GModule module)
{
int ht_size = 0;
GHashTable *ht;
GRawData *raw_data;
unsigned int ht_size = 0;

int i;
/* extract data from the corresponding hash table */
ht = get_ht_by_module (module);
ht_size = get_ht_size_by_module (module);
raw_data = parse_raw_data (ht, ht_size, module);
load_data_to_holder (raw_data, holder + module, module, sort[module]);
}

/* allocate memory for an instance of holder */
static void
allocate_holder (void)
{
GHashTable *ht;
GModule module;
GRawData *raw_data;
int i;
unsigned int ht_size = 0;

holder = new_gholder (TOTAL_MODULES);
for (i = 0; i < TOTAL_MODULES; i++) {
module = i;
switch (module) {
case VISITORS:
ht = ht_unique_vis;
break;
case REQUESTS:
ht = ht_requests;
break;
case REQUESTS_STATIC:
ht = ht_requests_static;
break;
case NOT_FOUND:
ht = ht_not_found_requests;
break;
case HOSTS:
ht = ht_hosts;
break;
case OS:
ht = ht_os;
break;
case BROWSERS:
ht = ht_browsers;
break;
case REFERRERS:
ht = ht_referrers;
break;
case REFERRING_SITES:
ht = ht_referring_sites;
break;
case KEYPHRASES:
ht = ht_keyphrases;
break;
case STATUS_CODES:
ht = ht_status_code;
break;
}

/* extract data from the corresponding hash table */
ht_size = g_hash_table_size (ht);
ht = get_ht_by_module (module);
ht_size = get_ht_size_by_module (module);
raw_data = parse_raw_data (ht, ht_size, module);
load_data_to_holder (raw_data, holder + module, module, sort[module]);
}
Expand All @@ -226,7 +206,6 @@ allocate_data ()
int size = 0, ht_size = 0;

int i;
GHashTable *ht;
GModule module;

dash = new_gdash ();
Expand All @@ -235,63 +214,52 @@ allocate_data ()

switch (module) {
case VISITORS:
ht = ht_unique_vis;
dash->module[module].head = VISIT_HEAD;
dash->module[module].desc = VISIT_DESC;
break;
case REQUESTS:
ht = ht_requests;
dash->module[module].head = REQUE_HEAD;
dash->module[module].desc = REQUE_DESC;
break;
case REQUESTS_STATIC:
ht = ht_requests_static;
dash->module[module].head = STATI_HEAD;
dash->module[module].desc = STATI_DESC;
break;
case NOT_FOUND:
ht = ht_not_found_requests;
dash->module[module].head = FOUND_HEAD;
dash->module[module].desc = FOUND_DESC;
break;
case HOSTS:
ht = ht_hosts;
dash->module[module].head = HOSTS_HEAD;
dash->module[module].desc = HOSTS_DESC;
break;
case OS:
ht = ht_os;
dash->module[module].head = OPERA_HEAD;
dash->module[module].desc = OPERA_DESC;
break;
case BROWSERS:
ht = ht_browsers;
dash->module[module].head = BROWS_HEAD;
dash->module[module].desc = BROWS_DESC;
break;
case REFERRERS:
ht = ht_referrers;
dash->module[module].head = REFER_HEAD;
dash->module[module].desc = REFER_DESC;
break;
case REFERRING_SITES:
ht = ht_referring_sites;
dash->module[module].head = SITES_HEAD;
dash->module[module].desc = SITES_DESC;
break;
case KEYPHRASES:
ht = ht_keyphrases;
dash->module[module].head = KEYPH_HEAD;
dash->module[module].desc = KEYPH_DESC;
break;
case STATUS_CODES:
ht = ht_status_code;
dash->module[module].head = CODES_HEAD;
dash->module[module].desc = CODES_DESC;
break;
}

ht_size = g_hash_table_size (ht);
ht_size = get_ht_size_by_module (module);
size = ht_size > col_data ? col_data : ht_size;
if (scrolling.expanded && module == scrolling.current)
size = MAX_CHOICES;
Expand Down Expand Up @@ -451,9 +419,9 @@ get_keys (GLog * logger)
reset_scroll_offsets (&scrolling);
scrolling.expanded = 1;

free_holder (&holder);
free_holder_by_module (&holder, scrolling.current);
free_dashboard (dash);
allocate_holder ();
allocate_holder_by_module (holder, scrolling.current);
allocate_data ();

display_content (main_win, logger, dash, &scrolling);
Expand Down
2 changes: 1 addition & 1 deletion ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ typedef enum MODULES
REFERRERS,
REFERRING_SITES,
KEYPHRASES,
STATUS_CODES,
STATUS_CODES
} GModule;

typedef enum SCHEMES
Expand Down

0 comments on commit 59e2231

Please sign in to comment.