Move printCallStack to core.

- Move captureCallStacks as well.
- Delete always true printMemoryOpCallStack from code.

Change-Id: I46a4b1727c31b8f147d5151371c3d1a76657873b
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-07-15 13:21:00 +02:00
committed by sys_ocldev
parent de381f01e8
commit a0d98f698c
10 changed files with 75 additions and 77 deletions

View File

@ -31,15 +31,13 @@ extern const char *frontEndDllName;
extern const char *igcDllName;
} // namespace Os
bool printMemoryOpCallStack = true;
void MemoryManagementFixture::SetUp() {
EXPECT_EQ(static_cast<size_t>(-1), MemoryManagement::failingAllocation);
MemoryManagement::indexAllocation = 0;
MemoryManagement::indexDeallocation = 0;
MemoryManagement::failingAllocation = -1;
previousAllocations = MemoryManagement::numAllocations.load();
MemoryManagement::logTraces = NEO::captureCallStacks;
MemoryManagement::logTraces = MemoryManagement::captureCallStacks;
}
void MemoryManagementFixture::TearDown() {
@ -57,65 +55,6 @@ void MemoryManagementFixture::clearFailingAllocation() {
MemoryManagement::failingAllocation = -1;
}
std::string printCallStack(const MemoryManagement::AllocationEvent &event) {
std::string result = "";
printf("printCallStack.%d.%d\n", printMemoryOpCallStack, event.frames);
if (!NEO::captureCallStacks) {
printf("for detailed stack information turn on captureCallStacks in memory_management_fixture.h\n");
}
if (printMemoryOpCallStack && event.frames > 0) {
#if defined(__linux__)
char **bt = backtrace_symbols(event.callstack, event.frames);
char *demangled;
int status;
char output[1024];
Dl_info info;
result += "\n";
for (int i = 0; i < event.frames; ++i) {
dladdr(event.callstack[i], &info);
if (info.dli_sname) {
demangled = nullptr;
status = -1;
if (info.dli_sname[0] == '_') {
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
}
snprintf(output, sizeof(output), "%-3d %*p %s + %zd\n",
(event.frames - i - 1), (int)(sizeof(void *) + 2), event.callstack[i],
status == 0 ? demangled : info.dli_sname == 0 ? bt[i] : info.dli_sname,
(char *)event.callstack[i] - (char *)info.dli_saddr);
free(demangled);
} else {
snprintf(output, sizeof(output), "%-3d %*p %s\n",
(event.frames - i - 1), (int)(sizeof(void *) + 2), event.callstack[i], bt[i]);
}
result += std::string(output);
}
result += "\n";
free(bt);
#elif defined(_WIN32)
SYMBOL_INFO *symbol;
HANDLE process;
process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
symbol = (SYMBOL_INFO *)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
for (int i = 0; i < event.frames; i++) {
SymFromAddr(process, (DWORD64)(event.callstack[i]), 0, symbol);
printf("%i: %s - 0x%0" PRIx64 "\n", event.frames - i - 1, symbol->Name, symbol->Address);
}
free(symbol);
#endif
}
return result;
}
::testing::AssertionResult MemoryManagementFixture::assertLeak(
const char *leakExpr,
size_t leakIndex) {

View File

@ -40,5 +40,3 @@ struct MemoryManagementFixture {
// Gets compared to # at TearDown time
size_t previousAllocations;
};
std::string printCallStack(const MemoryManagement::AllocationEvent &event);

View File

@ -24,8 +24,6 @@ set(IGDRCL_SRCS_LIB_ULT
${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/libult/ult_command_stream_receiver.h
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/debug_helpers.cpp
${IGDRCL_SOURCE_DIR}/core/unit_tests/helpers/memory_management.cpp
${IGDRCL_SOURCE_DIR}/core/unit_tests/helpers/memory_management.h
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/helpers/test_files.h
${IGDRCL_SOURCE_DIR}/unit_tests/libult/create_tbx_sockets.cpp
@ -35,6 +33,8 @@ set(IGDRCL_SRCS_LIB_ULT
${IGDRCL_SOURCE_DIR}/unit_tests/libult/source_level_debugger_library.h
${IGDRCL_SOURCE_DIR}/unit_tests/program/evaluate_unhandled_token_ult.cpp
${IGDRCL_SOURCE_DIR}/unit_tests/utilities/debug_settings_reader_creator.cpp
${NEO_CORE_DIRECTORY}/unit_tests/helpers/memory_management.h
${NEO_CORE_DIRECTORY}/unit_tests/helpers/memory_management.cpp
)
set(IGDRCL_SRCS_LIB_ULT_WINDOWS

View File

@ -61,7 +61,6 @@ PRODUCT_FAMILY productFamily = IGFX_SKYLAKE;
GFXCORE_FAMILY renderCoreFamily = IGFX_GEN9_CORE;
PRODUCT_FAMILY defaultProductFamily = productFamily;
extern bool printMemoryOpCallStack;
extern std::string lastTest;
bool generateRandomInput = false;
@ -214,8 +213,6 @@ int main(int argc, char **argv) {
useDefaultListener = true;
} else if (!strcmp("--disable_alarm", argv[i])) {
enable_alarm = false;
} else if (!strcmp("--print_memory_op_cs", argv[i])) {
printMemoryOpCallStack = true;
} else if (!strcmp("--tbx", argv[i])) {
if (testMode == TestMode::AubTests) {
testMode = TestMode::AubTestsWithTbx;

View File

@ -15,8 +15,8 @@ using ::testing::TestInfo;
using namespace NEO;
void MemoryLeakListener::OnTestStart(const TestInfo &testInfo) {
MemoryManagement::logTraces = NEO::captureCallStacks;
if (NEO::captureCallStacks) {
MemoryManagement::logTraces = MemoryManagement::captureCallStacks;
if (MemoryManagement::captureCallStacks) {
MemoryManagement::detailedAllocationLoggingActive = true;
}
MemoryManagement::fastLeakDetectionEnabled = true;
@ -31,7 +31,7 @@ void MemoryLeakListener::OnTestEnd(const TestInfo &testInfo) {
EXPECT_GT(MemoryManagement::fastEventsAllocatedCount, MemoryManagement::fastEventsDeallocatedCount);
}
MemoryManagement::fastLeaksDetectionMode = MemoryManagement::LeakDetectionMode::STANDARD;
} else if (NEO::captureCallStacks && (MemoryManagement::fastEventsAllocatedCount != MemoryManagement::fastEventsDeallocatedCount)) {
} else if (MemoryManagement::captureCallStacks && (MemoryManagement::fastEventsAllocatedCount != MemoryManagement::fastEventsDeallocatedCount)) {
auto leak = MemoryManagement::enumerateLeak(MemoryManagement::indexAllocation.load(), MemoryManagement::indexDeallocation.load(), true, true);
if (leak != MemoryManagement::failingAllocation) {
printf("\n %s ", printCallStack(MemoryManagement::eventsAllocated[leak]).c_str());

View File

@ -10,9 +10,6 @@
namespace NEO {
// capture allocations call stacks to print them during memory leak in ULTs
constexpr bool captureCallStacks = false;
class MemoryLeakListener : public ::testing::EmptyTestEventListener {
private:
void OnTestStart(const ::testing::TestInfo &) override;

View File

@ -20,8 +20,6 @@ const char *fSeparator = "/";
Environment *gEnvironment;
extern bool printMemoryOpCallStack;
std::string getRunPath() {
std::string res;
#if defined(__linux__)

View File

@ -31,6 +31,7 @@ if(WIN32)
${IGDRCL_SOURCE_DIR}/unit_tests/os_interface/windows/ult_dxgi_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mode.h
)
target_link_libraries(igdrcl_tbx_tests dbghelp)
else()
target_sources(igdrcl_tbx_tests PRIVATE
${IGDRCL_SOURCE_DIR}/runtime/dll/linux/allocator_helper.cpp