root/src/noit_conf.h

Revision 3eca56e24a3dacaef159473562f669d9d546035e, 6.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 months ago)

Address a particularly hot startup path...

61% of check load time is spent doing:
noit_conf_get_boolean(NULL, "//checks/@resolve_targets", ...)

This caches that answer.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _NOIT_CONF_H
34 #define _NOIT_CONF_H
35
36 #include "noit_defines.h"
37 #include "utils/noit_hash.h"
38 #include "noit_console.h"
39
40 #include <uuid/uuid.h>
41 #include <pcre.h>
42
43 typedef void * noit_conf_section_t;
44
45 #define NOIT_CONF_T_USERDATA "noit::state::conf_t"
46 typedef struct {
47   char *path;
48   uuid_t current_check;
49   char filter_name[50];
50   char prompt[80];
51 } noit_conf_t_userdata_t;
52
53 /* seconds == 0 disable config journaling watchdog */
54 API_EXPORT(void) noit_conf_coalesce_changes(u_int32_t seconds);
55 /* Start the watchdog */
56 API_EXPORT(void) noit_conf_watch_and_journal_watchdog(int (*f)(void *), void *c);
57
58 /* marks the config as changed.. if you manipulate the XML tree in any way
59  * you must call this function to "let the system know."  This is used
60  * to notice changes which are in turn flushed out.
61  */
62 API_EXPORT(void) noit_conf_mark_changed();
63
64 API_EXPORT(void) noit_conf_init(const char *toplevel);
65 API_EXPORT(void)
66   noit_conf_poke(const char *toplevel, const char *key, const char *val);
67 API_EXPORT(int) noit_conf_load(const char *path);
68 API_EXPORT(int) noit_conf_save(const char *path);
69 API_EXPORT(char *) noit_conf_config_filename();
70
71 API_EXPORT(void) noit_console_conf_init();
72
73 API_EXPORT(noit_conf_section_t)
74   noit_conf_get_section(noit_conf_section_t section, const char *path);
75 API_EXPORT(noit_conf_section_t *)
76   noit_conf_get_sections(noit_conf_section_t section, const char *path,
77                          int *cnt);
78 API_EXPORT(int)
79   noit_conf_remove_section(noit_conf_section_t section);
80
81 API_EXPORT(noit_hash_table *)
82   noit_conf_get_hash(noit_conf_section_t section, const char *path);
83 API_EXPORT(noit_hash_table *)
84   noit_conf_get_namespaced_hash(noit_conf_section_t section,
85                                 const char *path, const char *ns);
86
87 API_EXPORT(int) noit_conf_get_string(noit_conf_section_t section,
88                                      const char *path, char **value);
89
90 API_EXPORT(int) noit_conf_get_stringbuf(noit_conf_section_t section,
91                                         const char *path, char *value, int len);
92 API_EXPORT(int) noit_conf_get_int(noit_conf_section_t section,
93                                   const char *path, int *value);
94 API_EXPORT(int) noit_conf_string_to_int(const char *str);
95 API_EXPORT(int) noit_conf_get_float(noit_conf_section_t section,
96                                     const char *path, float *value);
97 API_EXPORT(float) noit_conf_string_to_float(const char *str);
98 API_EXPORT(int) noit_conf_get_boolean(noit_conf_section_t section,
99                                       const char *path, noit_boolean *value);
100 API_EXPORT(noit_boolean) noit_conf_string_to_boolean(const char *str);
101
102 API_EXPORT(int) noit_conf_should_resolve_targets(noit_boolean *);
103
104 API_EXPORT(int)
105   noit_conf_get_uuid(noit_conf_section_t section,
106                      const char *path, uuid_t out);
107
108 API_EXPORT(int) noit_conf_set_string(noit_conf_section_t section,
109                                      const char *path, const char *value);
110 API_EXPORT(int) noit_conf_set_int(noit_conf_section_t section,
111                                   const char *path, int value);
112 API_EXPORT(int) noit_conf_set_float(noit_conf_section_t section,
113                                     const char *path, float value);
114 API_EXPORT(int) noit_conf_set_boolean(noit_conf_section_t section,
115                                       const char *path, noit_boolean value);
116
117 API_EXPORT(int)
118   noit_conf_reload(noit_console_closure_t ncct,
119                    int argc, char **argv,
120                    noit_console_state_t *state, void *closure);
121 API_EXPORT(int)
122   noit_conf_write_terminal(noit_console_closure_t ncct,
123                            int argc, char **argv,
124                            noit_console_state_t *state, void *closure);
125 API_EXPORT(int)
126   noit_conf_write_file_console(noit_console_closure_t ncct,
127                                int argc, char **argv,
128                                noit_console_state_t *state, void *closure);
129 API_EXPORT(int)
130   noit_conf_write_file(char **err);
131
132 API_EXPORT(char *)
133   noit_conf_xml_in_mem(size_t *len);
134
135 API_EXPORT(int)
136   noit_conf_write_log();
137
138 API_EXPORT(void) noit_conf_log_init(const char *toplevel);
139 API_EXPORT(int) noit_conf_log_init_rotate(const char *, noit_boolean);
140
141 API_EXPORT(void) noit_conf_backingstore_remove(noit_conf_section_t node);
142 API_EXPORT(void) noit_conf_backingstore_dirty(noit_conf_section_t node);
143
144 API_EXPORT(void) noit_conf_set_namespace(const char *ns);
145
146 #define CONF_REMOVE(n) do { \
147   noit_conf_backingstore_remove(n); \
148 } while(0)
149
150 #define CONF_DIRTY(n) do { \
151  noit_conf_backingstore_dirty(n); \
152  noit_conf_mark_changed(); \
153 } while(0)
154
155 #define EXPOSE_CHECKER(name) \
156   API_EXPORT(pcre *) noit_conf_get_valid_##name##_checker()
157 #define DECLARE_CHECKER(name) \
158 static pcre *checker_valid_##name; \
159 pcre *noit_conf_get_valid_##name##_checker() { return checker_valid_##name; }
160 #define COMPILE_CHECKER(name, expr) do { \
161   const char *errorstr; \
162   int erroff; \
163   checker_valid_##name = pcre_compile(expr, 0, &errorstr, &erroff, NULL); \
164   if(! checker_valid_##name) { \
165     noitL(noit_error, "noit_conf error: compile checker %s failed: %s\n", \
166           #name, errorstr); \
167     exit(-1); \
168   } \
169 } while(0)
170
171 EXPOSE_CHECKER(name);
172
173 #endif
Note: See TracBrowser for help on using the browser.