diff --git a/src/dftracer/df_logger.cpp b/src/dftracer/df_logger.cpp index 1476d50..76f393d 100644 --- a/src/dftracer/df_logger.cpp +++ b/src/dftracer/df_logger.cpp @@ -3,8 +3,3 @@ template <> std::shared_ptr dftracer::Singleton::instance = nullptr; template <> bool dftracer::Singleton::stop_creating_instances = false; - -thread_local uint32_t DFTLogger::level = 0; -thread_local std::vector DFTLogger::index_stack = std::vector(); -thread_local std::unordered_map - DFTLogger::computed_hash = std::unordered_map(); \ No newline at end of file diff --git a/src/dftracer/df_logger.h b/src/dftracer/df_logger.h index c6c8c2e..4b6ae15 100644 --- a/src/dftracer/df_logger.h +++ b/src/dftracer/df_logger.h @@ -37,15 +37,16 @@ typedef std::chrono::high_resolution_clock chrono; class DFTLogger { private: + std::shared_mutex mtx; bool throw_error; bool is_init, dftracer_tid; ProcessID process_id; std::shared_ptr writer; std::atomic_int index; bool has_entry; - thread_local static uint32_t level; - thread_local static std::vector index_stack; - thread_local static std::unordered_map computed_hash; + uint32_t level; + std::vector index_stack; + std::unordered_map computed_hash; #ifdef DFTRACER_MPI_ENABLE bool mpi_event; #endif @@ -77,6 +78,9 @@ class DFTLogger { dftracer_tid(false), index(0), has_entry(false), + level(0), + index_stack(), + computed_hash(), #ifdef DFTRACER_MPI_ENABLE mpi_event(false), #endif @@ -181,6 +185,7 @@ class DFTLogger { } inline int enter_event() { + std::unique_lock lock(mtx); index++; level++; int current_index = index.load(); @@ -189,11 +194,13 @@ class DFTLogger { } inline void exit_event() { + std::unique_lock lock(mtx); level--; index_stack.pop_back(); } inline int get_parent() { + std::unique_lock lock(mtx); if (level > 1 && index_stack.size() > 1) { return index_stack[level - 2]; } @@ -201,12 +208,27 @@ class DFTLogger { } inline int get_current() { + std::unique_lock lock(mtx); if (level > 0 && index_stack.size() > 0) { return index_stack[level - 1]; } return -1; } + inline uint16_t has_hash(ConstEventNameType key) { + std::unique_lock lock(mtx); + auto iter = computed_hash.find(key); + if (iter == computed_hash.end()) + return 0; + else + iter->second; + } + + inline void insert_hash(ConstEventNameType key, uint16_t hash) { + std::unique_lock lock(mtx); + computed_hash.insert_or_assign(key, hash); + } + inline TimeResolution get_time() { DFTRACER_LOG_DEBUG("DFTLogger.get_time", ""); struct timeval tv {}; @@ -231,7 +253,7 @@ class DFTLogger { metadata->insert_or_assign("level", level); int parent_index_value = get_parent(); ConstEventNameType pidx = "p_idx"; - metadata->insert_or_assign(pidx, parent_index_value); + metadata->emplace(pidx, parent_index_value); } #ifdef DFTRACER_MPI_ENABLE if (!mpi_event) { @@ -285,11 +307,10 @@ class DFTLogger { inline uint16_t hash_and_store_str(char file[PATH_MAX], ConstEventNameType name) { - auto iter = computed_hash.find(file); - uint16_t hash = 0; - if (iter == computed_hash.end()) { + uint16_t hash = has_hash(file); + if (hash == 0) { md5String(file, &hash); - computed_hash.insert_or_assign(file, hash); + insert_hash(file, hash); if (this->writer != nullptr) { ThreadID tid = 0; if (dftracer_tid) { @@ -301,8 +322,6 @@ class DFTLogger { this->process_id, tid, false); this->exit_event(); } - } else { - hash = iter->second; } return hash; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c4031c6..ea72b7c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -127,6 +127,18 @@ set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_ENABLE=0) df_add_test(check_file_exists_${test_name} ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/check_file_not.sh ${CMAKE_CURRENT_BINARY_DIR}/${test_name}* 0) set_tests_properties(check_file_exists_${test_name} PROPERTIES DEPENDS ${test_name}) +set(test_name test_py_both) +df_add_test(${test_name} ${DFTRACER_PYTHON_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/py/test.py --format=npz --data_dir=${CMAKE_CURRENT_BINARY_DIR}/data) +set_common_properties(${test_name}) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=$ENV{PYTHONPATH}:${CMAKE_SOURCE_DIR}/venv/${DFTRACER_LIBDIR}) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/${DFTRACER_LIBDIR}:${CMAKE_SOURCE_DIR}/dependency/.spack-env/view/lib64:${DFTRACER_TEST_LD_LIBRARY_PATH}) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_LOG_FILE=${CMAKE_CURRENT_BINARY_DIR}/${test_name}_app) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT LD_PRELOAD=${CMAKE_BINARY_DIR}/${DFTRACER_LIBDIR}/libdftracer_preload.so) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_DATA_DIR=${CMAKE_BINARY_DIR}) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_LOG_FILE=${CMAKE_CURRENT_BINARY_DIR}/${test_name}) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_INIT=PRELOAD) +set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT DFTRACER_INC_METADATA=1) + set(TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/util.h) if (ENABLE_DLIO_BENCHMARK_TESTS)