[Nagios-checkins] SF.net SVN: nagios:[2116] nagioscore/trunk

ageric at users.sourceforge.net ageric at users.sourceforge.net
Sun Aug 26 20:12:07 UTC 2012


Revision: 2116
          http://nagios.svn.sourceforge.net/nagios/?rev=2116&view=rev
Author:   ageric
Date:     2012-08-26 20:12:07 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
cgi: Optimize child/parent count for hosts

We have the list of child and parent hosts attached to each host
object as hostsmember structs, so we add a small helper to count
the entries in one and return that value, calling it from the two
functions that actually need it, which are thus made up entirely
of wrapping code.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/common/objects.c
    nagioscore/trunk/include/objects.h

Modified: nagioscore/trunk/common/objects.c
===================================================================
--- nagioscore/trunk/common/objects.c	2012-08-26 20:11:40 UTC (rev 2115)
+++ nagioscore/trunk/common/objects.c	2012-08-26 20:12:07 UTC (rev 2116)
@@ -2186,69 +2186,29 @@
 	return FALSE;
 	}
 
+#ifdef NSCGI
+int hostsmember_elements(hostsmember *list)
+{
+	int elems = 0;
+	for (; list; list = list->next)
+		elems++;
+	return elems;
+}
 
 /* returns a count of the immediate children for a given host */
 /* NOTE: This function is only used by the CGIS */
 int number_of_immediate_child_hosts(host *hst) {
-	int children = 0;
-	host *temp_host = NULL;
-
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
-		if(is_host_immediate_child_of_host(hst, temp_host) == TRUE)
-			children++;
-		}
-
-	return children;
+	return hst == NULL ? 0 : hostsmember_elements(hst->child_hosts);
 	}
 
 
-/* returns a count of the total children for a given host */
-/* NOTE: This function is only used by the CGIS */
-int number_of_total_child_hosts(host *hst) {
-	int children = 0;
-	host *temp_host = NULL;
-
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
-		if(is_host_immediate_child_of_host(hst, temp_host) == TRUE)
-			children += number_of_total_child_hosts(temp_host) + 1;
-		}
-
-	return children;
-	}
-
-
 /* get the number of immediate parent hosts for a given host */
 /* NOTE: This function is only used by the CGIS */
 int number_of_immediate_parent_hosts(host *hst) {
-	int parents = 0;
-	host *temp_host = NULL;
-
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
-		if(is_host_immediate_parent_of_host(hst, temp_host) == TRUE) {
-			parents++;
-			}
-		}
-
-	return parents;
+	return hst == NULL ? 0 : hostsmember_elements(hst->parent_hosts);
 	}
+#endif
 
-
-/* get the total number of parent hosts for a given host */
-/* NOTE: This function is only used by the CGIS */
-int number_of_total_parent_hosts(host *hst) {
-	int parents = 0;
-	host *temp_host = NULL;
-
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
-		if(is_host_immediate_parent_of_host(hst, temp_host) == TRUE) {
-			parents += number_of_total_parent_hosts(temp_host) + 1;
-			}
-		}
-
-	return parents;
-	}
-
-
 /*  tests whether a host is a member of a particular hostgroup */
 /* NOTE: This function is only used by the CGIS */
 int is_host_member_of_hostgroup(hostgroup *group, host *hst) {

Modified: nagioscore/trunk/include/objects.h
===================================================================
--- nagioscore/trunk/include/objects.h	2012-08-26 20:11:40 UTC (rev 2115)
+++ nagioscore/trunk/include/objects.h	2012-08-26 20:12:07 UTC (rev 2116)
@@ -710,7 +710,6 @@
 int number_of_immediate_child_hosts(host *);		                /* counts the number of immediate child hosts for a particular host */
 int number_of_total_child_hosts(host *);				/* counts the number of total child hosts for a particular host */
 int number_of_immediate_parent_hosts(host *);				/* counts the number of immediate parents hosts for a particular host */
-int number_of_total_parent_hosts(host *);				/* counts the number of total parents hosts for a particular host */
 
 #ifdef NSCORE
 int check_for_circular_servicedependency_path(servicedependency *, servicedependency *, int); /* checks if a circular dependency exists for a given service */

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list