warn when memory usage of local tracer grows too much
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
typedef struct databuf {
|
typedef struct databuf {
|
||||||
char *d;
|
char *d;
|
||||||
@@ -20,6 +22,8 @@ typedef struct {
|
|||||||
pthread_mutex_t datalock;
|
pthread_mutex_t datalock;
|
||||||
pthread_cond_t datacond;
|
pthread_cond_t datacond;
|
||||||
databuf * volatile head, *tail;
|
databuf * volatile head, *tail;
|
||||||
|
uint64_t memusage;
|
||||||
|
uint64_t last_warning_memusage;
|
||||||
} forward_data;
|
} forward_data;
|
||||||
|
|
||||||
static void *data_sender(void *_f)
|
static void *data_sender(void *_f)
|
||||||
@@ -37,6 +41,7 @@ wait:
|
|||||||
buf = cur->d;
|
buf = cur->d;
|
||||||
size = cur->l;
|
size = cur->l;
|
||||||
f->head = cur->next;
|
f->head = cur->next;
|
||||||
|
f->memusage -= size;
|
||||||
if (f->head == NULL) f->tail = NULL;
|
if (f->head == NULL) f->tail = NULL;
|
||||||
if (pthread_mutex_unlock(&f->datalock)) abort();
|
if (pthread_mutex_unlock(&f->datalock)) abort();
|
||||||
free(cur);
|
free(cur);
|
||||||
@@ -122,6 +127,9 @@ void *forwarder(char *ip, int port)
|
|||||||
f->sc = -1;
|
f->sc = -1;
|
||||||
f->head = f->tail = NULL;
|
f->head = f->tail = NULL;
|
||||||
|
|
||||||
|
f->memusage = 0;
|
||||||
|
f->last_warning_memusage = 0;
|
||||||
|
|
||||||
printf("connecting to remote tracer %s:%d\n", ip, port);
|
printf("connecting to remote tracer %s:%d\n", ip, port);
|
||||||
|
|
||||||
again:
|
again:
|
||||||
@@ -167,6 +175,19 @@ void forward(void *_forwarder, char *buf, int size)
|
|||||||
if (f->tail != NULL) f->tail->next = new;
|
if (f->tail != NULL) f->tail->next = new;
|
||||||
f->tail = new;
|
f->tail = new;
|
||||||
|
|
||||||
|
f->memusage += size+4;
|
||||||
|
/* warn every 100MB */
|
||||||
|
if (f->memusage > f->last_warning_memusage &&
|
||||||
|
f->memusage - f->last_warning_memusage > 100000000) {
|
||||||
|
f->last_warning_memusage += 100000000;
|
||||||
|
printf("WARNING: memory usage is over %"PRIu64"MB\n",
|
||||||
|
f->last_warning_memusage / 1000000);
|
||||||
|
} else
|
||||||
|
if (f->memusage < f->last_warning_memusage &&
|
||||||
|
f->last_warning_memusage - f->memusage > 100000000) {
|
||||||
|
f->last_warning_memusage = (f->memusage/100000000) * 100000000;
|
||||||
|
}
|
||||||
|
|
||||||
if (pthread_cond_signal(&f->datacond)) abort();
|
if (pthread_cond_signal(&f->datacond)) abort();
|
||||||
if (pthread_mutex_unlock(&f->datalock)) abort();
|
if (pthread_mutex_unlock(&f->datalock)) abort();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user