[PATCH] D45461: [sanitizer] Allow BackgroundThread to not depend on StackDepot v2

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 10 07:44:43 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT329706: [sanitizer] Allow BackgroundThread to not depend on StackDepot v2 (authored by cryptoad, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45461?vs=141751&id=141848#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45461

Files:
  lib/sanitizer_common/sanitizer_common_libcdep.cc


Index: lib/sanitizer_common/sanitizer_common_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_common_libcdep.cc
+++ lib/sanitizer_common/sanitizer_common_libcdep.cc
@@ -18,7 +18,6 @@
 #include "sanitizer_flags.h"
 #include "sanitizer_procmaps.h"
 #include "sanitizer_report_decorator.h"
-#include "sanitizer_stackdepot.h"
 #include "sanitizer_stacktrace.h"
 #include "sanitizer_symbolizer.h"
 
@@ -113,32 +112,39 @@
 }
 
 #if SANITIZER_LINUX && !SANITIZER_GO
+// Weak default implementation for when sanitizer_stackdepot is not linked in.
+SANITIZER_WEAK_ATTRIBUTE StackDepotStats *StackDepotGetStats() {
+  return nullptr;
+}
+
 void BackgroundThread(void *arg) {
-  uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb;
-  uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb;
-  bool heap_profile = common_flags()->heap_profile;
+  const uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb;
+  const uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb;
+  const bool heap_profile = common_flags()->heap_profile;
   uptr prev_reported_rss = 0;
   uptr prev_reported_stack_depot_size = 0;
   bool reached_soft_rss_limit = false;
   uptr rss_during_last_reported_profile = 0;
   while (true) {
     SleepForMillis(100);
-    uptr current_rss_mb = GetRSS() >> 20;
+    const uptr current_rss_mb = GetRSS() >> 20;
     if (Verbosity()) {
       // If RSS has grown 10% since last time, print some information.
       if (prev_reported_rss * 11 / 10 < current_rss_mb) {
         Printf("%s: RSS: %zdMb\n", SanitizerToolName, current_rss_mb);
         prev_reported_rss = current_rss_mb;
       }
       // If stack depot has grown 10% since last time, print it too.
       StackDepotStats *stack_depot_stats = StackDepotGetStats();
-      if (prev_reported_stack_depot_size * 11 / 10 <
-          stack_depot_stats->allocated) {
-        Printf("%s: StackDepot: %zd ids; %zdM allocated\n",
-               SanitizerToolName,
-               stack_depot_stats->n_uniq_ids,
-               stack_depot_stats->allocated >> 20);
-        prev_reported_stack_depot_size = stack_depot_stats->allocated;
+      if (stack_depot_stats) {
+        if (prev_reported_stack_depot_size * 11 / 10 <
+            stack_depot_stats->allocated) {
+          Printf("%s: StackDepot: %zd ids; %zdM allocated\n",
+                 SanitizerToolName,
+                 stack_depot_stats->n_uniq_ids,
+                 stack_depot_stats->allocated >> 20);
+          prev_reported_stack_depot_size = stack_depot_stats->allocated;
+        }
       }
     }
     // Check RSS against the limit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45461.141848.patch
Type: text/x-patch
Size: 2660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180410/be8cf99b/attachment.bin>


More information about the llvm-commits mailing list