Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove memory sub-structure #317

Merged
merged 1 commit into from
Jun 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,6 @@ typedef struct {
int querytypedata[7];
} overTimeDataStruct;

typedef struct {
int domainnames;
int clientips;
int forwardedips;
int forwarddata;
int clientdata;
int querytypedata;
} memoryStruct;

typedef struct {
int count;
char **domains;
Expand Down Expand Up @@ -249,8 +240,6 @@ extern bool threadwritelock;
extern bool threadreadlock;
extern unsigned char blockingstatus;

extern memoryStruct memory;

extern char * username;
extern char timestamp[16];
extern bool flush;
Expand Down
37 changes: 0 additions & 37 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,43 +773,6 @@ void getRecentBlocked(char *client_message, int *sock)
}
}

void getMemoryUsage(int *sock)
{
unsigned long int structbytes = sizeof(countersStruct) + sizeof(ConfigStruct) + counters.queries_MAX*sizeof(queriesDataStruct) + counters.forwarded_MAX*sizeof(forwardedDataStruct) + counters.clients_MAX*sizeof(clientsDataStruct) + counters.domains_MAX*sizeof(domainsDataStruct) + counters.overTime_MAX*sizeof(overTimeDataStruct);
char *structprefix = calloc(2, sizeof(char));
if(structprefix == NULL) return;
double formated = 0.0;
format_memory_size(structprefix, structbytes, &formated);

if(istelnet[*sock])
ssend(*sock,"memory allocated for internal data structure: %lu bytes (%.2f %sB)\n",structbytes,formated,structprefix);
else
pack_uint64(*sock, structbytes);
free(structprefix);

unsigned long int dynamicbytes = memory.domainnames + memory.clientips + memory.forwardedips + memory.forwarddata;
char *dynamicprefix = calloc(2, sizeof(char));
if(dynamicprefix == NULL) return;
format_memory_size(dynamicprefix, dynamicbytes, &formated);

if(istelnet[*sock])
ssend(*sock,"dynamically allocated memory used for strings: %lu bytes (%.2f %sB)\n",dynamicbytes,formated,dynamicprefix);
else
pack_uint64(*sock, dynamicbytes);
free(dynamicprefix);

unsigned long int totalbytes = structbytes + dynamicbytes;
char *totalprefix = calloc(2, sizeof(char));
if(totalprefix == NULL) return;
format_memory_size(totalprefix, totalbytes, &formated);

if(istelnet[*sock])
ssend(*sock,"Sum: %lu bytes (%.2f %sB)\n",totalbytes,formated,totalprefix);
else
pack_uint64(*sock, totalbytes);
free(totalprefix);
}

void getClientID(int *sock)
{
if(istelnet[*sock])
Expand Down
1 change: 0 additions & 1 deletion api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void getClientNames(int *sock);
void getDomainDetails(char *client_message, int *sock);

// FTL methods
void getMemoryUsage(int *sock);
void getClientID(int *sock);
void getVersion(int *sock);
void getDBstats(int *sock);
Expand Down
4 changes: 0 additions & 4 deletions datastructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ int findOverTimeID(int overTimetimestamp)
// overTime[timeidx].querytypedata is static
overTime[timeidx].clientnum = 0;
overTime[timeidx].clientdata = NULL;
memory.querytypedata += (TYPE_MAX-1)*sizeof(int);
counters.overTime++;

// Update time stamp for next loop interation
Expand Down Expand Up @@ -114,7 +113,6 @@ int findForwardID(const char * forward, bool count)
forwarded[forwardID].count = 0;
// Save forward destination IP address
forwarded[forwardID].ip = strdup(forward);
memory.forwardedips += (strlen(forward) + 1) * sizeof(char);
forwarded[forwardID].failed = 0;
// Initialize forward hostname
// Due to the nature of us being the resolver,
Expand Down Expand Up @@ -163,7 +161,6 @@ int findDomainID(const char *domain)
domains[domainID].blockedcount = 0;
// Store domain name - no need to check for NULL here as it doesn't harm
domains[domainID].domain = strdup(domain);
memory.domainnames += (strlen(domain) + 1) * sizeof(char);
// RegEx needs to be evaluated for this new domain
domains[domainID].regexmatch = REGEX_UNKNOWN;
// Increase counter by one
Expand Down Expand Up @@ -208,7 +205,6 @@ int findClientID(const char *client)
clients[clientID].blockedcount = 0;
// Store client IP - no need to check for NULL here as it doesn't harm
clients[clientID].ip = strdup(client);
memory.clientips += (strlen(client) + 1) * sizeof(char);
// Initialize client hostname
// Due to the nature of us being the resolver,
// the actual resolving of the host name has
Expand Down
12 changes: 1 addition & 11 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,7 @@ void format_memory_size(char *prefix, unsigned long int bytes, double *formated)

void logg_struct_resize(const char* str, int to, int step)
{
unsigned long int structbytes = sizeof(countersStruct) + sizeof(ConfigStruct) + counters.queries_MAX*sizeof(queriesDataStruct) + counters.forwarded_MAX*sizeof(forwardedDataStruct) + counters.clients_MAX*sizeof(clientsDataStruct) + counters.domains_MAX*sizeof(domainsDataStruct) + counters.overTime_MAX*sizeof(overTimeDataStruct);
unsigned long int dynamicbytes = memory.domainnames + memory.clientips + memory.forwardedips + memory.forwarddata + memory.querytypedata;

unsigned long int bytes = structbytes + dynamicbytes;
char *prefix = calloc(2, sizeof(char));
if(prefix == NULL) return;
double formated = 0.0;
format_memory_size(prefix, bytes, &formated);

logg("Notice: Increasing %s struct size from %i to %i (%.2f %sB)", str, (to-step), to, formated, prefix);
free(prefix);
logg("Notice: Increasing %s struct size from %i to %i", str, (to-step), to);
}

void log_counter_info(void)
Expand Down
2 changes: 0 additions & 2 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ logFileNamesStruct files = {
// Fixed size structs
countersStruct counters = { 0 };
ConfigStruct config;
memoryStruct memory;

// Variable size array structs
queriesDataStruct *queries;
Expand Down Expand Up @@ -177,7 +176,6 @@ void validate_access_oTcl(int timeidx, int clientID, int line, const char * func
for(i = overTime[timeidx].clientnum; i <= clientID; i++)
{
overTime[timeidx].clientdata[i] = 0;
memory.clientdata++;
}
// Update counter
overTime[timeidx].clientnum = clientID + 1;
Expand Down
5 changes: 0 additions & 5 deletions request.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ void process_request(char *client_message, int *sock)
processed = true;
getRecentBlocked(client_message, sock);
}
else if(command(client_message, ">memory"))
{
processed = true;
getMemoryUsage(sock);
}
else if(command(client_message, ">clientID"))
{
processed = true;
Expand Down