stats.c
Go to the documentation of this file.
/*
* Copyright (c) 2009 NLNet Labs. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "log.h"
#include "signer/stats.h"
stats_type*
stats_create(void)
{
stats_type* stats = (stats_type*) malloc(sizeof(stats_type));
stats_clear(stats);
pthread_mutex_init(&stats->stats_lock, NULL);
return stats;
}
void
stats_clear(stats_type* stats)
{
ods_log_assert(stats);
stats->sort_count = 0;
stats->sort_time = 0;
stats->sort_done = 0;
stats->nsec_count = 0;
stats->nsec_time = 0;
stats->sig_count = 0;
stats->sig_soa_count = 0;
stats->sig_reuse = 0;
stats->sig_time = 0;
stats->start_time = 0;
stats->end_time = 0;
}
void
stats_log(stats_type* stats, const char* name, uint32_t serial,
ldns_rr_type nsec_type)
{
uint32_t avsign = 0;
if (!stats) {
return;
}
ods_log_assert(stats);
if (stats->sig_time) {
avsign = (uint32_t) (stats->sig_count/stats->sig_time);
}
ods_log_info("[STATS] %s %u RR[count=%u time=%lu(sec)] "
"NSEC%s[count=%u time=%lu(sec)] "
"RRSIG[new=%u reused=%u time=%lu(sec) avg=%u(sig/sec)] "
"TOTAL[time=%u(sec)] ",
name?name:"(null)", (unsigned) serial,
stats->sort_count, (unsigned long)stats->sort_time,
nsec_type==LDNS_RR_TYPE_NSEC3?"3":"", stats->nsec_count,
(unsigned long)stats->nsec_time, stats->sig_count, stats->sig_reuse,
(unsigned long)stats->sig_time, avsign,
(uint32_t) (stats->end_time - stats->start_time));
}
void
stats_cleanup(stats_type* stats)
{
pthread_mutex_destroy(&stats->stats_lock);
free((void*) stats);
}
stats_struct::sort_done
int sort_done
Definition: stats.h:53
stats_struct
Definition: stats.h:50
stats_create
stats_type * stats_create(void)
Definition: stats.c:40
stats_struct::sig_time
time_t sig_time
Definition: stats.h:59
stats.h
stats_struct::nsec_time
time_t nsec_time
Definition: stats.h:55
stats_struct::nsec_count
uint32_t nsec_count
Definition: stats.h:54
stats_log
void stats_log(stats_type *stats, const char *name, uint32_t serial, ldns_rr_type nsec_type)
Definition: stats.c:76
stats_struct::start_time
time_t start_time
Definition: stats.h:61
stats_struct::sort_time
time_t sort_time
Definition: stats.h:52
stats_struct::sig_reuse
uint32_t sig_reuse
Definition: stats.h:58
stats_cleanup
void stats_cleanup(stats_type *stats)
Definition: stats.c:106
stats_struct::end_time
time_t end_time
Definition: stats.h:62
stats_struct::sort_count
uint32_t sort_count
Definition: stats.h:51
stats_struct::sig_soa_count
uint32_t sig_soa_count
Definition: stats.h:57
stats_struct::sig_count
uint32_t sig_count
Definition: stats.h:56
stats_struct::stats_lock
pthread_mutex_t stats_lock
Definition: stats.h:63
stats_clear
void stats_clear(stats_type *stats)
Definition: stats.c:54