summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingFile.c
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-24 01:23:09 +0000
committerXinliang David Li <davidxl@google.com>2016-05-24 01:23:09 +0000
commit46ef7f54dfd94166caffd8499806079579b9be9c (patch)
tree97a814e6c94ce5e587578d2d51f122cf72392e31 /lib/profile/InstrProfilingFile.c
parent6d872768fea44f055826ecc28807a3e9b1f238e7 (diff)
[profile] clean up file initialization code
Also added more documentation. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingFile.c')
-rw-r--r--lib/profile/InstrProfilingFile.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c
index ab98cb8da..d5abf9fee 100644
--- a/lib/profile/InstrProfilingFile.c
+++ b/lib/profile/InstrProfilingFile.c
@@ -181,42 +181,50 @@ static int setFilenamePossiblyWithPid(const char *Filename) {
return 0;
}
-static int setFilenameFromEnvironment(void) {
+static const char *getFilenameFromEnv(void) {
const char *Filename = getenv("LLVM_PROFILE_FILE");
-
if (!Filename || !Filename[0])
- return -1;
-
- return setFilenamePossiblyWithPid(Filename);
-}
-
-static void setFilenameAutomatically(void) {
- if (!setFilenameFromEnvironment())
- return;
-
- resetFilenameToDefault();
+ return 0;
+ return Filename;
}
+/* 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
+ * environment variable can override this default value. */
COMPILER_RT_VISIBILITY
void __llvm_profile_initialize_file(void) {
+ const char *Filename;
/* Check if the filename has been initialized. */
if (__llvm_profile_CurrentFilename)
return;
/* Detect the filename and truncate. */
- setFilenameAutomatically();
+ Filename = getFilenameFromEnv();
+ if (!Filename || setFilenamePossiblyWithPid(Filename))
+ resetFilenameToDefault();
}
+/* This API is directly called by the user application code. It has the
+ * highest precedence compared with LLVM_PROFILE_FILE environment variable
+ * and command line option -fprofile-istr-generate=<profile_name>.
+ */
COMPILER_RT_VISIBILITY
void __llvm_profile_set_filename(const char *Filename) {
setFilenamePossiblyWithPid(Filename);
}
+/*
+ * This API is invoked by the global initializers emitted by Clang/LLVM when
+ * -fprofile-instr-generate=<..> is specified (vs -fprofile-instr-generate
+ * without an argument). This option has lower precedence than the
+ * LLVM_PROFILE_FILE environment variable.
+ */
COMPILER_RT_VISIBILITY
void __llvm_profile_override_default_filename(const char *Filename) {
/* If the env var is set, skip setting filename from argument. */
- const char *Env_Filename = getenv("LLVM_PROFILE_FILE");
- if (Env_Filename && Env_Filename[0])
+ const char *Env_Filename = getFilenameFromEnv();
+ if (Env_Filename)
return;
setFilenamePossiblyWithPid(Filename);
}