Skip to content

Commit

Permalink
improve config parser performance
Browse files Browse the repository at this point in the history
- use faster trim method
- skip sanitizing dependencies when reading precached objects
- skip regexp matching when reading precached objects
  • Loading branch information
sni committed Jan 29, 2025
1 parent 9eed0dc commit e84c67c
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 68 deletions.
2 changes: 2 additions & 0 deletions src/naemon/naemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ int main(int argc, char **argv)

/* read in all object config data */
if (result == OK) {
nm_log(NSLOG_INFO_MESSAGE, "Reading all config object data\n");
timing_point("Reading all object data\n");
result = read_all_object_data(config_file);
timing_point("Read all object data\n");
Expand All @@ -587,6 +588,7 @@ int main(int argc, char **argv)
timing_point("Initialized Event queue\n");

/* load modules */
nm_log(NSLOG_INFO_MESSAGE, "Loading neb modules\n");
timing_point("Loading modules\n");
if (neb_load_all_modules() != OK) {
nm_log(NSLOG_CONFIG_ERROR, "Error: Module loading failed. Aborting.\n");
Expand Down
24 changes: 24 additions & 0 deletions src/naemon/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include <glib.h>
#include <ctype.h>
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
Expand Down Expand Up @@ -412,6 +413,29 @@ void strip(char *buffer)
}
}

// strip trailing whitespace, returns pointer to stripped string
char *rstrip(char *c)
{
char *w = c + strlen(c) - 1;
while (w >= c && isspace(*w))
*w-- = '\0';
return c;
}

// strip trailing whitespace, returns pointer to stripped string
// NOTE: you need to free the original pointer, not the stripped one
char *lstrip(char *c)
{
while (isspace(*c)) c++;
return c;
}

// trim leading/trailing whitespace, returns pointer to stripped string
// NOTE: you need to free the original pointer, not the stripped one
char *trim(char *c)
{
return(lstrip(rstrip(c)));
}

/*
* given a date/time in time_t format, produce a corresponding
Expand Down
3 changes: 3 additions & 0 deletions src/naemon/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ int mmap_fclose(mmapfile *temp_mmapfile);
char *mmap_fgets(mmapfile *temp_mmapfile);
char *mmap_fgets_multiline(mmapfile * temp_mmapfile);
void strip(char *buffer);
char *rstrip(char *c);
char *lstrip(char *c);
char *trim(char *c);
void get_datetime_string(time_t *raw_time, char *buffer,
int buffer_length, int type);
void get_time_breakdown(unsigned long raw_time, int *days, int *hours,
Expand Down
Loading

0 comments on commit e84c67c

Please sign in to comment.