From bedb4f4a83d9f05142cd3b828f9a4af8468b963f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 30 Jan 2003 23:08:50 +0000 Subject: [PATCH] * Add new -track-memory option to tools which enables the mem usage column in the reports. This is now optional (and defaults to off) because mallinfo can be VERY slow as it seems to touch every page of allocated memory. llvm-svn: 5448 --- lib/Support/Timer.cpp | 16 ++++++++++++++-- support/lib/Support/Timer.cpp | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index 17fea8b93c8..8023c500e5d 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include "Support/Timer.h" +#include "Support/CommandLine.h" #include #include #include @@ -15,6 +16,13 @@ #include #include +namespace { + cl::opt + 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 { diff --git a/support/lib/Support/Timer.cpp b/support/lib/Support/Timer.cpp index 17fea8b93c8..8023c500e5d 100644 --- a/support/lib/Support/Timer.cpp +++ b/support/lib/Support/Timer.cpp @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include "Support/Timer.h" +#include "Support/CommandLine.h" #include #include #include @@ -15,6 +16,13 @@ #include #include +namespace { + cl::opt + 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 {