[compiler-rt] r333136 - [fuchsia] Add line buffering in RawWrite

Jake Ehrlich via llvm-commits llvm-commits at lists.llvm.org
Wed May 23 15:27:12 PDT 2018


Author: jakehehrlich
Date: Wed May 23 15:27:12 2018
New Revision: 333136

URL: http://llvm.org/viewvc/llvm-project?rev=333136&view=rev
Log:
[fuchsia] Add line buffering in RawWrite

This change causes RawWrite to buffer upto 128 bytes or until
a line is reached. This helps group calls into more readable
lines.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc?rev=333136&r1=333135&r2=333136&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc Wed May 23 15:27:12 2018
@@ -407,7 +407,31 @@ bool ReadFileToBuffer(const char *file_n
 }
 
 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 size_t lastLineEnd = 0;
+  static _Thread_local size_t cur = 0;
+
+  while (*buffer) {
+    if (cur >= size) {
+      if (lastLineEnd == 0)
+        lastLineEnd = size;
+      __sanitizer_log_write(line, lastLineEnd);
+      internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
+      cur = cur - lastLineEnd;
+      lastLineEnd = 0;
+    }
+    if (*buffer == '\n')
+      lastLineEnd = cur + 1;
+    line[cur++] = *buffer++;
+  }
+  // Flush all complete lines before returning.
+  if (lastLineEnd != 0) {
+    __sanitizer_log_write(line, lastLineEnd);
+    internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
+    cur = cur - lastLineEnd;
+    lastLineEnd = 0;
+  }
 }
 
 void CatastrophicErrorWrite(const char *buffer, uptr length) {




More information about the llvm-commits mailing list