|
@@ -891,16 +891,15 @@ mg_atomic_add(volatile int *addr, int value)
|
|
|
|
|
|
#if defined(USE_SERVER_STATS)
|
|
#if defined(USE_SERVER_STATS)
|
|
|
|
|
|
-// static unsigned long mg_memory_debug_blockCount = 0;
|
|
|
|
-// static unsigned long mg_memory_debug_totalMemUsed = 0;
|
|
|
|
-
|
|
|
|
struct mg_memory_stat {
|
|
struct mg_memory_stat {
|
|
volatile int blockCount;
|
|
volatile int blockCount;
|
|
volatile int totalMemUsed;
|
|
volatile int totalMemUsed;
|
|
volatile int maxMemUsed;
|
|
volatile int maxMemUsed;
|
|
};
|
|
};
|
|
|
|
|
|
-static struct mg_memory_stat mg_common_memory = {0, 0, 0};
|
|
|
|
|
|
+
|
|
|
|
+static struct mg_memory_stat *get_memory_stat(struct mg_context *ctx);
|
|
|
|
+
|
|
|
|
|
|
static void *
|
|
static void *
|
|
mg_malloc_ex(size_t size,
|
|
mg_malloc_ex(size_t size,
|
|
@@ -910,7 +909,7 @@ mg_malloc_ex(size_t size,
|
|
{
|
|
{
|
|
void *data = malloc(size + sizeof(size_t));
|
|
void *data = malloc(size + sizeof(size_t));
|
|
void *memory = 0;
|
|
void *memory = 0;
|
|
- struct mg_memory_stat *mstat = &mg_common_memory;
|
|
|
|
|
|
+ struct mg_memory_stat *mstat = get_memory_stat(ctx);
|
|
|
|
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
char mallocStr[256];
|
|
char mallocStr[256];
|
|
@@ -919,8 +918,6 @@ mg_malloc_ex(size_t size,
|
|
(void)line;
|
|
(void)line;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- (void)ctx;
|
|
|
|
-
|
|
|
|
if (data) {
|
|
if (data) {
|
|
int mmem = mg_atomic_add(&mstat->totalMemUsed, size);
|
|
int mmem = mg_atomic_add(&mstat->totalMemUsed, size);
|
|
if (mmem > mstat->maxMemUsed) {
|
|
if (mmem > mstat->maxMemUsed) {
|
|
@@ -979,7 +976,7 @@ mg_free_ex(void *memory,
|
|
{
|
|
{
|
|
void *data = (void *)(((char *)memory) - sizeof(size_t));
|
|
void *data = (void *)(((char *)memory) - sizeof(size_t));
|
|
size_t size;
|
|
size_t size;
|
|
- struct mg_memory_stat *mstat = &mg_common_memory;
|
|
|
|
|
|
+ struct mg_memory_stat *mstat = get_memory_stat(ctx);
|
|
|
|
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
char mallocStr[256];
|
|
char mallocStr[256];
|
|
@@ -988,8 +985,6 @@ mg_free_ex(void *memory,
|
|
(void)line;
|
|
(void)line;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- (void)ctx;
|
|
|
|
-
|
|
|
|
if (memory) {
|
|
if (memory) {
|
|
size = *(size_t *)data;
|
|
size = *(size_t *)data;
|
|
mg_atomic_add(&mstat->totalMemUsed, -size);
|
|
mg_atomic_add(&mstat->totalMemUsed, -size);
|
|
@@ -1024,7 +1019,7 @@ mg_realloc_ex(void *memory,
|
|
void *data;
|
|
void *data;
|
|
void *_realloc;
|
|
void *_realloc;
|
|
size_t oldsize;
|
|
size_t oldsize;
|
|
- struct mg_memory_stat *mstat = &mg_common_memory;
|
|
|
|
|
|
+ struct mg_memory_stat *mstat = get_memory_stat(ctx);
|
|
|
|
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
char mallocStr[256];
|
|
char mallocStr[256];
|
|
@@ -1033,8 +1028,6 @@ mg_realloc_ex(void *memory,
|
|
(void)line;
|
|
(void)line;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- (void)ctx;
|
|
|
|
-
|
|
|
|
if (newsize) {
|
|
if (newsize) {
|
|
if (memory) {
|
|
if (memory) {
|
|
data = (void *)(((char *)memory) - sizeof(size_t));
|
|
data = (void *)(((char *)memory) - sizeof(size_t));
|
|
@@ -2104,10 +2097,25 @@ struct mg_context {
|
|
int total_connections;
|
|
int total_connections;
|
|
int total_requests;
|
|
int total_requests;
|
|
int max_connections;
|
|
int max_connections;
|
|
|
|
+ struct mg_memory_stat ctx_memory;
|
|
#endif
|
|
#endif
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
+#if defined(USE_SERVER_STATS)
|
|
|
|
+static struct mg_memory_stat mg_common_memory = {0, 0, 0};
|
|
|
|
+
|
|
|
|
+static struct mg_memory_stat *
|
|
|
|
+get_memory_stat(struct mg_context *ctx)
|
|
|
|
+{
|
|
|
|
+ if (ctx) {
|
|
|
|
+ return &(ctx->ctx_memory);
|
|
|
|
+ }
|
|
|
|
+ return &mg_common_memory;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
struct mg_connection {
|
|
struct mg_connection {
|
|
struct mg_request_info request_info;
|
|
struct mg_request_info request_info;
|
|
struct mg_context *ctx;
|
|
struct mg_context *ctx;
|