summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingWriter.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/InstrProfilingWriter.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/InstrProfilingWriter.c')
-rw-r--r--lib/profile/InstrProfilingWriter.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/profile/InstrProfilingWriter.c b/lib/profile/InstrProfilingWriter.c
index aebe30468..db944e20f 100644
--- a/lib/profile/InstrProfilingWriter.c
+++ b/lib/profile/InstrProfilingWriter.c
@@ -13,9 +13,13 @@
#define INSTR_PROF_VALUE_PROF_DATA
#include "InstrProfData.inc"
+
COMPILER_RT_VISIBILITY void (*FreeHook)(void *) = NULL;
-COMPILER_RT_VISIBILITY void *(*CallocHook)(size_t, size_t) = NULL;
-uint32_t VPBufferSize = 0;
+static ProfBufferIO TheBufferIO;
+#define VP_BUFFER_SIZE 8 * 1024
+static uint8_t BufferIOBuffer[VP_BUFFER_SIZE];
+COMPILER_RT_VISIBILITY uint8_t *DynamicBufferIOBuffer = 0;
+COMPILER_RT_VISIBILITY uint32_t VPBufferSize = 0;
/* The buffer writer is reponsponsible in keeping writer state
* across the call.
@@ -43,20 +47,20 @@ static void llvmInitBufferIO(ProfBufferIO *BufferIO, WriterCallback FileWriter,
}
COMPILER_RT_VISIBILITY ProfBufferIO *
-lprofCreateBufferIO(WriterCallback FileWriter, void *File, uint32_t BufferSz) {
- ProfBufferIO *BufferIO = (ProfBufferIO *)CallocHook(1, sizeof(ProfBufferIO));
- uint8_t *Buffer = (uint8_t *)CallocHook(1, BufferSz);
+lprofCreateBufferIO(WriterCallback FileWriter, void *File) {
+ uint8_t *Buffer = DynamicBufferIOBuffer;
+ uint32_t BufferSize = VPBufferSize;
if (!Buffer) {
- FreeHook(BufferIO);
- return 0;
+ Buffer = &BufferIOBuffer[0];
+ BufferSize = sizeof(BufferIOBuffer);
}
- llvmInitBufferIO(BufferIO, FileWriter, File, Buffer, BufferSz);
- return BufferIO;
+ llvmInitBufferIO(&TheBufferIO, FileWriter, File, Buffer, BufferSize);
+ return &TheBufferIO;
}
COMPILER_RT_VISIBILITY void lprofDeleteBufferIO(ProfBufferIO *BufferIO) {
- FreeHook(BufferIO->BufferStart);
- FreeHook(BufferIO);
+ if (DynamicBufferIOBuffer)
+ FreeHook(DynamicBufferIOBuffer);
}
COMPILER_RT_VISIBILITY int
@@ -91,8 +95,6 @@ COMPILER_RT_VISIBILITY int lprofBufferIOFlush(ProfBufferIO *BufferIO) {
return 0;
}
-#define VP_BUFFER_SIZE 8 * 1024
-
static int writeOneValueProfData(ProfBufferIO *BufferIO,
VPGatherHookType VPDataGatherer,
const __llvm_profile_data *Data) {
@@ -111,14 +113,12 @@ static int writeValueProfData(WriterCallback Writer, void *WriterCtx,
const __llvm_profile_data *DataBegin,
const __llvm_profile_data *DataEnd) {
ProfBufferIO *BufferIO;
- uint32_t BufferSz;
const __llvm_profile_data *DI = 0;
if (!VPDataGatherer)
return 0;
- BufferSz = VPBufferSize ? VPBufferSize : VP_BUFFER_SIZE;
- BufferIO = lprofCreateBufferIO(Writer, WriterCtx, BufferSz);
+ BufferIO = lprofCreateBufferIO(Writer, WriterCtx);
for (DI = DataBegin; DI < DataEnd; DI++) {
if (writeOneValueProfData(BufferIO, VPDataGatherer, DI))