Commit de06a686 authored by Jan Kadlec's avatar Jan Kadlec

Fixes in code based on code review.

- Compilation warning fixed
- Constant with comment added
- Signed count removed
- Added missing header guards
- Changed output of estimation

Refs #37
parent 99fa7c79
......@@ -898,8 +898,7 @@ static int cmd_memstats(int argc, char *argv[], unsigned flags)
.dname_table = hattrie_create_n(TRIE_BUCKET_SIZE, &mem_ctx),
.dname_size = 0, .rrset_size = 0,
.node_size = 0, .ahtable_size = 0,
.rdata_size = 0, .record_count = 0,
.signed_count = 0 };
.rdata_size = 0, .record_count = 0 };
if (est.node_table == NULL) {
if (est.dname_table) {
hattrie_free(est.dname_table);
......@@ -952,23 +951,20 @@ static int cmd_memstats(int argc, char *argv[], unsigned flags)
hattrie_free(est.dname_table);
size_t zone_size = (size_t)(((double)(est.rdata_size +
est.node_size +
est.rrset_size +
est.dname_size +
est.ahtable_size +
malloc_size) * 1.2) / (1024.0 * 1024.0));
log_zone_info("Zone %s: %zu RRs, signed=%.2f%%, used memory estimation=%zuMB.\n",
zone->name, est.record_count,
est.signed_count ?
((double)(est.signed_count) / (est.record_count - est.signed_count)) * 100 : 0.0,
zone_size);
est.node_size +
est.rrset_size +
est.dname_size +
est.ahtable_size +
malloc_size) * ESTIMATE_MAGIC) / (1024.0 * 1024.0));
log_zone_info("Zone %s: %zu RRs, used memory estimation is %zuMB.\n",
zone->name, est.record_count, zone_size);
file_loader_free(loader);
total_size += zone_size;
}
if (argc == 0) { // for all zones
log_zone_info("Estimated memory consumption for all zones=%zuMB.\n", total_size);
log_zone_info("Estimated memory consumption for all zones is %zuMB.\n", total_size);
}
return rc;
......
......@@ -27,7 +27,7 @@
// Constants used for tweaking, mostly malloc overhead
enum estim_consts {
MALLOC_OVER = sizeof(size_t),
MALLOC_OVER = sizeof(size_t), // according to malloc.c, this is minimum
DNAME_MULT = 1,
DNAME_ADD = MALLOC_OVER * 3, // dname itself, labels, name
RDATA_MULT = 1,
......@@ -94,12 +94,12 @@ static size_t dname_memsize(const knot_dname_t *d)
static int insert_dname_into_table(hattrie_t *table, knot_dname_t *d,
dummy_node_t **n)
{
value_t *val = hattrie_tryget(table, d->name, d->size);
value_t *val = hattrie_tryget(table, (char *)d->name, d->size);
if (val == NULL) {
// Create new dummy node to use for this dname
*n = xmalloc(sizeof(dummy_node_t));
init_list(&(*n)->node_list);
*hattrie_get(table, d->name, d->size) = *n;
*hattrie_get(table, (char *)d->name, d->size) = *n;
return 0;
} else {
// Return previously found dummy node
......@@ -177,7 +177,6 @@ static void rrset_memsize(zone_estim_t *est, const scanner_t *scanner)
est->rdata_size += rdlen;
est->record_count++;
est->signed_count += scanner->r_type == KNOT_RRTYPE_RRSIG ? 1 : 0;
/*
* RDATA size done, now add static part of RRSet to size.
......
......@@ -24,9 +24,15 @@
* @{
*/
#ifndef _KNOT_ESTIMATOR_H_
#define _KNOT_ESTIMATOR_H_
#include "common/hattrie/hat-trie.h"
#include "zscanner/scanner.h"
// Mutiplicative constant, needed because of malloc's fragmentation
static const double ESTIMATE_MAGIC = 1.2;
/*!
* \brief Memory estimation context.
*/
......@@ -39,7 +45,6 @@ typedef struct zone_estim {
size_t ahtable_size; /*!< Estimated ahtable size. */
size_t rrset_size; /*!< Estimated RRSet size. */
size_t record_count; /*!< Total record count for zone. */
size_t signed_count; /*!< RRSIG count. */
} zone_estim_t;
/*!
......@@ -80,3 +85,5 @@ void estimator_rrset_memsize_wrap(const scanner_t *scanner);
* \param p Data to free.
*/
void estimator_free_trie_node(value_t *val, void *data);
#endif /* _KNOT_ESTIMATOR_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment