Index: lib/esan/CMakeLists.txt =================================================================== --- lib/esan/CMakeLists.txt +++ lib/esan/CMakeLists.txt @@ -10,7 +10,8 @@ set(ESAN_SOURCES esan.cpp esan_interface.cpp - esan_interceptors.cpp) + esan_interceptors.cpp + cache_frag.cpp) foreach (arch ${ESAN_SUPPORTED_ARCH}) add_compiler_rt_runtime(clang_rt.esan Index: lib/esan/cache_frag.h =================================================================== --- /dev/null +++ lib/esan/cache_frag.h @@ -0,0 +1,28 @@ +//===-- cache_frag.h --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of EfficiencySanitizer, a family of performance tuners. +// +// Header for cache-fragmentation-specific code. +//===----------------------------------------------------------------------===// + +#ifndef CACHE_FRAG_H +#define CACHE_FRAG_H + +namespace __esan { + +void processCacheFragCompilationUnitInit(void *Ptr); +void processCacheFragCompilationUnitExit(void *Ptr); + +int initializeCacheFrag(); +int finalizeCacheFrag(); + +} // namespace __esan + +#endif // CACHE_FRAG_H Index: lib/esan/cache_frag.cpp =================================================================== --- /dev/null +++ lib/esan/cache_frag.cpp @@ -0,0 +1,40 @@ +//===-- cache_frag.cpp ----------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of EfficiencySanitizer, a family of performance tuners. +// +// This file contains cache fragmentation-specific code. +//===----------------------------------------------------------------------===// + +#include "esan.h" + +namespace __esan { + +//===-- Init/exit functions -----------------------------------------------===// + +void processCacheFragCompilationUnitInit(void *Ptr) { + VPrintf(2, "in esan::%s\n", __FUNCTION__); +} + +void processCacheFragCompilationUnitExit(void *Ptr) { + VPrintf(2, "in esan::%s\n", __FUNCTION__); +} + +void initializeCacheFrag() { + VPrintf(2, "in esan::%s\n", __FUNCTION__); +} + +int finalizeCacheFrag() { + VPrintf(2, "in esan::%s\n", __FUNCTION__); + // FIXME: add the cache fragmentation final report. + Report("%s is not finished: nothing yet to report\n", SanitizerToolName); + return 0; +} + +} // namespace __esan Index: lib/esan/esan.cpp =================================================================== --- lib/esan/esan.cpp +++ lib/esan/esan.cpp @@ -15,6 +15,7 @@ #include "esan.h" #include "esan_interface_internal.h" #include "esan_shadow.h" +#include "cache_frag.h" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_flag_parser.h" #include "sanitizer_common/sanitizer_flags.h" @@ -155,7 +156,9 @@ ::__cxa_atexit((void (*)())finalizeLibrary); VPrintf(1, "in esan::%s\n", __FUNCTION__); - if (WhichTool != ESAN_CacheFrag) { + if (WhichTool == ESAN_CacheFrag) { + initializeCacheFrag(); + } else { Printf("ERROR: unknown tool %d requested\n", WhichTool); Die(); } @@ -169,22 +172,25 @@ int finalizeLibrary() { VPrintf(1, "in esan::%s\n", __FUNCTION__); if (WhichTool == ESAN_CacheFrag) { - // FIXME NYI: we need to add sampling + callstack gathering and have a - // strategy for how to generate a final report. - // We'll move this to cache_frag.cpp once we have something. - Report("%s is not finished: nothing yet to report\n", SanitizerToolName); + finalizeCacheFrag(); } return 0; } void processCompilationUnitInit(void *Ptr) { VPrintf(2, "in esan::%s\n", __FUNCTION__); + if (WhichTool == ESAN_CacheFrag) { + processCacheFragCompilationUnitInit(Ptr); + } } // This is called when the containing module is unloaded. // For the main executable module, this is called after finalizeLibrary. void processCompilationUnitExit(void *Ptr) { VPrintf(2, "in esan::%s\n", __FUNCTION__); + if (WhichTool == ESAN_CacheFrag) { + processCacheFragCompilationUnitExit(Ptr); + } } } // namespace __esan Index: test/esan/TestCases/struct-simple.cpp =================================================================== --- test/esan/TestCases/struct-simple.cpp +++ test/esan/TestCases/struct-simple.cpp @@ -26,13 +26,19 @@ #ifdef MAIN int main(int argc, char **argv) { // CHECK: in esan::initializeLibrary + // CHECK-NEXT: in esan::initializeCacheFrag // CHECK: in esan::processCompilationUnitInit - // CHECK: in esan::processCompilationUnitInit + // CHECK-NEXT: in esan::processCacheFragCompilationUnitInit + // CHECK-NEXT: in esan::processCompilationUnitInit + // CHECK-NEXT: in esan::processCacheFragCompilationUnitInit part(); return 0; - // CHECK-NEXT: in esan::finalizeLibrary + // CHECK: in esan::finalizeLibrary + // CHECK-NEXT: in esan::finalizeCacheFrag // CHECK-NEXT: {{.*}}EfficiencySanitizer is not finished: nothing yet to report - // CHECK: in esan::processCompilationUnitExit - // CHECK: in esan::processCompilationUnitExit + // CHECK-NEXT: in esan::processCompilationUnitExit + // CHECK-NEXT: in esan::processCacheFragCompilationUnitExit + // CHECK-NEXT: in esan::processCompilationUnitExit + // CHECK-NEXT: in esan::processCacheFragCompilationUnitExit } #endif // MAIN