[compiler-rt] r295108 - [PGO] Delay profile dir creation until write
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 14 13:39:56 PST 2017
Author: davidxl
Date: Tue Feb 14 15:39:55 2017
New Revision: 295108
URL: http://llvm.org/viewvc/llvm-project?rev=295108&view=rev
Log:
[PGO] Delay profile dir creation until write
Differential Revision: http://reviews.llvm.org/D29960
Added:
compiler-rt/trunk/test/profile/Linux/instrprof-dir.c
Modified:
compiler-rt/trunk/lib/profile/InstrProfilingFile.c
Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=295108&r1=295107&r2=295108&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Tue Feb 14 15:39:55 2017
@@ -172,6 +172,16 @@ static int doProfileMerging(FILE *Profil
return 0;
}
+/* Create the directory holding the file, if needed. */
+static void createProfileDir(const char *Filename) {
+ size_t Length = strlen(Filename);
+ if (lprofFindFirstDirSeparator(Filename)) {
+ char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1);
+ strncpy(Copy, Filename, Length + 1);
+ __llvm_profile_recursive_mkdir(Copy);
+ }
+}
+
/* Open the profile data for merging. It opens the file in r+b mode with
* file locking. If the file has content which is compatible with the
* current process, it also reads in the profile data in the file and merge
@@ -184,6 +194,7 @@ static FILE *openFileForMerging(const ch
FILE *ProfileFile;
int rc;
+ createProfileDir(ProfileFileName);
ProfileFile = lprofOpenFileEx(ProfileFileName);
if (!ProfileFile)
return NULL;
@@ -233,18 +244,13 @@ static void truncateCurrentFile(void) {
if (!Filename)
return;
- /* Create the directory holding the file, if needed. */
- if (lprofFindFirstDirSeparator(Filename)) {
- char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1);
- strncpy(Copy, Filename, Length + 1);
- __llvm_profile_recursive_mkdir(Copy);
- }
-
/* By pass file truncation to allow online raw profile
* merging. */
if (lprofCurFilename.MergePoolSize)
return;
+ createProfileDir(Filename);
+
/* Truncate the file. Later we'll reopen and append. */
File = fopen(Filename, "w");
if (!File)
Added: compiler-rt/trunk/test/profile/Linux/instrprof-dir.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/instrprof-dir.c?rev=295108&view=auto
==============================================================================
--- compiler-rt/trunk/test/profile/Linux/instrprof-dir.c (added)
+++ compiler-rt/trunk/test/profile/Linux/instrprof-dir.c Tue Feb 14 15:39:55 2017
@@ -0,0 +1,13 @@
+// RUN: %clang_pgogen -o %t %s
+// RUN: env LLVM_PROFILE_FILE="%t.d/%m.profraw"
+// RUN: rm -fr %t.d
+// RUN: %run %t %t.d
+
+#include <errno.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ if (access(argv[1], F_OK) == 0)
+ return 1; // %t.d should not exist yet.
+ return !(errno == ENOENT);
+}
More information about the llvm-commits
mailing list