diff options
author | Xinliang David Li <davidxl@google.com> | 2016-07-20 04:26:09 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-07-20 04:26:09 +0000 |
commit | cd776714f503eb9bf284f77cd7e861ba5e516c0f (patch) | |
tree | b8cc783d60187ebbe9c9cfdd1acbef286f2175ad /lib/profile/InstrProfilingFile.c | |
parent | c2512f9d99dd5effcfa1ba9790008a96ec8c36d1 (diff) |
[Profile] implement interface to get profile path prefix
Differential Revision: http://reviews.llvm.org/D22546
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingFile.c')
-rw-r--r-- | lib/profile/InstrProfilingFile.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c index 6670a2361..52715dd0b 100644 --- a/lib/profile/InstrProfilingFile.c +++ b/lib/profile/InstrProfilingFile.c @@ -63,6 +63,7 @@ static const char *getPNSStr(ProfileNameSpecifier PNS) { typedef struct lprofFilename { /* File name string possibly with %p or %h specifiers. */ const char *FilenamePat; + const char *ProfilePathPrefix; char PidChars[MAX_PID_SIZE]; char Hostname[COMPILER_RT_MAX_HOSTLEN]; unsigned NumPids; @@ -78,7 +79,7 @@ typedef struct lprofFilename { ProfileNameSpecifier PNS; } lprofFilename; -lprofFilename lprofCurFilename = {0, {0}, {0}, 0, 0, 0, PNS_unknown}; +lprofFilename lprofCurFilename = {0, 0, {0}, {0}, 0, 0, 0, PNS_unknown}; int getpid(void); static int getCurFilenameLength(); @@ -344,6 +345,12 @@ static void parseAndSetFilename(const char *FilenamePat, getPNSStr(PNS)); } + /* Clean up cached prefix. */ + if (lprofCurFilename.ProfilePathPrefix) { + free((void*)lprofCurFilename.ProfilePathPrefix); + lprofCurFilename.ProfilePathPrefix = NULL; + } + if (!lprofCurFilename.MergePoolSize) truncateCurrentFile(); } @@ -425,6 +432,37 @@ static const char *getFilenamePatFromEnv(void) { return Filename; } +COMPILER_RT_VISIBILITY +const char *__llvm_profile_get_path_prefix(void) { + int Length; + char *FilenameBuf, *Prefix; + const char *Filename, *PrefixEnd; + + if (lprofCurFilename.ProfilePathPrefix) + return lprofCurFilename.ProfilePathPrefix; + + Length = getCurFilenameLength(); + FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); + Filename = getCurFilename(FilenameBuf); + if (!Filename) + return "\0"; + + PrefixEnd = lprofFindLastDirSeparator(Filename); + if (!PrefixEnd) + return "\0"; + + Length = PrefixEnd - Filename + 1; + Prefix = (char *)malloc(Length + 1); + if (!Prefix) { + PROF_ERR("Failed to %s\n", "allocate memory."); + return "\0"; + } + memcpy(Prefix, Filename, Length); + Prefix[Length] = '\0'; + lprofCurFilename.ProfilePathPrefix = Prefix; + return Prefix; +} + /* This method is invoked by the runtime initialization hook * InstrProfilingRuntime.o if it is linked in. Both user specified * profile path via -fprofile-instr-generate= and LLVM_PROFILE_FILE |