diff options
author | Xinliang David Li <davidxl@google.com> | 2016-06-06 18:31:29 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-06-06 18:31:29 +0000 |
commit | 0891b6d59b2085b0bf453c2649cd4ce9a6c39f5f (patch) | |
tree | 0ca2ab65e9192e7dee315476f9555e3e1918c8fb | |
parent | 76c4a855bcb4bce60a9d0bdf57935338a9376f90 (diff) | |
download | bcm5719-llvm-0891b6d59b2085b0bf453c2649cd4ce9a6c39f5f.tar.gz bcm5719-llvm-0891b6d59b2085b0bf453c2649cd4ce9a6c39f5f.zip |
[profile] code cleanup /NFC
Address review feedback for better
readability.
llvm-svn: 271922
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingUtil.c | 26 | ||||
-rw-r--r-- | compiler-rt/test/profile/Inputs/instrprof-file_ex.c | 4 | ||||
-rw-r--r-- | compiler-rt/test/profile/Linux/instrprof-file_ex.test | 23 |
3 files changed, 31 insertions, 22 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c index 24e302d4a55..4c362371228 100644 --- a/compiler-rt/lib/profile/InstrProfilingUtil.c +++ b/compiler-rt/lib/profile/InstrProfilingUtil.c @@ -90,35 +90,43 @@ FILE *lprofOpenFileEx(const char *ProfileName) { s_flock.l_type = F_WRLCK; fd = open(ProfileName, O_RDWR | O_CREAT, 0666); if (fd < 0) - return 0; - - while (fcntl(fd, F_SETLKW, &s_flock) && errno == EINTR) - continue; + return NULL; + + 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 diff --git a/compiler-rt/test/profile/Inputs/instrprof-file_ex.c b/compiler-rt/test/profile/Inputs/instrprof-file_ex.c index 22e7555a13f..ba565711191 100644 --- a/compiler-rt/test/profile/Inputs/instrprof-file_ex.c +++ b/compiler-rt/test/profile/Inputs/instrprof-file_ex.c @@ -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; } diff --git a/compiler-rt/test/profile/Linux/instrprof-file_ex.test b/compiler-rt/test/profile/Linux/instrprof-file_ex.test index af79b7398cc..8b19b86ddcd 100644 --- a/compiler-rt/test/profile/Linux/instrprof-file_ex.test +++ b/compiler-rt/test/profile/Linux/instrprof-file_ex.test @@ -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 |