OpenDNSSEC-signer  2.1.7
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 "log.h"
33 #include "signer/stats.h"
34 
41 {
42  stats_type* stats = (stats_type*) malloc(sizeof(stats_type));
43  stats_clear(stats);
44  pthread_mutex_init(&stats->stats_lock, NULL);
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=%u time=%lu(sec)] "
89  "NSEC%s[count=%u time=%lu(sec)] "
90  "RRSIG[new=%u reused=%u time=%lu(sec) avg=%u(sig/sec)] "
91  "TOTAL[time=%u(sec)] ",
92  name?name:"(null)", (unsigned) serial,
93  stats->sort_count, (unsigned long)stats->sort_time,
94  nsec_type==LDNS_RR_TYPE_NSEC3?"3":"", stats->nsec_count,
95  (unsigned long)stats->nsec_time, stats->sig_count, stats->sig_reuse,
96  (unsigned long)stats->sig_time, avsign,
97  (uint32_t) (stats->end_time - stats->start_time));
98 }
99 
100 
105 void
107 {
108  pthread_mutex_destroy(&stats->stats_lock);
109  free((void*) stats);
110 }
stats_struct::sort_time
time_t sort_time
Definition: stats.h:52
stats_struct::end_time
time_t end_time
Definition: stats.h:62
stats_struct::start_time
time_t start_time
Definition: stats.h:61
stats.h
stats_log
void stats_log(stats_type *stats, const char *name, uint32_t serial, ldns_rr_type nsec_type)
Definition: stats.c:76
stats_clear
void stats_clear(stats_type *stats)
Definition: stats.c:54
stats_struct::nsec_time
time_t nsec_time
Definition: stats.h:55
stats_cleanup
void stats_cleanup(stats_type *stats)
Definition: stats.c:106
stats_struct
Definition: stats.h:50
stats_struct::sig_time
time_t sig_time
Definition: stats.h:59
stats_struct::sig_soa_count
uint32_t sig_soa_count
Definition: stats.h:57
stats_create
stats_type * stats_create(void)
Definition: stats.c:40
stats_struct::nsec_count
uint32_t nsec_count
Definition: stats.h:54
stats_struct::sort_count
uint32_t sort_count
Definition: stats.h:51
stats_struct::sig_reuse
uint32_t sig_reuse
Definition: stats.h:58
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_struct::sort_done
int sort_done
Definition: stats.h:53