<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 8, 2014 at 5:23 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: kcc<br>
Date: Mon Dec  8 19:22:59 2014<br>
New Revision: 223730<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223730&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223730&view=rev</a><br>
Log:<br>
[asan] move GetRSS from tsan to sanitizer_common<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc<br>
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h<br>
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc<br>
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc<br>
    compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Dec  8 19:22:59 2014<br>
@@ -66,6 +66,7 @@ bool MemoryRangeIsAvailable(uptr range_s<br>
 void FlushUnneededShadowMemory(uptr addr, uptr size);<br>
 void IncreaseTotalMmap(uptr size);<br>
 void DecreaseTotalMmap(uptr size);<br>
+uptr GetRSS();<br>
<br>
 // InternalScopedBuffer can be used instead of large stack arrays to<br>
 // keep frame size low.<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Mon Dec  8 19:22:59 2014<br>
@@ -379,6 +379,34 @@ static void ReadNullSepFileToArray(const<br>
   }<br>
   (*arr)[count] = 0;<br>
 }<br>
+<br>
+uptr GetRSS() {<br>
+  uptr fd = OpenFile("/proc/self/statm", false);<br>
+  if ((sptr)fd < 0)<br>
+    return 0;<br></blockquote><div><br></div><div>^^</div><div>You should use internal_iserror() here</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  char buf[64];<br>
+  uptr len = internal_read(fd, buf, sizeof(buf) - 1);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+  internal_close(fd);<br>
+  if ((sptr)len <= 0)<br>
+    return 0;<br></blockquote><div><br></div><div>^^ and probably here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  buf[len] = 0;<br>
+  // The format of the file is:<br>
+  // 1084 89 69 11 0 79 0<br>
+  // We need the second number which is RSS in 4K units.<br>
+  char *pos = buf;<br>
+  // Skip the first number.<br>
+  while (*pos >= '0' && *pos <= '9')<br>
+    pos++;<br>
+  // Skip whitespaces.<br>
+  while (!(*pos >= '0' && *pos <= '9') && *pos != 0)<br>
+    pos++;<br>
+  // Read the number.<br>
+  uptr rss = 0;<br>
+  while (*pos >= '0' && *pos <= '9')<br>
+    rss = rss * 10 + *pos++ - '0';<br></blockquote><div><br></div><div>I think you can greatly simplify this by using internal_simple_strtoll() function.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  return rss * 4096;<br>
+}<br>
+<br>
 #endif<br>
<br>
 static void GetArgsAndEnv(char*** argv, char*** envp) {<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Dec  8 19:22:59 2014<br>
@@ -317,6 +317,10 @@ MacosVersion GetMacosVersion() {<br>
   return result;<br>
 }<br>
<br>
+uptr GetRSS() {<br>
+  return 0;<br>
+}<br>
+<br>
 }  // namespace __sanitizer<br>
<br>
 #endif  // SANITIZER_MAC<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Mon Dec  8 19:22:59 2014<br>
@@ -375,6 +375,10 @@ uptr internal_rename(const char *oldpath<br>
   UNIMPLEMENTED();<br>
 }<br>
<br>
+uptr GetRSS() {<br>
+  return 0;<br>
+}<br>
+<br>
 // ---------------------- BlockingMutex ---------------- {{{1<br>
 const uptr LOCK_UNINITIALIZED = 0;<br>
 const uptr LOCK_READY = (uptr)-1;<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h Mon Dec  8 19:22:59 2014<br>
@@ -251,7 +251,6 @@ uptr ALWAYS_INLINE GetThreadTraceHeader(<br>
 void InitializePlatform();<br>
 void FlushShadowMemory();<br>
 void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive);<br>
-uptr GetRSS();<br>
<br>
 void *internal_start_thread(void(*func)(void*), void *arg);<br>
 void internal_join_thread(void *th);<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Mon Dec  8 19:22:59 2014<br>
@@ -118,33 +118,6 @@ void WriteMemoryProfile(char *buf, uptr<br>
       nlive, nthread);<br>
 }<br>
<br>
-uptr GetRSS() {<br>
-  uptr fd = OpenFile("/proc/self/statm", false);<br>
-  if ((sptr)fd < 0)<br>
-    return 0;<br>
-  char buf[64];<br>
-  uptr len = internal_read(fd, buf, sizeof(buf) - 1);<br>
-  internal_close(fd);<br>
-  if ((sptr)len <= 0)<br>
-    return 0;<br>
-  buf[len] = 0;<br>
-  // The format of the file is:<br>
-  // 1084 89 69 11 0 79 0<br>
-  // We need the second number which is RSS in 4K units.<br>
-  char *pos = buf;<br>
-  // Skip the first number.<br>
-  while (*pos >= '0' && *pos <= '9')<br>
-    pos++;<br>
-  // Skip whitespaces.<br>
-  while (!(*pos >= '0' && *pos <= '9') && *pos != 0)<br>
-    pos++;<br>
-  // Read the number.<br>
-  uptr rss = 0;<br>
-  while (*pos >= '0' && *pos <= '9')<br>
-    rss = rss * 10 + *pos++ - '0';<br>
-  return rss * 4096;<br>
-}<br>
-<br>
 #if SANITIZER_LINUX<br>
 void FlushShadowMemoryCallback(<br>
     const SuspendedThreadsList &suspended_threads_list,<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_mac.cc Mon Dec  8 19:22:59 2014<br>
@@ -50,10 +50,6 @@ void FlushShadowMemory() {<br>
 void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) {<br>
 }<br>
<br>
-uptr GetRSS() {<br>
-  return 0;<br>
-}<br>
-<br>
 #ifndef TSAN_GO<br>
 void InitializeShadowMemory() {<br>
   uptr shadow = (uptr)MmapFixedNoReserve(kShadowBeg,<br>
<br>
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc?rev=223730&r1=223729&r2=223730&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc?rev=223730&r1=223729&r2=223730&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc (original)<br>
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_windows.cc Mon Dec  8 19:22:59 2014<br>
@@ -31,10 +31,6 @@ void FlushShadowMemory() {<br>
 void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) {<br>
 }<br>
<br>
-uptr GetRSS() {<br>
-  return 0;<br>
-}<br>
-<br>
 void InitializePlatform() {<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Alexey Samsonov<br><a href="mailto:vonosmas@gmail.com" target="_blank">vonosmas@gmail.com</a></div></div>
</div></div>