summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ledger.13
-rw-r--r--src/account.h11
-rw-r--r--src/accum.h11
-rw-r--r--src/commodity.h4
-rw-r--r--src/csv.h4
-rw-r--r--src/draft.h16
-rw-r--r--src/global.cc21
-rw-r--r--src/global.h1
-rw-r--r--src/history.cc7
-rw-r--r--src/iterators.cc8
-rw-r--r--src/iterators.h103
-rw-r--r--src/main.cc1
-rw-r--r--src/pstream.h5
-rw-r--r--src/py_journal.cc5
-rw-r--r--src/report.cc7
-rw-r--r--src/report.h23
-rw-r--r--src/scope.h14
-rw-r--r--src/temps.h4
-rw-r--r--src/utils.cc110
-rw-r--r--test/baseline/opt-verify-memory.test0
20 files changed, 299 insertions, 59 deletions
diff --git a/doc/ledger.1 b/doc/ledger.1
index cd76d5b0..9cfa41c0 100644
--- a/doc/ledger.1
+++ b/doc/ledger.1
@@ -1,4 +1,4 @@
-.Dd March 17, 2012
+.Dd March 18, 2012
.Dt ledger 1
.Sh NAME
.Nm ledger
@@ -431,6 +431,7 @@ appeared in the original journal file.
.It Fl \-value-expr Ar EXPR
.It Fl \-verbose
.It Fl \-verify
+.It Fl \-verify-memory
.It Fl \-version
.It Fl \-weekly Pq Fl W
.It Fl \-wide Pq Fl w
diff --git a/src/account.h b/src/account.h
index 4ddd85e7..fee12595 100644
--- a/src/account.h
+++ b/src/account.h
@@ -189,7 +189,16 @@ public:
posts_cleared_count(0),
posts_last_7_count(0),
posts_last_30_count(0),
- posts_this_month_count(0) {}
+ posts_this_month_count(0) {
+ TRACE_CTOR(account_t::xdata_t::details_t, "");
+ }
+ // A copy copies nothing
+ details_t(const details_t&) {
+ TRACE_CTOR(account_t::xdata_t::details_t, "copy");
+ }
+ ~details_t() throw() {
+ TRACE_DTOR(account_t::xdata_t::details_t);
+ }
details_t& operator+=(const details_t& other);
diff --git a/src/accum.h b/src/accum.h
index dde93c30..628a6b36 100644
--- a/src/accum.h
+++ b/src/accum.h
@@ -51,7 +51,12 @@ protected:
std::string::size_type index;
public:
- straccbuf() : index(0) {}
+ straccbuf() : index(0) {
+ TRACE_CTOR(straccbuf, "");
+ }
+ ~straccbuf() throw() {
+ TRACE_DTOR(straccbuf);
+ }
protected:
virtual std::streamsize xsputn(const char * s, std::streamsize num);
@@ -66,8 +71,12 @@ protected:
public:
straccstream() : std::ostream(0) {
+ TRACE_CTOR(straccstream, "");
rdbuf(&buf);
}
+ ~straccstream() throw() {
+ TRACE_DTOR(straccstream);
+ }
void clear() {
std::ostream::clear();
diff --git a/src/commodity.h b/src/commodity.h
index 148a3636..ba47a572 100644
--- a/src/commodity.h
+++ b/src/commodity.h
@@ -132,10 +132,10 @@ protected:
static_cast<uint_least16_t>(COMMODITY_STYLE_DECIMAL_COMMA) :
static_cast<uint_least16_t>(COMMODITY_STYLE_DEFAULTS)),
symbol(_symbol), precision(0) {
- TRACE_CTOR(base_t, "const string&");
+ TRACE_CTOR(commodity_t::base_t, "const string&");
}
virtual ~base_t() {
- TRACE_DTOR(base_t);
+ TRACE_DTOR(commodity_t::base_t);
}
#if defined(HAVE_BOOST_SERIALIZATION)
diff --git a/src/csv.h b/src/csv.h
index 24ea9121..d98c0567 100644
--- a/src/csv.h
+++ b/src/csv.h
@@ -91,8 +91,12 @@ public:
cost_mask("cost"),
total_mask("total"),
note_mask("note") {
+ TRACE_CTOR(csv_reader, "parse_context_t&");
read_index(*context.stream.get());
}
+ ~csv_reader() {
+ TRACE_DTOR(csv_reader);
+ }
void read_index(std::istream& in);
string read_field(std::istream& in);
diff --git a/src/draft.h b/src/draft.h
index 41485731..e5d29134 100644
--- a/src/draft.h
+++ b/src/draft.h
@@ -68,12 +68,22 @@ class draft_t : public expr_base_t<value_t>
optional<string> cost_operator;
optional<amount_t> cost;
- post_template_t() : from(false) {}
+ post_template_t() : from(false) {
+ TRACE_CTOR(post_template_t, "");
+ }
+ ~post_template_t() throw() {
+ TRACE_DTOR(post_template_t);
+ }
};
std::list<post_template_t> posts;
- xact_template_t() {}
+ xact_template_t() {
+ TRACE_CTOR(xact_template_t, "");
+ }
+ ~xact_template_t() throw() {
+ TRACE_DTOR(xact_template_t);
+ }
void dump(std::ostream& out) const;
};
@@ -86,7 +96,7 @@ public:
if (! args.empty())
parse_args(args);
}
- virtual ~draft_t() {
+ virtual ~draft_t() throw() {
TRACE_DTOR(draft_t);
}
diff --git a/src/global.cc b/src/global.cc
index d7742161..b5ceb614 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -272,6 +272,7 @@ void global_scope_t::report_options(report_t& report, std::ostream& out)
HANDLER(trace_).report(out);
HANDLER(verbose).report(out);
HANDLER(verify).report(out);
+ HANDLER(verify_memory).report(out);
out << std::endl << "[Session scope options]" << std::endl;
report.session.report_options(out);
@@ -315,6 +316,7 @@ option_t<global_scope_t> * global_scope_t::lookup_option(const char * p)
case 'v':
OPT_(verbose);
else OPT(verify);
+ else OPT(verify_memory);
else OPT(version);
break;
}
@@ -452,29 +454,36 @@ void handle_debug_options(int argc, char * argv[])
if (std::strcmp(argv[i], "--args-only") == 0) {
args_only = true;
}
+ else if (std::strcmp(argv[i], "--verify-memory") == 0) {
+#if defined(VERIFY_ON)
+ verify_enabled = true;
+
+ _log_level = LOG_DEBUG;
+ _log_category = "memory\\.counts";
+#endif
+ }
else if (std::strcmp(argv[i], "--verify") == 0) {
#if defined(VERIFY_ON)
- verify_enabled = true; // global in utils.h
+ verify_enabled = true;
#endif
}
else if (std::strcmp(argv[i], "--verbose") == 0 ||
std::strcmp(argv[i], "-v") == 0) {
#if defined(LOGGING_ON)
- _log_level = LOG_INFO; // global in utils.h
+ _log_level = LOG_INFO;
#endif
}
else if (i + 1 < argc && std::strcmp(argv[i], "--debug") == 0) {
#if defined(DEBUG_ON)
- _log_level = LOG_DEBUG; // global in utils.h
- _log_category = argv[i + 1]; // global in utils.h
+ _log_level = LOG_DEBUG;
+ _log_category = argv[i + 1];
i++;
#endif
}
else if (i + 1 < argc && std::strcmp(argv[i], "--trace") == 0) {
#if defined(TRACING_ON)
- _log_level = LOG_TRACE; // global in utils.h
+ _log_level = LOG_TRACE;
try {
- // global in utils.h
_trace_level = boost::lexical_cast<uint8_t>(argv[i + 1]);
}
catch (const boost::bad_lexical_cast&) {
diff --git a/src/global.h b/src/global.h
index 0c11e025..5786bb89 100644
--- a/src/global.h
+++ b/src/global.h
@@ -158,6 +158,7 @@ See LICENSE file included with the distribution for details and disclaimer.");
OPTION(global_scope_t, trace_);
OPTION(global_scope_t, verbose);
OPTION(global_scope_t, verify);
+ OPTION(global_scope_t, verify_memory);
OPTION_(global_scope_t, version, DO() { // -v
parent->show_version_info(std::cout);
diff --git a/src/history.cc b/src/history.cc
index f1e88401..d94ec647 100644
--- a/src/history.cc
+++ b/src/history.cc
@@ -423,7 +423,12 @@ commodity_history_t::find_price(const commodity_t& source,
template <class Name>
class label_writer {
public:
- label_writer(Name _name) : name(_name) {}
+ label_writer(Name _name) : name(_name) {
+ TRACE_CTOR(label_writer<Name>, "Name");
+ }
+ ~label_writer() throw() {
+ TRACE_DTOR(label_writer<Name>);
+ }
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const {
diff --git a/src/iterators.cc b/src/iterators.cc
index acbb581f..7cc1291a 100644
--- a/src/iterators.cc
+++ b/src/iterators.cc
@@ -88,7 +88,13 @@ namespace {
create_price_xact(journal_t& _journal, account_t * _account,
temporaries_t& _temps, xacts_list& _xact_temps)
: journal(_journal), account(_account), temps(_temps),
- xact_temps(_xact_temps) {}
+ xact_temps(_xact_temps) {
+ TRACE_CTOR(create_price_xact,
+ "journal_t&, account_t *, temporaries_t&, xacts_list&");
+ }
+ ~create_price_xact() throw() {
+ TRACE_DTOR(create_price_xact);
+ }
void operator()(datetime_t& date, const amount_t& price) {
xact_t * xact;
diff --git a/src/iterators.h b/src/iterators.h
index 5bb9de6f..922ebccd 100644
--- a/src/iterators.h
+++ b/src/iterators.h
@@ -58,7 +58,15 @@ class iterator_facade_base
typedef Value node_base;
public:
- iterator_facade_base() : m_node(NULL) {}
+ iterator_facade_base() : m_node(NULL) {
+ TRACE_CTOR(iterator_facade_base, "");
+ }
+ iterator_facade_base(const iterator_facade_base& i) : m_node(i.m_node) {
+ TRACE_CTOR(iterator_facade_base, "copy");
+ }
+ ~iterator_facade_base() throw() {
+ TRACE_DTOR(iterator_facade_base);
+ }
explicit iterator_facade_base(node_base p) : m_node(p) {}
@@ -87,12 +95,24 @@ class xact_posts_iterator
bool posts_uninitialized;
public:
- xact_posts_iterator() : posts_uninitialized(true) {}
+ xact_posts_iterator() : posts_uninitialized(true) {
+ TRACE_CTOR(xact_posts_iterator, "");
+ }
xact_posts_iterator(xact_t& xact)
: posts_uninitialized(true) {
+ TRACE_CTOR(xact_posts_iterator, "xact_t&");
reset(xact);
}
- ~xact_posts_iterator() throw() {}
+ xact_posts_iterator(const xact_posts_iterator& i)
+ : iterator_facade_base<xact_posts_iterator, post_t *,
+ boost::forward_traversal_tag>(i),
+ posts_i(i.posts_i), posts_end(i.posts_end),
+ posts_uninitialized(i.posts_uninitialized) {
+ TRACE_CTOR(xact_posts_iterator, "copy");
+ }
+ ~xact_posts_iterator() throw() {
+ TRACE_DTOR(xact_posts_iterator);
+ }
void reset(xact_t& xact) {
posts_i = xact.posts.begin();
@@ -121,15 +141,28 @@ public:
bool xacts_uninitialized;
- xacts_iterator() : xacts_uninitialized(true) {}
+ xacts_iterator() : xacts_uninitialized(true) {
+ TRACE_CTOR(xacts_iterator, "");
+ }
xacts_iterator(journal_t& journal) : xacts_uninitialized(false) {
+ TRACE_CTOR(xacts_iterator, "journal_t&");
reset(journal);
}
xacts_iterator(xacts_list::iterator beg,
xacts_list::iterator end) : xacts_uninitialized(false) {
+ TRACE_CTOR(xacts_iterator, "xacts_list::iterator, xacts_list::iterator");
reset(beg, end);
}
- ~xacts_iterator() throw() {}
+ xacts_iterator(const xacts_iterator& i)
+ : iterator_facade_base<xacts_iterator, xact_t *,
+ boost::forward_traversal_tag>(i),
+ xacts_i(i.xacts_i), xacts_end(i.xacts_end),
+ xacts_uninitialized(i.xacts_uninitialized) {
+ TRACE_CTOR(xacts_iterator, "copy");
+ }
+ ~xacts_iterator() throw() {
+ TRACE_DTOR(xacts_iterator);
+ }
void reset(journal_t& journal);
@@ -150,11 +183,22 @@ class journal_posts_iterator
xact_posts_iterator posts;
public:
- journal_posts_iterator() {}
+ journal_posts_iterator() {
+ TRACE_CTOR(journal_posts_iterator, "");
+ }
journal_posts_iterator(journal_t& journal) {
+ TRACE_CTOR(journal_posts_iterator, "journal_t&");
reset(journal);
}
- ~journal_posts_iterator() throw() {}
+ journal_posts_iterator(const journal_posts_iterator& i)
+ : iterator_facade_base<journal_posts_iterator, post_t *,
+ boost::forward_traversal_tag>(i),
+ xacts(i.xacts), posts(i.posts) {
+ TRACE_CTOR(journal_posts_iterator, "copy");
+ }
+ ~journal_posts_iterator() throw() {
+ TRACE_DTOR(journal_posts_iterator);
+ }
void reset(journal_t& journal);
@@ -173,11 +217,23 @@ protected:
temporaries_t temps;
public:
- posts_commodities_iterator() {}
+ posts_commodities_iterator() {
+ TRACE_CTOR(posts_commodities_iterator, "");
+ }
posts_commodities_iterator(journal_t& journal) {
+ TRACE_CTOR(posts_commodities_iterator, "journal_t&");
reset(journal);
}
- ~posts_commodities_iterator() throw() {}
+ posts_commodities_iterator(const posts_commodities_iterator& i)
+ : iterator_facade_base<posts_commodities_iterator, post_t *,
+ boost::forward_traversal_tag>(i),
+ journal_posts(i.journal_posts), xacts(i.xacts), posts(i.posts),
+ xact_temps(i.xact_temps), temps(i.temps) {
+ TRACE_CTOR(posts_commodities_iterator, "copy");
+ }
+ ~posts_commodities_iterator() throw() {
+ TRACE_DTOR(posts_commodities_iterator);
+ }
void reset(journal_t& journal);
@@ -192,12 +248,23 @@ class basic_accounts_iterator
std::list<accounts_map::const_iterator> accounts_end;
public:
- basic_accounts_iterator() {}
+ basic_accounts_iterator() {
+ TRACE_CTOR(basic_accounts_iterator, "");
+ }
basic_accounts_iterator(account_t& account) {
+ TRACE_CTOR(basic_accounts_iterator, "account_t&");
push_back(account);
increment();
}
- ~basic_accounts_iterator() throw() {}
+ basic_accounts_iterator(const basic_accounts_iterator& i)
+ : iterator_facade_base<basic_accounts_iterator, account_t *,
+ boost::forward_traversal_tag>(i),
+ accounts_i(i.accounts_i), accounts_end(i.accounts_end) {
+ TRACE_CTOR(basic_accounts_iterator, "copy");
+ }
+ ~basic_accounts_iterator() throw() {
+ TRACE_DTOR(basic_accounts_iterator);
+ }
void increment();
@@ -225,10 +292,22 @@ public:
sorted_accounts_iterator(account_t& account,
const expr_t& _sort_cmp, bool _flatten_all)
: sort_cmp(_sort_cmp), flatten_all(_flatten_all) {
+ TRACE_CTOR(sorted_accounts_iterator, "account_t&, expr_t, bool");
push_back(account);
increment();
}
- ~sorted_accounts_iterator() throw() {}
+ sorted_accounts_iterator(const sorted_accounts_iterator& i)
+ : iterator_facade_base<sorted_accounts_iterator, account_t *,
+ boost::forward_traversal_tag>(i),
+ sort_cmp(i.sort_cmp), flatten_all(i.flatten_all),
+ accounts_list(i.accounts_list),
+ sorted_accounts_i(i.sorted_accounts_i),
+ sorted_accounts_end(i.sorted_accounts_end) {
+ TRACE_CTOR(sorted_accounts_iterator, "copy");
+ }
+ ~sorted_accounts_iterator() throw() {
+ TRACE_DTOR(sorted_accounts_iterator);
+ }
void increment();
diff --git a/src/main.cc b/src/main.cc
index 9d2ba311..0130d5c6 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -58,6 +58,7 @@ int main(int argc, char * argv[], char * envp[])
// --verbose ; turns on logging
// --debug CATEGORY ; turns on debug logging
// --trace LEVEL ; turns on trace logging
+ // --memory ; turns on memory usage tracing
handle_debug_options(argc, argv);
#if defined(VERIFY_ON)
IF_VERIFY() initialize_memory_tracing();
diff --git a/src/pstream.h b/src/pstream.h
index a894325d..dfb27056 100644
--- a/src/pstream.h
+++ b/src/pstream.h
@@ -58,6 +58,8 @@ class ptristream : public std::istream
public:
ptrinbuf(char * _ptr, std::size_t _len) : ptr(_ptr), len(_len) {
+ TRACE_CTOR(ptrinbuf, "char *, std::size_t");
+
if (*ptr && len == 0)
len = std::strlen(ptr);
@@ -65,6 +67,9 @@ class ptristream : public std::istream
ptr, // read position
ptr+len); // end position
}
+ ~ptrinbuf() throw() {
+ TRACE_DTOR(ptrinbuf);
+ }
protected:
virtual int_type underflow() {
diff --git a/src/py_journal.cc b/src/py_journal.cc
index 550fb14e..50a52be9 100644
--- a/src/py_journal.cc
+++ b/src/py_journal.cc
@@ -151,8 +151,11 @@ namespace {
collector_wrapper(journal_t& _journal, report_t& base)
: journal(_journal), report(base),
- posts_collector(new collect_posts) {}
+ posts_collector(new collect_posts) {
+ TRACE_CTOR(collector_wrapper, "journal_t&, report_t&");
+ }
~collector_wrapper() {
+ TRACE_DTOR(collector_wrapper);
journal.clear_xdata();
}
diff --git a/src/report.cc b/src/report.cc
index bff068b8..28836d0f 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -321,7 +321,12 @@ namespace {
report_t& report;
posts_flusher(post_handler_ptr _handler, report_t& _report)
- : handler(_handler), report(_report) {}
+ : handler(_handler), report(_report) {
+ TRACE_CTOR(posts_flusher, "post_handler_ptr, report_t&");
+ }
+ ~posts_flusher() throw() {
+ TRACE_DTOR(posts_flusher);
+ }
void operator()(const value_t&) {
report.session.journal->clear_xdata();
diff --git a/src/report.h b/src/report.h
index aca4f466..37123377 100644
--- a/src/report.h
+++ b/src/report.h
@@ -119,9 +119,19 @@ public:
explicit report_t(session_t& _session)
: session(_session), terminus(CURRENT_TIME()),
- budget_flags(BUDGET_NO_BUDGET) {}
+ budget_flags(BUDGET_NO_BUDGET) {
+ TRACE_CTOR(report_t, "session_t&");
+ }
+ report_t(const report_t& report)
+ : session(report.session),
+ output_stream(report.output_stream),
+ terminus(report.terminus),
+ budget_flags(report.budget_flags) {
+ TRACE_CTOR(report_t, "copy");
+ }
virtual ~report_t() {
+ TRACE_DTOR(report_t);
output_stream.close();
}
@@ -1045,7 +1055,16 @@ class reporter
public:
reporter(shared_ptr<item_handler<Type> > _handler,
report_t& _report, const string& _whence)
- : handler(_handler), report(_report), whence(_whence) {}
+ : handler(_handler), report(_report), whence(_whence) {
+ TRACE_CTOR(reporter, "item_handler<Type>, report_t&, string");
+ }
+ reporter(const reporter& other)
+ : handler(other.handler), report(other.report), whence(other.whence) {
+ TRACE_CTOR(reporter, "copy");
+ }
+ ~reporter() throw() {
+ TRACE_DTOR(reporter);
+ }
value_t operator()(call_scope_t& args)
{
diff --git a/src/scope.h b/src/scope.h
index 134babb2..9318fc5c 100644
--- a/src/scope.h
+++ b/src/scope.h
@@ -142,6 +142,13 @@ private:
class empty_scope_t : public scope_t
{
public:
+ empty_scope_t() {
+ TRACE_CTOR(empty_scope_t, "");
+ }
+ ~empty_scope_t() throw() {
+ TRACE_DTOR(empty_scope_t);
+ }
+
virtual string description() {
return _("<empty>");
}
@@ -683,7 +690,12 @@ class value_scope_t : public child_scope_t
public:
value_scope_t(scope_t& _parent, const value_t& _value)
- : child_scope_t(_parent), value(_value) {}
+ : child_scope_t(_parent), value(_value) {
+ TRACE_CTOR(value_scope_t, "scope_t&, value_t");
+ }
+ ~value_scope_t() throw() {
+ TRACE_DTOR(value_scope_t);
+ }
virtual string description() {
return parent->description();
diff --git a/src/temps.h b/src/temps.h
index ad4e5672..f41c487c 100644
--- a/src/temps.h
+++ b/src/temps.h
@@ -51,7 +51,11 @@ class temporaries_t
optional<std::list<account_t> > acct_temps;
public:
+ temporaries_t() {
+ TRACE_CTOR(temporaries_t, "");
+ }
~temporaries_t() {
+ TRACE_DTOR(temporaries_t);
clear();
}
diff --git a/src/utils.cc b/src/utils.cc
index 628fb158..5a364008 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -270,13 +270,79 @@ void operator delete[](void * ptr, const std::nothrow_t&) throw() {
namespace ledger {
-inline void report_count_map(std::ostream& out, object_count_map& the_map)
-{
- foreach (object_count_map::value_type& pair, the_map)
- out << " " << std::right << std::setw(12) << pair.second.first
- << " " << std::right << std::setw(7) << pair.second.second
- << " " << std::left << pair.first
- << std::endl;
+namespace {
+ void stream_commified_number(std::ostream& out, std::size_t num)
+ {
+ std::ostringstream buf;
+ std::ostringstream obuf;
+
+ buf << num;
+
+ int integer_digits = 0;
+ // Count the number of integer digits
+ for (const char * p = buf.str().c_str(); *p; p++) {
+ if (*p == '.')
+ break;
+ else if (*p != '-')
+ integer_digits++;
+ }
+
+ for (const char * p = buf.str().c_str(); *p; p++) {
+ if (*p == '.') {
+ obuf << *p;
+ assert(integer_digits <= 3);
+ }
+ else if (*p == '-') {
+ obuf << *p;
+ }
+ else {
+ obuf << *p;
+
+ if (integer_digits > 3 && --integer_digits % 3 == 0)
+ obuf << ',';
+ }
+ }
+
+ out << obuf.str();
+ }
+
+ void stream_memory_size(std::ostream& out, std::size_t size)
+ {
+ std::ostringstream obuf;
+
+ if (size > 10 * 1024 * 1024)
+ obuf << "\033[1m";
+ if (size > 100 * 1024 * 1024)
+ obuf << "\033[31m";
+
+ obuf << std::setw(7);
+
+ if (size < 1024)
+ obuf << size << 'b';
+ else if (size < (1024 * 1024))
+ obuf << int(double(size) / 1024.0) << 'K';
+ else if (size < (1024 * 1024 * 1024))
+ obuf << int(double(size) / (1024.0 * 1024.0)) << 'M';
+ else
+ obuf << int(double(size) / (1024.0 * 1024.0 * 1024.0)) << 'G';
+
+ if (size > 10 * 1024 * 1024)
+ obuf << "\033[0m";
+
+ out << obuf.str();
+ }
+
+ void report_count_map(std::ostream& out, object_count_map& the_map)
+ {
+ foreach (object_count_map::value_type& pair, the_map) {
+ out << " " << std::right << std::setw(12);
+ stream_commified_number(out, pair.second.first);
+ out << " " << std::right << std::setw(7);
+ stream_memory_size(out, pair.second.second);
+ out << " " << std::left << pair.first
+ << std::endl;
+ }
+ }
}
std::size_t current_objects_size()
@@ -354,7 +420,7 @@ void trace_dtor_func(void * ptr, const char * cls_name, std::size_t cls_size)
void report_memory(std::ostream& out, bool report_all)
{
- if (! live_memory || ! memory_tracing_active) return;
+ if (! live_memory) return;
if (live_memory_count->size() > 0) {
out << "NOTE: There may be memory held by Boost "
@@ -366,11 +432,13 @@ void report_memory(std::ostream& out, bool report_all)
if (live_memory->size() > 0) {
out << "Live memory:" << std::endl;
- foreach (const memory_map::value_type& pair, *live_memory)
+ foreach (const memory_map::value_type& pair, *live_memory) {
out << " " << std::right << std::setw(12) << pair.first
- << " " << std::right << std::setw(7) << pair.second.second
- << " " << std::left << pair.second.first
+ << " " << std::right << std::setw(7);
+ stream_memory_size(out, pair.second.second);
+ out << " " << std::left << pair.second.first
<< std::endl;
+ }
}
if (report_all && total_memory_count->size() > 0) {
@@ -386,11 +454,13 @@ void report_memory(std::ostream& out, bool report_all)
if (live_objects->size() > 0) {
out << "Live objects:" << std::endl;
- foreach (const objects_map::value_type& pair, *live_objects)
+ foreach (const objects_map::value_type& pair, *live_objects) {
out << " " << std::right << std::setw(12) << pair.first
- << " " << std::right << std::setw(7) << pair.second.second
- << " " << std::left << pair.second.first
+ << " " << std::right << std::setw(7);
+ stream_memory_size(out, pair.second.second);
+ out << " " << std::left << pair.second.first
<< std::endl;
+ }
}
if (report_all) {
@@ -529,18 +599,6 @@ std::ostringstream _log_buffer;
uint8_t _trace_level;
#endif
-static inline void stream_memory_size(std::ostream& out, std::size_t size)
-{
- if (size < 1024)
- out << size << 'b';
- else if (size < (1024 * 1024))
- out << (double(size) / 1024.0) << 'K';
- else if (size < (1024 * 1024 * 1024))
- out << (double(size) / (1024.0 * 1024.0)) << 'M';
- else
- out << (double(size) / (1024.0 * 1024.0 * 1024.0)) << 'G';
-}
-
static bool logger_has_run = false;
static ptime logger_start;
diff --git a/test/baseline/opt-verify-memory.test b/test/baseline/opt-verify-memory.test
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/baseline/opt-verify-memory.test