diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:19 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:19 +0000 |
| commit | cf4bb960bd915218eebc91b8bd61a2176c3361cd (patch) | |
| tree | d7fc2fb51ef7849fb6cedb637fb62a87d547b2db /compiler-rt/lib/profile/InstrProfilingFile.c | |
| parent | be0a5e176b6cadae34b14a7efac7eae2d918cfb6 (diff) | |
| download | bcm5719-llvm-cf4bb960bd915218eebc91b8bd61a2176c3361cd.tar.gz bcm5719-llvm-cf4bb960bd915218eebc91b8bd61a2176c3361cd.zip | |
InstrProf: If libc is available, use it; no functionality change
It was misguided to plan to rely on __llvm_profile_write_buffer() in
__llvm_profile_write_file(). It's less complex to duplicate the writing
logic than to mmap the file.
Since it's here to stay, move `FILE*`-based writing logic into
InstrProfilingFile.c.
<rdar://problem/15943240>
llvm-svn: 204498
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingFile.c')
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingFile.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 505d748f77c..27fa92611e6 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -12,6 +12,47 @@ #include <stdlib.h> #include <string.h> +static int writeFile(FILE *File) { + const __llvm_profile_data *DataBegin = __llvm_profile_data_begin(); + const __llvm_profile_data *DataEnd = __llvm_profile_data_end(); + const uint64_t *CountersBegin = __llvm_profile_counters_begin(); + const uint64_t *CountersEnd = __llvm_profile_counters_end(); + const char *NamesBegin = __llvm_profile_names_begin(); + const char *NamesEnd = __llvm_profile_names_end(); + + /* Calculate size of sections. */ + const uint64_t DataSize = DataEnd - DataBegin; + const uint64_t CountersSize = CountersEnd - CountersBegin; + const uint64_t NamesSize = NamesEnd - NamesBegin; + + /* Get rest of header data. */ + const uint64_t Magic = __llvm_profile_get_magic(); + const uint64_t Version = __llvm_profile_get_version(); + const uint64_t CountersDelta = (uint64_t)CountersBegin; + const uint64_t NamesDelta = (uint64_t)NamesBegin; + +#define CHECK_fwrite(Data, Size, Length, File) \ + do { if (fwrite(Data, Size, Length, File) != Length) return -1; } while (0) + + /* Write the header. */ + CHECK_fwrite(&Magic, sizeof(uint64_t), 1, File); + CHECK_fwrite(&Version, sizeof(uint64_t), 1, File); + CHECK_fwrite(&DataSize, sizeof(uint64_t), 1, File); + CHECK_fwrite(&CountersSize, sizeof(uint64_t), 1, File); + CHECK_fwrite(&NamesSize, sizeof(uint64_t), 1, File); + CHECK_fwrite(&CountersDelta, sizeof(uint64_t), 1, File); + CHECK_fwrite(&NamesDelta, sizeof(uint64_t), 1, File); + + /* Write the data. */ + CHECK_fwrite(DataBegin, sizeof(__llvm_profile_data), DataSize, File); + CHECK_fwrite(CountersBegin, sizeof(uint64_t), CountersSize, File); + CHECK_fwrite(NamesBegin, sizeof(char), NamesSize, File); + +#undef CHECK_fwrite + + return 0; +} + static int writeFileWithName(const char *OutputName) { int RetVal; FILE *OutputFile; @@ -21,7 +62,7 @@ static int writeFileWithName(const char *OutputName) { if (!OutputFile) return -1; - RetVal = __llvm_profile_write_buffer(OutputFile); + RetVal = writeFile(OutputFile); fclose(OutputFile); return RetVal; |

