diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:22 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-03-21 18:29:22 +0000 |
commit | 117cf2bd1ff585f9754b5f30f5a4cfd65b230bbf (patch) | |
tree | 08ca07d872346e5092f8cdebf84317c0c32b9e4b /compiler-rt/lib/profile/InstrProfilingBuffer.c | |
parent | cf4bb960bd915218eebc91b8bd61a2176c3361cd (diff) | |
download | bcm5719-llvm-117cf2bd1ff585f9754b5f30f5a4cfd65b230bbf.tar.gz bcm5719-llvm-117cf2bd1ff585f9754b5f30f5a4cfd65b230bbf.zip |
InstrProf: Write the __llvm_profile_write_buffer()
Write __llvm_profile_write_buffer(), which uses the same logic as
__llvm_profile_write_file(), but writes directly to a provided `char*`
buffer instead.
<rdar://problem/15943240>
llvm-svn: 204499
Diffstat (limited to 'compiler-rt/lib/profile/InstrProfilingBuffer.c')
-rw-r--r-- | compiler-rt/lib/profile/InstrProfilingBuffer.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c b/compiler-rt/lib/profile/InstrProfilingBuffer.c index 36d892f6588..2d91961a616 100644 --- a/compiler-rt/lib/profile/InstrProfilingBuffer.c +++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c @@ -10,5 +10,48 @@ #include "InstrProfiling.h" #include <string.h> -/* TODO: uint64_t __llvm_profile_get_size_for_buffer(void) */ -/* TODO: int __llvm_profile_write_buffer(char *Buffer) */ +uint64_t __llvm_profile_get_size_for_buffer(void) { + return sizeof(uint64_t) * 7 + + PROFILE_RANGE_SIZE(data) * sizeof(__llvm_profile_data) + + PROFILE_RANGE_SIZE(counters) * sizeof(uint64_t) + + PROFILE_RANGE_SIZE(names) * sizeof(char); +} + +int __llvm_profile_write_buffer(char *Buffer) { + 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; + + /* Create the header. */ + uint64_t Header[] = { + __llvm_profile_get_magic(), + __llvm_profile_get_version(), + DataSize, + CountersSize, + NamesSize, + (uint64_t)CountersBegin, + (uint64_t)NamesBegin + }; + + /* Write the data. */ +#define UPDATE_memcpy(Data, Size) \ + do { \ + memcpy(Buffer, Data, Size); \ + Buffer += Size; \ + } while (0) + UPDATE_memcpy(Header, sizeof(Header)); + UPDATE_memcpy(DataBegin, DataSize * sizeof(__llvm_profile_data)); + UPDATE_memcpy(CountersBegin, CountersSize * sizeof(uint64_t)); + UPDATE_memcpy(NamesBegin, NamesSize * sizeof(char)); +#undef UPDATE_memcpy + + return 0; +} |