Skip to content
Snippets Groups Projects
Commit 29f9bfc4 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

Commented private functions in statistics module.

Closes #688 @30m
parent 30ca9abe
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,8 @@ src/dnslib/dname.h
src/dnslib/dname.c
src/dnslib/rrset.h
src/dnslib/rrset.c
src/dnslib/error.c
src/dnslib/error.h
src/dnslib/rdata.h
src/dnslib/rdata.c
src/dnslib/node.h
......
......@@ -14,7 +14,9 @@ gatherer_t *new_gatherer()
return NULL;
}
pthread_mutex_init(&ret->mutex_read, NULL);
pthread_mutex_init(&ret->mutex_read, NULL);
/* TODO check success */
for (int i = 0; i < FREQ_BUFFER_SIZE; i++) {
ret->freq_array[i] = 0;
......
......@@ -49,7 +49,7 @@ struct gatherer {
double udp_qps; /*!< Queries per second - UDP. */
double tcp_qps; /*!< Queries per second - TCP. */
/* latency currently disabled */
/*!< \note latency currently disabled */
/* double mean_latency;
double udp_mean_latency;
double tcp_mean_latency;
......
......@@ -13,6 +13,8 @@
#include "knot/stat/stat.h"
#include "knot/stat/gatherer.h"
#define STAT_COMPILE
#ifdef STAT_COMPILE
/* Static local gatherer variable, to be used with all functions. */
......@@ -33,6 +35,11 @@ static uint stat_last_query_time( stat_t *stat )
return (stat->t2).tv_nsec-(stat->t1).tv_nsec;
}*/
/*!
* \brief Increases query count in the local data gatherer.
*
* \param stat Current stat instance.
*/
static void stat_inc_query(stat_t *stat)
{
if (stat->protocol == stat_UDP) {
......@@ -42,8 +49,18 @@ static void stat_inc_query(stat_t *stat)
}
}
/*!
* \brief Calculates very simple hash from IPv4 address and returns index to
* array.
*
* \param s_addr Socket address structure.
* \param protocol Used protocol.
*
* \return uint Calculated index.
*/
static uint return_index(struct sockaddr_in *s_addr , protocol_t protocol)
{
/* TODO IPv6 */
/* This is the first "hash" I could think of quickly. */
uint ret = 0;
......@@ -69,8 +86,17 @@ static uint return_index(struct sockaddr_in *s_addr , protocol_t protocol)
return ret;
}
/*!
* \brief Adds data to local gatherer structure.
*
* \param stat Current stat variable.
*
* \retval 0 on success.
* \retval -1 on memory error.
*/
static int stat_gatherer_add_data(stat_t *stat)
{
/* TODO IPv6*/
uint index = return_index(stat->s_addr, stat->protocol);
if (!local_gath->freq_array[index]) {
char addr[24];
......@@ -99,6 +125,9 @@ static int stat_gatherer_add_data(stat_t *stat)
return 0;
}
/*!
* \brief Resets logging array.
*/
static void stat_reset_gatherer_array()
{
for (int i = 0; i < FREQ_BUFFER_SIZE; i++) {
......@@ -106,6 +135,10 @@ static void stat_reset_gatherer_array()
}
}
/*!
* \brief Sleeps for given time and then runs all the computations,
* results of which are stored in local gatherer.
*/
static void stat_sleep_compute()
{
while (1) {
......@@ -183,16 +216,16 @@ void stat_set_protocol(stat_t *stat, int protocol)
void stat_get_first(stat_t *stat , struct sockaddr_in *s_addr)
{
// gettimeofday(&stat->t2, NULL);
// gettimeofday(&stat->t2, NULL);
stat->s_addr = s_addr;
//check if s_addr does not get overwritten
// check if s_addr does not get overwritten
}
void stat_get_second(stat_t *stat)
{
// gettimeofday(&stat->t2, NULL);
// gettimeofday(&stat->t2, NULL);
stat_inc_query(stat);
// stat_inc_latency(stat, stat_last_query_time(stat));
// stat_inc_latency(stat, stat_last_query_time(stat));
stat_gatherer_add_data(stat);
}
......
......@@ -37,12 +37,14 @@ static uint const ACTIVE_FLOW_THRESHOLD = 10;
/*!
* \brief Statistics structure, unique for each UDP/TCP thread.
*/
typedef struct stat_t {
struct stat_t {
// struct timespec t1, t2; /* Currently disabled */
protocol_t protocol; /*!< Flags. */
struct sockaddr_in *s_addr;
// gatherer_t *gatherer; / * not needed when using static gatherer. */
} stat_t;
};
typedef struct stat stat_t;
/*!
* \brief Creates new stat_t structure.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment