gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r5016 - GNUnet/src/applications/stats


From: gnunet
Subject: [GNUnet-SVN] r5016 - GNUnet/src/applications/stats
Date: Mon, 11 Jun 2007 19:29:52 -0600 (MDT)

Author: grothoff
Date: 2007-06-11 19:29:52 -0600 (Mon, 11 Jun 2007)
New Revision: 5016

Modified:
   GNUnet/src/applications/stats/statistics.c
Log:
clean up statistics module -- 15 percent of time for gnunet-stats was spent in 
strlen, getting rid of it

Modified: GNUnet/src/applications/stats/statistics.c
===================================================================
--- GNUnet/src/applications/stats/statistics.c  2007-06-11 21:46:41 UTC (rev 
5015)
+++ GNUnet/src/applications/stats/statistics.c  2007-06-12 01:29:52 UTC (rev 
5016)
@@ -55,20 +55,18 @@
  */
 static cron_t startTime;
 
-/**
- * How many values do we keep statistics for?
- */
-static unsigned int statCounters = 0;
+struct StatEntry {
+  unsigned long long value;
+  char * description;
+  unsigned int descStrLen;
+};
 
-/**
- * What are these values (value)
- */
-static unsigned long long * values = NULL;
+static struct StatEntry * entries;
 
 /**
- * A description for each of the values
+ * Size of the entries array
  */
-static char ** descriptions = NULL;
+static unsigned int statCounters;
 
 /**
  * lock for the stat module
@@ -91,19 +89,16 @@
   GE_ASSERT(NULL, name != NULL);
   MUTEX_LOCK(statLock);
   for (i=0;i<statCounters;i++)
-    if (0 == strcmp(descriptions[i], name)) {
+    if (0 == strcmp(entries[i].description, name)) {
       MUTEX_UNLOCK(statLock);
       return i;
     }
-
-  GROW(values,
+  GROW(entries,
        statCounters,
        statCounters+1);
-  statCounters--;
-  GROW(descriptions,
-       statCounters,
-       statCounters+1);
-  descriptions[statCounters-1] = STRDUP(name);
+  entries[statCounters-1].description = STRDUP(name);
+  entries[statCounters-1].descStrLen = strlen(name);
+  entries[statCounters-1].value = 0;
   MUTEX_UNLOCK(statLock);
   return statCounters-1;
 }
@@ -124,7 +119,7 @@
     MUTEX_UNLOCK(statLock);
     return;
   }
-  values[handle] = value;
+  entries[handle].value = value;
   MUTEX_UNLOCK(statLock);
 }
 
@@ -137,7 +132,7 @@
     MUTEX_UNLOCK(statLock);
     return -1;
   }
-  ret = values[handle];
+  ret = entries[handle].value;
   MUTEX_UNLOCK(statLock);
   return ret;
 }
@@ -158,7 +153,7 @@
     MUTEX_UNLOCK(statLock);
     return;
   }
-  values[handle] += delta;
+  entries[handle].value += delta;
   MUTEX_UNLOCK(statLock);
 }
 
@@ -171,10 +166,8 @@
 
   MUTEX_DESTROY(statLock);
   for (i=0;i<statCounters;i++)
-    FREE(descriptions[i]);
-  FREENONNULL(descriptions);
-  descriptions = NULL;
-  GROW(values,
+    FREE(entries[i].description);
+  GROW(entries,
        statCounters,
        0);
 }
@@ -281,7 +274,7 @@
   int mpos; /* postion in the message */
 
   immediateUpdates();
-  statMsg = (CS_stats_reply_MESSAGE*)MALLOC(MAX_BUFFER_SIZE);
+  statMsg = MALLOC(MAX_BUFFER_SIZE);
   statMsg->header.type
     = htons(CS_PROTO_stats_STATISTICS);
   statMsg->totalCounters
@@ -299,21 +292,22 @@
     mpos = 0;
     while ( (pos < statCounters) &&
            (mpos + sizeof(unsigned long long)
-            + strlen(descriptions[pos]) + 1
+            + entries[pos].descStrLen + 1
             < MAX_BUFFER_SIZE - sizeof(CS_stats_reply_MESSAGE)) ) {
       mpos += sizeof(unsigned long long); /* value */
-      mpos += strlen(descriptions[pos])+1;
+      mpos += entries[pos].descStrLen + 1;
       pos++;
     }
     end = pos;
     /* second pass: copy values and messages to message */
     for (pos=start;pos<end;pos++)
-      ((CS_stats_reply_MESSAGE_GENERIC*)statMsg)->values[pos-start] = 
htonll(values[pos]);
+      ((CS_stats_reply_MESSAGE_GENERIC*)statMsg)->values[pos-start] = 
htonll(entries[pos].value);
     mpos = sizeof(unsigned long long) * (end - start);
     for (pos=start;pos<end;pos++) {
-      
strcpy(&((char*)(((CS_stats_reply_MESSAGE_GENERIC*)statMsg))->values)[mpos],
-            descriptions[pos]);
-      mpos += strlen(descriptions[pos])+1;
+      
memcpy(&((char*)(((CS_stats_reply_MESSAGE_GENERIC*)statMsg))->values)[mpos],
+            entries[pos].description,
+            entries[pos].descStrLen+1);
+      mpos += entries[pos].descStrLen+1;
     }
     statMsg->statCounters = htonl(end - start);
     GE_ASSERT(NULL, mpos + sizeof(CS_stats_reply_MESSAGE) < MAX_BUFFER_SIZE);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]