diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:15 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:15 +0000 |
| commit | be0a5e176b6cadae34b14a7efac7eae2d918cfb6 (patch) | |
| tree | 585c0ec1ada6e845167029fa5ec7e388a0bc22c7 /compiler-rt/lib/profile/InstrProfilingBuffer.c | |
| parent | 24b4b6533925e6dbd0faef7976c7f794499e0ec6 (diff) | |
| download | bcm5719-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/InstrProfilingBuffer.c')
| -rw-r--r-- | compiler-rt/lib/profile/InstrProfilingBuffer.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c new file mode 100644 index 00000000000..7b662ca7dd9 --- /dev/null +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -0,0 +1,54 @@ +/*===- InstrProfilingBuffer.c - Write instrumentation to a memory buffer --===*\ +|* +|* 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> + +/* TODO: uint64_t __llvm_profile_get_size_for_buffer(void) */ + +int __llvm_profile_write_buffer(FILE *OutputFile) { + 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, OutputFile); + CHECK_fwrite(&Version, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&DataSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&CountersSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&NamesSize, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&CountersDelta, sizeof(uint64_t), 1, OutputFile); + CHECK_fwrite(&NamesDelta, sizeof(uint64_t), 1, OutputFile); + + /* Write the data. */ + CHECK_fwrite(DataBegin, sizeof(__llvm_profile_data), DataSize, OutputFile); + CHECK_fwrite(CountersBegin, sizeof(uint64_t), CountersSize, OutputFile); + CHECK_fwrite(NamesBegin, sizeof(char), NamesSize, OutputFile); + +#undef CHECK_fwrite + + return 0; +} |

