extended statusall output
authorMartin Willi <martin@strongswan.org>
Thu, 21 Sep 2006 07:03:21 +0000 (07:03 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 21 Sep 2006 07:03:21 +0000 (07:03 -0000)
  added job/event-queue statistics
  added allocation statistics when using LEAK_DETECTIVE

src/charon/threads/stroke_interface.c
src/libstrongswan/utils/leak_detective.c
src/libstrongswan/utils/leak_detective.h

index a5f32f0..311d865 100755 (executable)
@@ -39,6 +39,7 @@
 #include <crypto/x509.h>
 #include <queues/jobs/initiate_job.h>
 #include <queues/jobs/route_job.h>
+#include <utils/leak_detective.h>
 
 #define IKE_PORT       500
 #define PATH_BUF       256
@@ -384,7 +385,8 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
                        proposal = proposal_create_from_string(PROTO_IKE, proposal_string);
                        if (proposal == NULL)
                        {
-                               this->logger->log(this->logger, ERROR, "invalid IKE proposal string: %s", msg->add_conn.algorithms.esp);
+                               this->logger->log(this->logger, ERROR, 
+                                                                 "invalid IKE proposal string: %s", proposal_string);
                                my_id->destroy(my_id);
                                other_id->destroy(other_id);
                                my_ts->destroy(my_ts);
@@ -433,7 +435,7 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
                        if (proposal == NULL)
                        {
                                this->logger->log(this->logger, ERROR,
-                                       "invalid ESP proposal string: %s", msg->add_conn.algorithms.esp);
+                                                                 "invalid ESP proposal string: %s", proposal_string);
                                policy->destroy(policy);
                                connection->destroy(connection);
                                return;
@@ -615,14 +617,22 @@ static void stroke_status(private_stroke_t *this, stroke_msg_t *msg)
        linked_list_t *list;
        host_t *host;
        
+       leak_detective_status(this->stroke_logger);
+       
+       this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1,
+                                                        "job queue load: %d",
+                                                        charon->job_queue->get_count(charon->job_queue));
+       this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1,
+                                                        "scheduled events: %d",
+                                                        charon->event_queue->get_count(charon->event_queue));
        list = charon->socket->create_local_address_list(charon->socket);
-       this->logger->log(this->logger, CONTROL|LEVEL1,
-                                         "listening on %d addresses:",
-                                         list->get_count(list));
+       this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1,
+                                                        "listening on %d addresses:",
+                                                        list->get_count(list));
        while (list->remove_first(list, (void**)&host) == SUCCESS)
        {
-               this->logger->log(this->logger, CONTROL|LEVEL1,
-                                                 "  %s", host->get_string(host));
+               this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1,
+                                                                "  %s", host->get_string(host));
                host->destroy(host);
                
        }
@@ -632,8 +642,10 @@ static void stroke_status(private_stroke_t *this, stroke_msg_t *msg)
        {
                pop_string(msg, &(msg->status.name));
        }
-       charon->connections->log_connections(charon->connections, this->stroke_logger, msg->status.name);
-       charon->ike_sa_manager->log_status(charon->ike_sa_manager, this->stroke_logger, msg->status.name);
+       charon->connections->log_connections(charon->connections,
+                                                                                this->stroke_logger, msg->status.name);
+       charon->ike_sa_manager->log_status(charon->ike_sa_manager,
+                                                                          this->stroke_logger, msg->status.name);
 }
 
 /**
index fbcd7d9..86071a5 100644 (file)
@@ -37,7 +37,6 @@
 #include "leak_detective.h"
 
 #include <types.h>
-#include <utils/logger_manager.h>
 
 #ifdef LEAK_DETECTIVE
 
@@ -62,7 +61,10 @@ static void uninstall_hooks(void);
 static void *malloc_hook(size_t, const void *);
 static void *realloc_hook(void *, size_t, const void *);
 static void free_hook(void*, const void *);
-static void load_excluded_functions();
+
+static u_int count_malloc = 0;
+static u_int count_free = 0;
+static u_int count_realloc = 0;
 
 typedef struct memory_header_t memory_header_t;
 
@@ -269,6 +271,7 @@ void *malloc_hook(size_t bytes, const void *caller)
        memory_header_t *hdr;
        
        pthread_mutex_lock(&mutex);
+       count_malloc++;
        uninstall_hooks();
        hdr = malloc(bytes + sizeof(memory_header_t));
        /* set to something which causes crashes */
@@ -307,6 +310,7 @@ void free_hook(void *ptr, const void *caller)
        }
        
        pthread_mutex_lock(&mutex);
+       count_free++;
        uninstall_hooks();
        if (hdr->magic != MEMORY_HEADER_MAGIC)
        {
@@ -352,6 +356,7 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
        hdr = old - sizeof(memory_header_t);
        
        pthread_mutex_lock(&mutex);
+       count_realloc++;
        uninstall_hooks();
        if (hdr->magic != MEMORY_HEADER_MAGIC)
        {
@@ -399,4 +404,38 @@ void leak_detective_cleanup()
        report_leaks();
 }
 
+/**
+ * Log memory allocation statistics
+ */
+void leak_detective_status(logger_t *logger)
+{
+       u_int blocks = 0;
+       size_t bytes = 0;
+       memory_header_t *hdr = &first_header;
+       
+       pthread_mutex_lock(&mutex);
+       while ((hdr = hdr->next))
+       {
+               blocks++;
+               bytes += hdr->bytes;
+       }
+       pthread_mutex_unlock(&mutex);
+       
+       logger->log(logger, CONTROL|LEVEL1, "allocation statistics:");
+       logger->log(logger, CONTROL|LEVEL1, "  call stats: malloc: %d, free: %d, realloc: %d",
+                       count_malloc, count_free, count_realloc);
+       logger->log(logger, CONTROL|LEVEL1, "  allocated %d blocks, total size %d bytes (avg. %d bytes)",
+                       blocks, bytes, bytes/blocks);
+}
+
+#else /* !LEAK_DETECTION */
+
+/**
+ * Dummy when !using LEAK_DETECTIVE
+ */
+void leak_detective_status(logger_t *logger)
+{
+
+}
+
 #endif /* LEAK_DETECTION */
index 13c0d01..07b2f65 100644 (file)
 #define LEAK_DETECTIVE_H_
 
 
+#include <utils/logger_manager.h>
+
+/**
+ * Log status information about allocation
+ */
+void leak_detective_status(logger_t *logger);
+
 #ifdef LEAK_DETECTIVE
 
 /**