[compiler-rt] r271922 - [profile] code cleanup /NFC

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 11:31:29 PDT 2016


Author: davidxl
Date: Mon Jun  6 13:31:29 2016
New Revision: 271922

URL: http://llvm.org/viewvc/llvm-project?rev=271922&view=rev
Log:
[profile] code cleanup /NFC

Address review feedback for better
readability.

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
    compiler-rt/trunk/test/profile/Inputs/instrprof-file_ex.c
    compiler-rt/trunk/test/profile/Linux/instrprof-file_ex.test

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=271922&r1=271921&r2=271922&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Mon Jun  6 13:31:29 2016
@@ -90,35 +90,43 @@ FILE *lprofOpenFileEx(const char *Profil
   s_flock.l_type = F_WRLCK;
   fd = open(ProfileName, O_RDWR | O_CREAT, 0666);
   if (fd < 0)
-    return 0;
+    return NULL;
 
-  while (fcntl(fd, F_SETLKW, &s_flock) && errno == EINTR)
-    continue;
+  while (fcntl(fd, F_SETLKW, &s_flock) == -1) {
+    if (errno != EINTR) {
+      if (errno == ENOLCK) {
+        PROF_WARN("Data may be corrupted during profile merging : %s\n",
+                  "Fail to obtain file lock due to system limit.");
+      }
+      break;
+    }
+  }
 
   f = fdopen(fd, "r+b");
 #elif defined(_WIN32)
   HANDLE h = CreateFile(ProfileName, GENERIC_READ | GENERIC_WRITE, 0, 0,
                         OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
   if (h == INVALID_HANDLE_VALUE)
-    return 0;
+    return NULL;
 
   fd = _open_osfhandle((intptr_t)h, 0);
   if (fd == -1) {
     CloseHandle(h);
-    return 0;
+    return NULL;
   }
 
   f = _fdopen(fd, "r+b");
   if (f == 0) {
     CloseHandle(h);
-    return 0;
+    return NULL;
   }
 #else
   /* Worst case no locking applied.  */
-  PROF_WARN("Concurrent file access is not supported : %s\n", "lack file locking");
+  PROF_WARN("Concurrent file access is not supported : %s\n",
+            "lack file locking");
   fd = open(ProfileName, O_RDWR | O_CREAT, 0666);
   if (fd < 0)
-    return 0;
+    return NULL;
   f = fdopen(fd, "r+b");
 #endif
 

Modified: compiler-rt/trunk/test/profile/Inputs/instrprof-file_ex.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/instrprof-file_ex.c?rev=271922&r1=271921&r2=271922&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Inputs/instrprof-file_ex.c (original)
+++ compiler-rt/trunk/test/profile/Inputs/instrprof-file_ex.c Mon Jun  6 13:31:29 2016
@@ -34,7 +34,7 @@ int main(int argc, char *argv[]) {
         exit(1);
       }
       fseek(F, 0, SEEK_END);
-      fprintf(F, "Dump from Child %d\n", i + 11);
+      fprintf(F, "Dump from Child %d\n", i);
       fclose(F);
       exit(0);
     } else {
@@ -54,6 +54,6 @@ int main(int argc, char *argv[]) {
     exit(1);
   }
   fseek(F, 0, SEEK_END);
-  fprintf(F, "Dump from parent %d\n", i + 11);
+  fprintf(F, "Dump from parent %d\n", i);
   return 0;
 }

Modified: compiler-rt/trunk/test/profile/Linux/instrprof-file_ex.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/instrprof-file_ex.test?rev=271922&r1=271921&r2=271922&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Linux/instrprof-file_ex.test (original)
+++ compiler-rt/trunk/test/profile/Linux/instrprof-file_ex.test Mon Jun  6 13:31:29 2016
@@ -1,16 +1,17 @@
 RUN: mkdir -p %t.d
 RUN: %clang_profgen -fprofile-instr-generate %S/../Inputs/instrprof-file_ex.c -o %t
+RUN: rm %t.d/run.dump
 RUN: %run %t %t.d/run.dump
 RUN: sort %t.d/run.dump | FileCheck %s
 
-CHECK: Dump from Child 11
-CHECK-NEXT: Dump from Child 12
-CHECK-NEXT: Dump from Child 13
-CHECK-NEXT: Dump from Child 14
-CHECK-NEXT: Dump from Child 15
-CHECK-NEXT: Dump from Child 16
-CHECK-NEXT: Dump from Child 17
-CHECK-NEXT: Dump from Child 18
-CHECK-NEXT: Dump from Child 19
-CHECK-NEXT: Dump from Child 20
-CHECK-NEXT: Dump from parent 21
+CHECK: Dump from Child 0
+CHECK-NEXT: Dump from Child 1
+CHECK-NEXT: Dump from Child 2
+CHECK-NEXT: Dump from Child 3
+CHECK-NEXT: Dump from Child 4
+CHECK-NEXT: Dump from Child 5
+CHECK-NEXT: Dump from Child 6
+CHECK-NEXT: Dump from Child 7 
+CHECK-NEXT: Dump from Child 8
+CHECK-NEXT: Dump from Child 9
+CHECK-NEXT: Dump from parent 10




More information about the llvm-commits mailing list