OpenDNSSEC-signer  1.4.5
stats.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 NLNet Labs. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26 
32 #include "shared/log.h"
33 #include "signer/stats.h"
34 
41 {
42  stats_type* stats = (stats_type*) malloc(sizeof(stats_type));
43  stats_clear(stats);
44  lock_basic_init(&stats->stats_lock);
45  return stats;
46 }
47 
48 
53 void
55 {
56  ods_log_assert(stats);
57  stats->sort_count = 0;
58  stats->sort_time = 0;
59  stats->sort_done = 0;
60  stats->nsec_count = 0;
61  stats->nsec_time = 0;
62  stats->sig_count = 0;
63  stats->sig_soa_count = 0;
64  stats->sig_reuse = 0;
65  stats->sig_time = 0;
66  stats->start_time = 0;
67  stats->end_time = 0;
68 }
69 
70 
75 void
76 stats_log(stats_type* stats, const char* name, uint32_t serial,
77  ldns_rr_type nsec_type)
78 {
79  uint32_t avsign = 0;
80 
81  if (!stats) {
82  return;
83  }
84  ods_log_assert(stats);
85  if (stats->sig_time) {
86  avsign = (uint32_t) (stats->sig_count/stats->sig_time);
87  }
88  ods_log_info("[STATS] %s %u RR[count=%d time=%u(sec)] "
89  "NSEC%s[count=%d time=%u(sec)] "
90  "RRSIG[new=%d reused=%d time=%u(sec) avg=%u(sig/sec)] "
91  "TOTAL[time=%u(sec)] ",
92  name?name:"(null)", (unsigned) serial,
93  stats->sort_count, stats->sort_time,
94  nsec_type==LDNS_RR_TYPE_NSEC3?"3":"", stats->nsec_count,
95  stats->nsec_time, stats->sig_count, stats->sig_reuse,
96  stats->sig_time, avsign,
97  (uint32_t) (stats->end_time - stats->start_time));
98  return;
99 }
100 
101 
106 void
108 {
110  free((void*) stats);
111  return;
112 }
int sort_done
Definition: stats.h:57
stats_type * stats_create(void)
Definition: stats.c:40
#define lock_basic_destroy(lock)
Definition: locks.h:90
time_t sig_time
Definition: stats.h:63
void ods_log_info(const char *format,...)
Definition: log.c:302
int32_t nsec_count
Definition: stats.h:58
lock_basic_type stats_lock
Definition: stats.h:67
int32_t sort_count
Definition: stats.h:55
int32_t sig_reuse
Definition: stats.h:62
time_t nsec_time
Definition: stats.h:59
int32_t sig_count
Definition: stats.h:60
void stats_log(stats_type *stats, const char *name, uint32_t serial, ldns_rr_type nsec_type)
Definition: stats.c:76
time_t start_time
Definition: stats.h:65
time_t sort_time
Definition: stats.h:56
void stats_cleanup(stats_type *stats)
Definition: stats.c:107
time_t end_time
Definition: stats.h:66
#define lock_basic_init(lock)
Definition: locks.h:89
#define ods_log_assert(x)
Definition: log.h:154
int32_t sig_soa_count
Definition: stats.h:61
void stats_clear(stats_type *stats)
Definition: stats.c:54