summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingFile.c
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-13 18:26:26 +0000
committerXinliang David Li <davidxl@google.com>2016-05-13 18:26:26 +0000
commitd2006b722b9193efa23a990d60fd0eaddb92c70b (patch)
tree83bc96f96774d846de35e0e633159c569ae1d3c9 /lib/profile/InstrProfilingFile.c
parent84611c6a8dfbf9cdffe3d19fd9805f4abed15c6d (diff)
[profile] Eliminate dynamic memory allocation for buffered writer
With this change, dynamic memory allocation is only used for testing purpose. This change is one of the many steps to make instrument profiler dynamic allocation free. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269453 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingFile.c')
-rw-r--r--lib/profile/InstrProfilingFile.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/profile/InstrProfilingFile.c b/lib/profile/InstrProfilingFile.c
index 14f7517b6..e2f68002e 100644
--- a/lib/profile/InstrProfilingFile.c
+++ b/lib/profile/InstrProfilingFile.c
@@ -32,18 +32,24 @@ static uint32_t fileWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs,
COMPILER_RT_VISIBILITY ProfBufferIO *
lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) {
- CallocHook = calloc;
- FreeHook = free;
- return lprofCreateBufferIO(fileWriter, File, BufferSz);
+ FreeHook = &free;
+ DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1);
+ VPBufferSize = BufferSz;
+ return lprofCreateBufferIO(fileWriter, File);
}
-static int writeFile(FILE *File) {
+static void setupIOBuffer() {
const char *BufferSzStr = 0;
- FreeHook = &free;
- CallocHook = &calloc;
BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE");
- if (BufferSzStr && BufferSzStr[0])
+ if (BufferSzStr && BufferSzStr[0]) {
VPBufferSize = atoi(BufferSzStr);
+ DynamicBufferIOBuffer = (uint8_t *)calloc(VPBufferSize, 1);
+ }
+}
+
+static int writeFile(FILE *File) {
+ FreeHook = &free;
+ setupIOBuffer();
return lprofWriteData(fileWriter, File, lprofGatherValueProfData);
}