Browse code

core: execute core events when pkg usage changes

- track used and real_used metrics for q/f_malloc when MALLOC_STATS is
defined

Daniel-Constantin Mierla authored on 20/12/2010 08:40:46
Showing 2 changed files
... ...
@@ -55,6 +55,9 @@
55 55
 #include "memdbg.h"
56 56
 #include "../bit_scan.h"
57 57
 #include "../cfg/cfg.h" /* memlog */
58
+#ifdef MALLOC_STATS
59
+#include "../evnets.h"
60
+#endif
58 61
 
59 62
 
60 63
 /*useful macros*/
... ...
@@ -240,6 +243,9 @@ void fm_split_frag(struct fm_block* qm, struct fm_frag* frag,
240 240
 		FRAG_CLEAR_USED(n); /* never used */
241 241
 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
242 242
 		qm->real_used+=FRAG_OVERHEAD;
243
+#ifdef MALLOC_STATS
244
+		sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
245
+#endif
243 246
 #endif
244 247
 #ifdef DBG_F_MALLOC
245 248
 		/* frag created by malloc, mark it*/
... ...
@@ -406,6 +412,10 @@ found:
406 406
 	qm->used+=frag->size;
407 407
 	if (qm->max_real_used<qm->real_used)
408 408
 		qm->max_real_used=qm->real_used;
409
+#ifdef MALLOC_STATS
410
+	sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
411
+	sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
412
+#endif
409 413
 #endif
410 414
 	FRAG_MARK_USED(frag); /* mark it as used */
411 415
 	return (char*)frag+sizeof(struct fm_frag);
... ...
@@ -444,6 +454,10 @@ void fm_free(struct fm_block* qm, void* p)
444 444
 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
445 445
 	qm->used-=size;
446 446
 	qm->real_used-=size;
447
+#ifdef MALLOC_STATS
448
+	sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
449
+	sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
450
+#endif
447 451
 #endif
448 452
 #ifdef DBG_F_MALLOC
449 453
 	f->file=file;
... ...
@@ -513,6 +527,10 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
513 513
 		   free frag, so here we only need orig_size-f->size for real used */
514 514
 		qm->real_used-=(orig_size-f->size);
515 515
 		qm->used-=(orig_size-f->size);
516
+#ifdef MALLOC_STATS
517
+		sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
518
+		sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
519
+#endif
516 520
 #endif
517 521
 	}else if (f->size<size){
518 522
 		/* grow */
... ...
@@ -546,6 +564,9 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
546 546
 			f->size+=n->size+FRAG_OVERHEAD;
547 547
 		#if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
548 548
 			qm->real_used-=FRAG_OVERHEAD;
549
+#ifdef MALLOC_STATS
550
+			sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
551
+#endif
549 552
 		#endif
550 553
 			/* split it if necessary */
551 554
 			if (f->size > size){
... ...
@@ -559,6 +580,10 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
559 559
 		#if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
560 560
 			qm->real_used+=(f->size-orig_size);
561 561
 			qm->used+=(f->size-orig_size);
562
+#ifdef MALLOC_STATS
563
+			sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
564
+			sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
565
+#endif
562 566
 		#endif
563 567
 		}else{
564 568
 			/* could not join => realloc */
... ...
@@ -48,6 +48,9 @@
48 48
 #include "../globals.h"
49 49
 #include "memdbg.h"
50 50
 #include "../cfg/cfg.h" /* memlog */
51
+#ifdef MALLOC_STATS
52
+#include "../events.h"
53
+#endif
51 54
 
52 55
 
53 56
 /*useful macros*/
... ...
@@ -394,6 +397,10 @@ void* qm_malloc(struct qm_block* qm, unsigned long size)
394 394
 		qm->used+=f->size;
395 395
 		if (qm->max_real_used<qm->real_used)
396 396
 			qm->max_real_used=qm->real_used;
397
+#ifdef MALLOC_STATS
398
+		sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
399
+		sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
400
+#endif
397 401
 #ifdef DBG_QM_MALLOC
398 402
 		f->file=file;
399 403
 		f->func=func;
... ...
@@ -452,6 +459,10 @@ void qm_free(struct qm_block* qm, void* p)
452 452
 	size=f->size;
453 453
 	qm->used-=size;
454 454
 	qm->real_used-=size;
455
+#ifdef MALLOC_STATS
456
+	sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
457
+	sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
458
+#endif
455 459
 
456 460
 #ifdef QM_JOIN_FREE
457 461
 	/* mark this fragment as used (might fall into the middle of joined frags)
... ...
@@ -568,6 +579,10 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
568 568
 			 */
569 569
 			qm->real_used-=(orig_size-f->size);
570 570
 			qm->used-=(orig_size-f->size);
571
+#ifdef MALLOC_STATS
572
+			sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
573
+			sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
574
+#endif
571 575
 		}
572 576
 		
573 577
 	}else if (f->size < size){
... ...
@@ -598,6 +613,10 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
598 598
 				}
599 599
 				qm->real_used+=(f->size-orig_size);
600 600
 				qm->used+=(f->size-orig_size);
601
+#ifdef MALLOC_STATS
602
+				sr_event_exec(SREV_PKG_SET_USED, (void*)qm->used);
603
+				sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
604
+#endif
601 605
 			}else{
602 606
 				/* could not join => realloc */
603 607
 	#ifdef DBG_QM_MALLOC