diff options
author | Xinliang David Li <davidxl@google.com> | 2017-02-14 21:39:55 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2017-02-14 21:39:55 +0000 |
commit | 987d58d2e2e598413ba12ef07d413e95721e00b7 (patch) | |
tree | 65ee32372593b647d23df0cb3a517bb624e81b81 /lib/profile/InstrProfilingFile.c | |
parent | efaaf0df986bb8a07f20ff79fbd832174a95e289 (diff) |
[PGO] Delay profile dir creation until write
Differential Revision: http://reviews.llvm.org/D29960
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingFile.c')
-rw-r--r-- | lib/profile/InstrProfilingFile.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index f82080c98..cd3590e12 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -172,6 +172,16 @@ static int doProfileMerging(FILE *ProfileFile) { 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 char *ProfileFileName) { 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) |