[PATCH] D47170: [fuchsia] Add line buffering in RawWrite

Jake Ehrlich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 14:50:41 PDT 2018


jakehehrlich updated this revision to Diff 148106.
jakehehrlich added a comment.

Modified to group multiple lines into a single flush but still flush at least once if a newline is found.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D47170

Files:
  compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc


Index: compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
+++ compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -407,7 +407,32 @@
 }
 
 void RawWrite(const char *buffer) {
-  __sanitizer_log_write(buffer, internal_strlen(buffer));
+  constexpr size_t size = 128;
+  static _Thread_local char line[size];
+  static _Thread_local char *lastNewline = nullptr;
+  static _Thread_local size_t cur = 0;
+
+  while (*buffer) {
+    if (cur >= size) {
+      if (lastNewline == nullptr)
+        lastNewline = line;
+      __sanitizer_log_write(line, lastNewline - line);
+      internal_memmove(line, lastNewline, line + size - lastNewline);
+      cur = 0;
+      lastNewline = nullptr;
+    }
+    if (*buffer == '\n')
+      lastNewline = line + cur;
+    line[cur++] = *buffer++;
+  }
+  // Flush if there's a newline in the buffer but the buffer isn't full.
+  // This prevents the last few lines from not being flushed.
+  if (lastNewline != nullptr) {
+    __sanitizer_log_write(line, lastNewline - line);
+    internal_memmove(line, lastNewline, line + cur - lastNewline);
+    cur = 0;
+    lastNewline = nullptr;
+  }
 }
 
 void CatastrophicErrorWrite(const char *buffer, uptr length) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47170.148106.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/01153732/attachment.bin>


More information about the llvm-commits mailing list