* Add new -track-memory option to tools which enables the mem usage column in the...
authorChris Lattner <sabre@nondot.org>
Thu, 30 Jan 2003 23:08:50 +0000 (23:08 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 30 Jan 2003 23:08:50 +0000 (23:08 +0000)
This is now optional (and defaults to off) because mallinfo can be VERY slow as it
seems to touch every page of allocated memory.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5448 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Timer.cpp
support/lib/Support/Timer.cpp

index 17fea8b93c88b30370bd2ed7e88476de7f09528d..8023c500e5d665b24993dbd57f11fdb5c7acbb69 100644 (file)
@@ -5,6 +5,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Support/Timer.h"
+#include "Support/CommandLine.h"
 #include <sys/resource.h>
 #include <sys/time.h>
 #include <sys/unistd.h>
 #include <algorithm>
 #include <functional>
 
+namespace {
+  cl::opt<bool>
+  TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
+                                      "tracking (this may be slow)"),
+             cl::Hidden);
+}
+
 // getNumBytesToNotCount - This function is supposed to return the number of
 // bytes that are to be considered not allocated, even though malloc thinks they
 // are allocated.
@@ -65,8 +73,12 @@ Timer::~Timer() {
 }
 
 static long getMemUsage() {
-  struct mallinfo MI = mallinfo();
-  return MI.uordblks/*+MI.hblkhd-getNumBytesToNotCount()*/;
+  if (TrackSpace) {
+    struct mallinfo MI = mallinfo();
+    return MI.uordblks/*+MI.hblkhd-getNumBytesToNotCount()*/;
+  } else {
+    return 0;
+  }
 }
 
 struct TimeRecord {
index 17fea8b93c88b30370bd2ed7e88476de7f09528d..8023c500e5d665b24993dbd57f11fdb5c7acbb69 100644 (file)
@@ -5,6 +5,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Support/Timer.h"
+#include "Support/CommandLine.h"
 #include <sys/resource.h>
 #include <sys/time.h>
 #include <sys/unistd.h>
 #include <algorithm>
 #include <functional>
 
+namespace {
+  cl::opt<bool>
+  TrackSpace("track-memory", cl::desc("Enable -time-passes memory "
+                                      "tracking (this may be slow)"),
+             cl::Hidden);
+}
+
 // getNumBytesToNotCount - This function is supposed to return the number of
 // bytes that are to be considered not allocated, even though malloc thinks they
 // are allocated.
@@ -65,8 +73,12 @@ Timer::~Timer() {
 }
 
 static long getMemUsage() {
-  struct mallinfo MI = mallinfo();
-  return MI.uordblks/*+MI.hblkhd-getNumBytesToNotCount()*/;
+  if (TrackSpace) {
+    struct mallinfo MI = mallinfo();
+    return MI.uordblks/*+MI.hblkhd-getNumBytesToNotCount()*/;
+  } else {
+    return 0;
+  }
 }
 
 struct TimeRecord {