Browse code

print N/A if libc memory usage is not available (bb #1445).

git-svn: trunk@4951

Török Edvin authored on 2009/03/16 21:29:25
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Mar 16 14:29:19 EET 2009 (edwin)
2
+------------------------------------
3
+ * clamd/thrmgr.c, clamdtop/clamdtop.c: print N/A if libc memory
4
+ usage is not available (bb #1445).
5
+
1 6
 Sat Mar 14 22:45:28 EET 2009 (edwin)
2 7
 ------------------------------------
3 8
  * unit_tests/check_clamd.c: put back ifndef C_BSD in unit test
... ...
@@ -196,6 +196,7 @@ int thrmgr_printstats(int f)
196 196
 	size_t pool_used = 0, pool_total = 0, seen_cnt = 0, error_flag = 0;
197 197
 	float mem_heap = 0, mem_mmap = 0, mem_used = 0, mem_free = 0, mem_releasable = 0;
198 198
 	const struct cl_engine **seen = NULL;
199
+	int has_libc_memstats = 0;
199 200
 
200 201
 	pthread_mutex_lock(&pools_lock);
201 202
 	for(cnt=0,l=pools;l;l=l->nxt) cnt++;
... ...
@@ -289,15 +290,20 @@ int thrmgr_printstats(int f)
289 289
 		mem_used = inf.uordblks/(1024*1024.0);
290 290
 		mem_free = inf.fordblks/(1024*1024.0);
291 291
 		mem_releasable = inf.keepcost/(1024*1024.0);
292
+		has_libc_memstats=1;
292 293
 		/* TODO: figure out how to print these statistics on other OSes */
293 294
 	}
294 295
 #endif
295 296
 	if (error_flag) {
296 297
 		mdprintf(f, "ERROR: error encountered while formatting statistics\n");
297 298
 	} else {
299
+	    if (has_libc_memstats)
298 300
 		mdprintf(f,"MEMSTATS: heap %.3fM mmap %.3fM used %.3fM free %.3fM releasable %.3fM pools %u pools_used %.3fM pools_total %.3fM\n",
299 301
 			mem_heap, mem_mmap, mem_used, mem_free, mem_releasable, pool_cnt,
300 302
 			pool_used/(1024*1024.0), pool_total/(1024*1024.0));
303
+	    else
304
+		mdprintf(f,"MEMSTATS: heap N/A mmap N/A used N/A free N/A releasable N/A pools %u pools_used %.3fM pools_total %.3fM\n",
305
+			 pool_cnt, pool_used/(1024*1024.0), pool_total/(1024*1024.0));
301 306
 	}
302 307
 	mdprintf(f,"END\n");
303 308
 	pthread_mutex_unlock(&pools_lock);
... ...
@@ -746,21 +746,27 @@ static void output_memstats(struct stats *stats)
746 746
 	int blink = 0;
747 747
 
748 748
 	werase(mem_window);
749
-	if (stats->mem > 0) {
749
+	if (stats->mem > 0 || (!stats->mem && (stats->lpoolt > 0))) {
750 750
 		box(mem_window, 0, 0);
751 751
 
752
-		snprintf(buf, sizeof(buf),"heap %4luM mmap %4luM unused %3luM",
753
-				stats->lheapu/1024, stats->lmmapu/1024, stats->lreleasable/1024);
752
+		if (stats->mem)
753
+		    snprintf(buf, sizeof(buf),"heap %4luM mmap %4luM unused %3luM",
754
+			     stats->lheapu/1024, stats->lmmapu/1024, stats->lreleasable/1024);
755
+		else
756
+		    snprintf(buf, sizeof(buf), "heap   N/A mmap   N/A unused  N/A");
754 757
 		mvwprintw(mem_window, 1, 1, "Mem:  ");
755 758
 		print_colored(mem_window, buf);
756 759
 
757 760
 		mvwprintw(mem_window, 2, 1, "Libc: ");
758
-		snprintf(buf, sizeof(buf),"used %4luM free %4luM total %4luM",
759
-				stats->ltotalu/1024, stats->ltotalf/1024, (stats->ltotalu+stats->ltotalf)/1024);
761
+		if (stats->mem)
762
+		    snprintf(buf, sizeof(buf),"used %4luM free %4luM total %4luM",
763
+			     stats->ltotalu/1024, stats->ltotalf/1024, (stats->ltotalu+stats->ltotalf)/1024);
764
+		else
765
+		    snprintf(buf, sizeof(buf), "used   N/A free   N/A total   N/A");
760 766
 		print_colored(mem_window, buf);
761 767
 
762 768
 		mvwprintw(mem_window, 3, 1, "Pool: ");
763
-		snprintf(buf, sizeof(buf), "count   %u  used %4luM total %4luM",
769
+		snprintf(buf, sizeof(buf), "count %4u used %4luM total %4luM",
764 770
 			stats->pools_cnt, stats->lpoolu/1024, stats->lpoolt/1024);
765 771
 		print_colored(mem_window, buf);
766 772
 
... ...
@@ -780,8 +786,17 @@ static void parse_memstats(const char *line, struct stats *stats)
780 780
 	double heapu, mmapu, totalu, totalf, releasable, pools_used, pools_total;
781 781
 
782 782
 	if(sscanf(line, " heap %lfM mmap %lfM used %lfM free %lfM releasable %lfM pools %u pools_used %lfM pools_total %lfM",
783
-			&heapu, &mmapu, &totalu, &totalf, &releasable, &stats->pools_cnt, &pools_used, &pools_total) != 8)
783
+			&heapu, &mmapu, &totalu, &totalf, &releasable, &stats->pools_cnt, &pools_used, &pools_total) != 8) {
784
+	    if (sscanf(line , " heap N/A mmap N/A used N/A free N/A releasable N/A pools %u pools_used %lfM pools_total %lfM",
785
+		       &stats->pools_cnt, &pools_used, &pools_total) != 3) {
786
+		stats->mem = -1;
784 787
 		return;
788
+	    }
789
+	    stats->lpoolu = pools_used*1000;
790
+	    stats->lpoolt = pools_total*1000;
791
+	    stats->mem = 0;
792
+	    return;
793
+	}
785 794
 	stats->lheapu = heapu*1000;
786 795
 	stats->lmmapu = mmapu*1000;
787 796
 	stats->ltotalu = totalu*1000;