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 18:29:15 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 18:29:15 +0000
commitbe0a5e176b6cadae34b14a7efac7eae2d918cfb6 (patch)
tree585c0ec1ada6e845167029fa5ec7e388a0bc22c7 /compiler-rt/lib/profile/InstrProfilingExtras.c
parent24b4b6533925e6dbd0faef7976c7f794499e0ec6 (diff)
downloadbcm5719-llvm-be0a5e176b6cadae34b14a7efac7eae2d918cfb6.tar.gz
bcm5719-llvm-be0a5e176b6cadae34b14a7efac7eae2d918cfb6.zip
InstrProf: Reorganize files; no functionality change
Move functions around to prepare for some other changes. - Merge InstrProfilingExtras.h with InstrProfiling.h. There's no benefit to having these split. - Rename InstrProfilingExtras.c to InstrProfilingFile.c. - Split actual buffer writing code out of InstrProfiling.c into InstrProfilingBuffer.c. - Drive-by corrections of a couple of header comments. <rdar://problem/15943240> llvm-svn: 204497
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingExtras.c')
-rw-r--r--compiler-rt/lib/profile/InstrProfilingExtras.c105
1 files changed, 0 insertions, 105 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingExtras.c b/compiler-rt/lib/profile/InstrProfilingExtras.c
deleted file mode 100644
index 723952f0856..00000000000
--- a/compiler-rt/lib/profile/InstrProfilingExtras.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*===- InstrProfilingExtras.c - Support library for PGO instrumentation ---===*\
-|*
-|* The LLVM Compiler Infrastructure
-|*
-|* This file is distributed under the University of Illinois Open Source
-|* License. See LICENSE.TXT for details.
-|*
-\*===----------------------------------------------------------------------===*/
-
-#include "InstrProfiling.h"
-#include <string.h>
-
-static int __llvm_profile_write_file_with_name(const char *OutputName) {
- int RetVal;
- FILE *OutputFile;
- if (!OutputName || !OutputName[0])
- return -1;
- OutputFile = fopen(OutputName, "w");
- 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.
- */
- RetVal = __llvm_profile_write_buffer(OutputFile);
-
- fclose(OutputFile);
- return RetVal;
-}
-
-static const char *CurrentFilename = NULL;
-void __llvm_profile_set_filename(const char *Filename) {
- CurrentFilename = Filename;
-}
-
-int getpid(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 };
- int PidLength = 0;
- int NumPids = 0;
-
- // Get the filename.
- const char *Filename = CurrentFilename;
-#define UPDATE_FILENAME(NextFilename) \
- if (!Filename || !Filename[0]) Filename = NextFilename
- UPDATE_FILENAME(getenv("LLVM_PROFILE_FILE"));
- UPDATE_FILENAME("default.profdata");
-#undef UPDATE_FILENAME
-
- // Check the filename for "%p", which indicates a pid-substitution.
- for (I = 0; Filename[I]; ++I)
- if (Filename[I] == '%' && Filename[++I] == 'p')
- if (!NumPids++) {
- PidLength = snprintf(PidChars, MAX_PID_SIZE, "%d", getpid());
- if (PidLength <= 0)
- return -1;
- }
- if (NumPids) {
- // Allocate enough space for the substituted filename.
- AllocatedFilename = (char*)malloc(I + NumPids*(PidLength - 2) + 1);
- if (!AllocatedFilename)
- return -1;
-
- // Construct the new filename.
- for (I = 0, J = 0; Filename[I]; ++I)
- if (Filename[I] == '%') {
- if (Filename[++I] == 'p') {
- memcpy(AllocatedFilename + J, PidChars, PidLength);
- J += PidLength;
- }
- // Drop any unknown substitutions.
- } else
- AllocatedFilename[J++] = Filename[I];
- AllocatedFilename[J] = 0;
-
- // Actually use the computed name.
- Filename = AllocatedFilename;
- }
-
- // Write the file.
- 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(writeFileWithoutReturn);
- }
-}
OpenPOWER on IntegriCloud