diff --git a/gc_sections.cc b/gc_sections.cc index e4306610..ded9b3b2 100644 --- a/gc_sections.cc +++ b/gc_sections.cc @@ -115,7 +115,7 @@ static void mark(tbb::concurrent_vector roots) { // Remove unreachable sections static void sweep() { - Timer t3("sweep"); + Timer t("sweep"); static Counter counter("garbage_sections"); tbb::parallel_for_each(out::objs, [&](ObjectFile *file) { diff --git a/main.cc b/main.cc index b852feeb..11409d9a 100644 --- a/main.cc +++ b/main.cc @@ -889,6 +889,9 @@ int main(int argc, char **argv) { on_complete = fork_child(); } + if (config.print_stats) + Counter::enabled = true; + for (std::string_view arg : config.trace_symbol) Symbol::intern(arg)->traced = true; diff --git a/mold.h b/mold.h index 060f4715..03f504d7 100644 --- a/mold.h +++ b/mold.h @@ -1102,17 +1102,21 @@ public: } Counter &operator++(int) { - values.local()++; + if (enabled) + values.local()++; return *this; } Counter &operator+=(int delta) { - values.local() += delta; + if (enabled) + values.local() += delta; return *this; } static void print(); + static inline bool enabled = false; + private: i64 get_value();