Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
oai
openairinterface5G
Commits
185e6a4e
Commit
185e6a4e
authored
May 04, 2016
by
Cédric Roux
Browse files
warn when memory usage of local tracer grows too much
parent
d4f5ab77
Changes
1
Hide whitespace changes
Inline
Side-by-side
common/utils/T/tracer/forward.c
View file @
185e6a4e
...
...
@@ -6,6 +6,8 @@
#include
<unistd.h>
#include
<pthread.h>
#include
<string.h>
#include
<stdint.h>
#include
<inttypes.h>
typedef
struct
databuf
{
char
*
d
;
...
...
@@ -20,6 +22,8 @@ typedef struct {
pthread_mutex_t
datalock
;
pthread_cond_t
datacond
;
databuf
*
volatile
head
,
*
tail
;
uint64_t
memusage
;
uint64_t
last_warning_memusage
;
}
forward_data
;
static
void
*
data_sender
(
void
*
_f
)
...
...
@@ -37,6 +41,7 @@ wait:
buf
=
cur
->
d
;
size
=
cur
->
l
;
f
->
head
=
cur
->
next
;
f
->
memusage
-=
size
;
if
(
f
->
head
==
NULL
)
f
->
tail
=
NULL
;
if
(
pthread_mutex_unlock
(
&
f
->
datalock
))
abort
();
free
(
cur
);
...
...
@@ -122,6 +127,9 @@ void *forwarder(char *ip, int port)
f
->
sc
=
-
1
;
f
->
head
=
f
->
tail
=
NULL
;
f
->
memusage
=
0
;
f
->
last_warning_memusage
=
0
;
printf
(
"connecting to remote tracer %s:%d
\n
"
,
ip
,
port
);
again:
...
...
@@ -167,6 +175,19 @@ void forward(void *_forwarder, char *buf, int size)
if
(
f
->
tail
!=
NULL
)
f
->
tail
->
next
=
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_mutex_unlock
(
&
f
->
datalock
))
abort
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment