summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfiling.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
commitad46436a217cc8a17a5bd8948cda0bd9dd6788c4 (patch)
tree69fee8a7849f75899cd3fa0e138968d0abec3ac5 /lib/profile/InstrProfiling.c
parent10692cccd92c84573854be22f01544324da328cf (diff)
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> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfiling.c')
-rw-r--r--lib/profile/InstrProfiling.c51
1 files changed, 4 insertions, 47 deletions
diff --git a/lib/profile/InstrProfiling.c b/lib/profile/InstrProfiling.c
index a62c214c1..de88f1ba3 100644
--- a/lib/profile/InstrProfiling.c
+++ b/lib/profile/InstrProfiling.c
@@ -10,9 +10,8 @@
#include "InstrProfiling.h"
#include <string.h>
-/* TODO: void __llvm_profile_get_size_for_buffer(void); */
-
-static uint64_t getMagic(void) {
+uint64_t __llvm_profile_get_magic(void) {
+ /* Magic number to detect file format and endianness. */
return
(uint64_t)'l' << 56 |
(uint64_t)'p' << 48 |
@@ -24,53 +23,11 @@ static uint64_t getMagic(void) {
(uint64_t)'w';
}
-static uint64_t getVersion(void) {
+uint64_t __llvm_profile_get_version(void) {
+ /* This should be bumped any time the output format changes. */
return 1;
}
-int __llvm_profile_write_buffer(FILE *OutputFile) {
- /* TODO: Requires libc: break requirement by taking a char* buffer instead of
- * a FILE stream.
- */
- 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 = getMagic();
- const uint64_t Version = getVersion();
- 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;
-}
-
void __llvm_profile_reset_counters(void) {
uint64_t *I = __llvm_profile_counters_begin();
uint64_t *E = __llvm_profile_counters_end();