summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/profile/InstrProfilingExtras.c
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 00:27:50 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 00:27:50 +0000
commit4543aac96efcfcd316da6d4d9fe97f6edeec7a48 (patch)
treec1b4d94731c5ac1d75acff34b0bf61c58f32f495 /compiler-rt/lib/profile/InstrProfilingExtras.c
parente5edc8869b4b0fb05ad4639131cada1f77fcc544 (diff)
downloadbcm5719-llvm-4543aac96efcfcd316da6d4d9fe97f6edeec7a48.tar.gz
bcm5719-llvm-4543aac96efcfcd316da6d4d9fe97f6edeec7a48.zip
PGO: Indicate errors in profile runtime API
Return 0 for success, non-0 for failure. llvm-svn: 204415
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingExtras.c')
-rw-r--r--compiler-rt/lib/profile/InstrProfilingExtras.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingExtras.c b/compiler-rt/lib/profile/InstrProfilingExtras.c
index bf727068050..723952f0856 100644
--- a/compiler-rt/lib/profile/InstrProfilingExtras.c
+++ b/compiler-rt/lib/profile/InstrProfilingExtras.c
@@ -10,19 +10,22 @@
#include "InstrProfiling.h"
#include <string.h>
-static void __llvm_profile_write_file_with_name(const char *OutputName) {
+static int __llvm_profile_write_file_with_name(const char *OutputName) {
+ int RetVal;
FILE *OutputFile;
if (!OutputName || !OutputName[0])
- return;
+ return -1;
OutputFile = fopen(OutputName, "w");
- if (!OutputFile) return;
+ if (!OutputFile)
+ return -1;
/* TODO: mmap file to buffer of size __llvm_profile_get_size_for_buffer() and
* pass the buffer in, instead of the file.
*/
- __llvm_profile_write_buffer(OutputFile);
+ RetVal = __llvm_profile_write_buffer(OutputFile);
fclose(OutputFile);
+ return RetVal;
}
static const char *CurrentFilename = NULL;
@@ -31,9 +34,10 @@ void __llvm_profile_set_filename(const char *Filename) {
}
int getpid(void);
-void __llvm_profile_write_file(void) {
+int __llvm_profile_write_file(void) {
char *AllocatedFilename = NULL;
int I, J;
+ int RetVal;
#define MAX_PID_SIZE 16
char PidChars[MAX_PID_SIZE] = { 0 };
@@ -54,13 +58,13 @@ void __llvm_profile_write_file(void) {
if (!NumPids++) {
PidLength = snprintf(PidChars, MAX_PID_SIZE, "%d", getpid());
if (PidLength <= 0)
- return;
+ return -1;
}
if (NumPids) {
// Allocate enough space for the substituted filename.
AllocatedFilename = (char*)malloc(I + NumPids*(PidLength - 2) + 1);
if (!AllocatedFilename)
- return;
+ return -1;
// Construct the new filename.
for (I = 0, J = 0; Filename[I]; ++I)
@@ -79,18 +83,23 @@ void __llvm_profile_write_file(void) {
}
// Write the file.
- __llvm_profile_write_file_with_name(Filename);
+ RetVal = __llvm_profile_write_file_with_name(Filename);
// Free the filename.
if (AllocatedFilename)
free(AllocatedFilename);
+
+ return RetVal;
}
+static void writeFileWithoutReturn(void) {
+ __llvm_profile_write_file();
+}
void __llvm_profile_register_write_file_atexit(void) {
static int HasBeenRegistered = 0;
if (!HasBeenRegistered) {
HasBeenRegistered = 1;
- atexit(__llvm_profile_write_file);
+ atexit(writeFileWithoutReturn);
}
}
OpenPOWER on IntegriCloud