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