[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1352 - gnunet-gtk/src/plugins/stats
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1352 - gnunet-gtk/src/plugins/stats |
Date: |
Sat, 9 Jul 2005 08:23:45 -0700 (PDT) |
Author: grothoff
Date: 2005-07-09 08:23:36 -0700 (Sat, 09 Jul 2005)
New Revision: 1352
Modified:
gnunet-gtk/src/plugins/stats/functions.c
Log:
optimizations
Modified: gnunet-gtk/src/plugins/stats/functions.c
===================================================================
--- gnunet-gtk/src/plugins/stats/functions.c 2005-07-09 14:53:32 UTC (rev
1351)
+++ gnunet-gtk/src/plugins/stats/functions.c 2005-07-09 15:23:36 UTC (rev
1352)
@@ -36,6 +36,12 @@
static Mutex lock;
+static long connectionGoal;
+
+static long long banddown;
+
+static long long bandup;
+
static int getStatValue(long long * value,
long long * lvalue,
cron_t * dtime,
@@ -64,28 +70,53 @@
return SYSERR;
}
-static int getConnectedNodesStat(const void * closure,
- gfloat ** data) {
- long long val;
+static void updateConnectionGoal(void * unused) {
char * cmh;
- long cval;
+ char * availableDown;
+ char * availableUp;
MUTEX_LOCK(&lock);
cmh = getConfigurationOptionValue(sock,
"gnunetd",
"connection-max-hosts");
+ availableDown = getConfigurationOptionValue(sock,
+ "LOAD",
+ "MAXNETDOWNBPSTOTAL");
+ availableUp = getConfigurationOptionValue(sock,
+ "LOAD",
+ "MAXNETUPBPSTOTAL");
MUTEX_UNLOCK(&lock);
- if (cmh == NULL)
+ if (cmh == NULL)
+ connectionGoal = 0;
+ else
+ connectionGoal = atol(cmh);
+ if (availableDown == NULL)
+ banddown = 0;
+ else
+ banddown = atol(availableDown);
+ if (availableUp == NULL)
+ bandup = 0;
+ else
+ bandup = atol(availableUp);
+
+ FREENONNULL(cmh);
+ FREENONNULL(availableDown);
+ FREENONNULL(availableUp);
+}
+
+static int getConnectedNodesStat(const void * closure,
+ gfloat ** data) {
+ long long val;
+
+ if (connectionGoal == 0)
return SYSERR;
- cval = atol(cmh);
- FREE(cmh);
if (OK != getStatValue(&val,
NULL,
NULL,
dgettext("GNUnet",
"# of connected peers")))
return SYSERR;
- data[0][0] = 0.8 * val / cval;
+ data[0][0] = 0.8 * val / connectionGoal;
return OK;
}
@@ -113,9 +144,7 @@
long long lnoise;
long long lcontent;
long long lqueries;
- long long band;
cron_t dtime;
- char * available;
char * buffer;
int i;
@@ -159,30 +188,24 @@
lqueries = 0;
}
FREE(buffer);
- MUTEX_LOCK(&lock);
- available = getConfigurationOptionValue(sock,
- "LOAD",
- "MAXNETDOWNBPSTOTAL");
- MUTEX_UNLOCK(&lock);
- if (available == NULL)
+ if (banddown == 0)
return SYSERR;
- band = atol(available) * dtime / cronSECONDS;
- FREE(available);
+
total -= ltotal;
noise -= lnoise;
queries -= lqueries;
content -= lcontent;
- if (band <= 0) {
+ if (banddown < 0) {
data[0][0] = 0.0;
data[0][1] = 0.0;
data[0][2] = 0.0;
data[0][3] = 0.0;
return OK;
}
- data[0][0] = 0.8 * noise / band; /* red */
- data[0][1] = 0.8 * (content+noise) / band; /* green */
- data[0][2] = 0.8 * (queries+content+noise) / band; /* yellow */
- data[0][3] = 0.8 * total / band; /* blue */
+ data[0][0] = 0.8 * noise / (banddown * dtime / cronSECONDS); /* red */
+ data[0][1] = 0.8 * (content+noise) / (banddown * dtime / cronSECONDS); /*
green */
+ data[0][2] = 0.8 * (queries+content+noise) / (banddown * dtime /
cronSECONDS); /* yellow */
+ data[0][3] = 0.8 * total / (banddown * dtime / cronSECONDS); /* blue */
/*printf("I: %f %f %f\n",
data[0][0],
data[0][1],
@@ -201,9 +224,7 @@
long long lnoise;
long long lcontent;
long long lqueries;
- long long band;
cron_t dtime;
- char * available;
char * buffer;
int i;
@@ -247,30 +268,23 @@
lqueries = 0;
}
FREE(buffer);
- MUTEX_LOCK(&lock);
- available = getConfigurationOptionValue(sock,
- "LOAD",
- "MAXNETUPBPSTOTAL");
- MUTEX_UNLOCK(&lock);
- if (available == NULL)
+ if (bandup == 0)
return SYSERR;
- band = atol(available) * dtime / cronSECONDS;
- FREE(available);
total -= ltotal;
noise -= lnoise;
queries -= lqueries;
content -= lcontent;
- if (band <= 0) {
+ if (bandup < 0) {
data[0][0] = 0.0;
data[0][1] = 0.0;
data[0][2] = 0.0;
data[0][3] = 0.0;
return OK;
}
- data[0][0] = 0.8 * noise / band; /* red */
- data[0][1] = 0.8 * (noise + content) / band; /* green */
- data[0][2] = 0.8 * (noise + content + queries) / band; /* yellow */
- data[0][3] = 0.8 * total / band; /* yellow */
+ data[0][0] = 0.8 * noise / (bandup * dtime / cronSECONDS); /* red */
+ data[0][1] = 0.8 * (noise + content) / (bandup*dtime / cronSECONDS); /*
green */
+ data[0][2] = 0.8 * (noise + content + queries) / (bandup*dtime /
cronSECONDS); /* yellow */
+ data[0][3] = 0.8 * total / (bandup*dtime / cronSECONDS); /* yellow */
/* printf("O: %f %f %f\n",
data[0][0],
data[0][1],
@@ -380,13 +394,22 @@
UPDATE_INTERVAL = 30 * cronSECONDS;
sock = getClientSocket();
MUTEX_CREATE(&lock);
+ updateStatValues(NULL);
+ updateConnectionGoal(NULL);
addCronJob(&updateStatValues,
UPDATE_INTERVAL,
UPDATE_INTERVAL,
NULL);
+ addCronJob(&updateConnectionGoal,
+ 5 * cronMINUTES,
+ 5 * cronMINUTES,
+ NULL);
}
void done_functions() {
+ delCronJob(&updateConnectionGoal,
+ 5 * cronMINUTES,
+ NULL);
delCronJob(&updateStatValues,
UPDATE_INTERVAL,
NULL);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1352 - gnunet-gtk/src/plugins/stats,
grothoff <=