mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 02:38:07 +08:00
Adds a flag COMPILER_RT_PROFILE_BAREMETAL, which disables the parts of the profile runtime which require a filesystem or malloc. This minimal library only requires string.h from the C library. This is useful for profiling or code coverage of baremetal images, which don't have filesystem APIs, and might not have malloc configured (or have limited heap space). Expected usage: - Add code to your project to call `__llvm_profile_get_size_for_buffer()` and `__llvm_profile_write_buffer()` to write the profile data to a buffer in memory, and then copy that data off the device using target-specific tools. - If you're using a linker script, set up your linker script to map the profiling and coverage input sections to corresponding output sections with the same name, and mark them KEEP. `__llvm_covfun` and `__llvm_covmap` are non-allocatable, `__llvm_prf_names` is read-only allocatable, and `__llvm_prf_cnts` and `__llvm_prf_data` are read-write allocatable. - The resulting data is in same format as the non-baremetal profiles. There's some room for improvement here in the future for doing profiling and code coverage for baremetal. If we revised the profiling format, and introduced some additional host tooling, we could move some of the metadata into non-allocated sections, and construct the profraw file on the host. But this patch is sufficient for some use-cases.
45 lines
1.6 KiB
C
45 lines
1.6 KiB
C
/*===- InstrProfilingMergeFile.c - Profile in-process Merging ------------===*\
|
|
|*
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|* See https://llvm.org/LICENSE.txt for license information.
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|*
|
|
|*===----------------------------------------------------------------------===
|
|
|* This file defines APIs needed to support in-process merging for profile data
|
|
|* stored in files.
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
#if !defined(__Fuchsia__)
|
|
|
|
#include "InstrProfiling.h"
|
|
#include "InstrProfilingInternal.h"
|
|
|
|
#define INSTR_PROF_VALUE_PROF_DATA
|
|
#include "profile/InstrProfData.inc"
|
|
|
|
/* Merge value profile data pointed to by SrcValueProfData into
|
|
* in-memory profile counters pointed by to DstData. */
|
|
COMPILER_RT_VISIBILITY
|
|
void lprofMergeValueProfData(ValueProfData *SrcValueProfData,
|
|
__llvm_profile_data *DstData) {
|
|
unsigned I, S, V, DstIndex = 0;
|
|
InstrProfValueData *VData;
|
|
ValueProfRecord *VR = getFirstValueProfRecord(SrcValueProfData);
|
|
for (I = 0; I < SrcValueProfData->NumValueKinds; I++) {
|
|
VData = getValueProfRecordValueData(VR);
|
|
unsigned SrcIndex = 0;
|
|
for (S = 0; S < VR->NumValueSites; S++) {
|
|
uint8_t NV = VR->SiteCountArray[S];
|
|
for (V = 0; V < NV; V++) {
|
|
__llvm_profile_instrument_target_value(VData[SrcIndex].Value, DstData,
|
|
DstIndex, VData[SrcIndex].Count);
|
|
++SrcIndex;
|
|
}
|
|
++DstIndex;
|
|
}
|
|
VR = getValueProfRecordNext(VR);
|
|
}
|
|
}
|
|
|
|
#endif
|