From 7b83cc5d915baaccf4cc9ab5350b1edbc7e023e0 Mon Sep 17 00:00:00 2001 From: David Boehme Date: Fri, 15 Mar 2024 09:46:58 -0700 Subject: [PATCH] Miscellaneous code cleanup (#544) * Save region count entry in event service * Deprecate CALI_ATTR_NOMERGE property * Remove CALI_ATTR_NOMERGE from callpath attributes * Remove PGI constexpr hack * Remove SoSFlow * Enable region.count in spot by default * CMake cleanup * Remove datatracker alloc functions --- CMakeLists.txt | 44 ++---- caliper-config.h.in | 6 - cmake/FindSOSFlow.cmake | 42 ----- include/caliper/cali_datatracker.h | 81 ++-------- include/caliper/common/Entry.h | 2 +- include/caliper/common/Variant.h | 2 +- include/caliper/common/cali_types.h | 4 +- src/caliper/Caliper.cpp | 29 ++-- src/caliper/cali_datatracker.cpp | 47 +----- src/caliper/controllers/SpotController.cpp | 6 +- src/caliper/test/test_attribute.cpp | 17 -- src/services/CMakeLists.txt | 3 - src/services/callpath/Callpath.cpp | 6 +- src/services/event/EventTrigger.cpp | 5 +- src/services/sos/CMakeLists.txt | 9 -- src/services/sos/README.md | 15 -- src/services/sos/Sos.cpp | 175 --------------------- test/ci_app_tests/ci_test_alloc.c | 8 +- test/ci_app_tests/ci_test_c_ann.c | 2 +- 19 files changed, 67 insertions(+), 436 deletions(-) delete mode 100644 cmake/FindSOSFlow.cmake delete mode 100644 src/services/sos/CMakeLists.txt delete mode 100644 src/services/sos/README.md delete mode 100644 src/services/sos/Sos.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b93c294fd..35a75aa69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,24 +35,22 @@ option(CALIPER_OPTION_PREFIX "Option names are prefixed with 'CALIPER_'" OFF) mark_as_advanced(CALIPER_OPTION_PREFIX) macro(ADD_CALIPER_OPTION NAME) - if(CALIPER_OPTION_PREFIX) - option(CALIPER_${NAME} ${ARGN}) - # set the option locally for this project - set(${NAME} ${CALIPER_${NAME}}) - else() - option(${NAME} ${ARGN}) - endif() + if(CALIPER_OPTION_PREFIX) + option(CALIPER_${NAME} ${ARGN}) + # set the option locally for this project + set(${NAME} ${CALIPER_${NAME}}) + else() + option(${NAME} ${ARGN}) + endif() endmacro() -# Optional Fortran -add_caliper_option(WITH_FORTRAN "Install Fortran interface") - # Shared libs option option(BUILD_SHARED_LIBS "Build shared libraries" TRUE) - # RPATH setup. By default, rpath everything. option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add rpath for all dependencies" TRUE) +# Optional Fortran +add_caliper_option(WITH_FORTRAN "Install Fortran interface" FALSE) add_caliper_option(WITH_TOOLS "Build Caliper tools" TRUE) add_caliper_option(WITH_NVTX "Enable NVidia nvtx bindings for NVprof and NSight (requires CUDA)" FALSE) @@ -69,7 +67,6 @@ add_caliper_option(WITH_GOTCHA "Enable GOTCHA wrapping" ${CALIPER_HAVE_LINUX} add_caliper_option(WITH_ROCTX "Enable AMD RocTX support" FALSE) add_caliper_option(WITH_ROCTRACER "Enable AMD RocTracer support" FALSE) add_caliper_option(WITH_ROCM "Enable AMD RocTracer and RocTX support" FALSE) -#add_caliper_option(WITH_SOS "Enable SOSFlow data management" FALSE) add_caliper_option(WITH_TAU "Enable TAU service (TAU Performance System)" FALSE) add_caliper_option(WITH_VTUNE "Enable Intel(R) VTune(tm) annotation bindings" FALSE) add_caliper_option(WITH_ADIAK "Enable adiak support" FALSE) @@ -313,16 +310,6 @@ if (WITH_ADIAK) endif() endif() -if (WITH_SOS) - include(FindSOSFlow) - if (SOSFlow_FOUND) - message(STATUS "Found sosflow in " ${SOSFlow_LIBRARY}) - list(APPEND CALIPER_EXTERNAL_LIBS ${SOSFlow_LIBRARY}) - set(CALIPER_HAVE_SOS TRUE) - set(CALIPER_SOSFlow_CMAKE_MSG "Yes, using ${SOSFlow_LIBRARY}") - endif() -endif() - if (WITH_KOKKOS) set(CALIPER_HAVE_KOKKOS TRUE) set(CALIPER_Kokkos_CMAKE_MSG "Yes") @@ -333,8 +320,8 @@ set(THREADS_PREFER_PTHREAD_FLAG On) find_package(Threads REQUIRED) if (WITH_OMPT) - set(CALIPER_HAVE_OMPT TRUE) - set(CALIPER_OMPT_CMAKE_MSG "Yes") + set(CALIPER_HAVE_OMPT TRUE) + set(CALIPER_OMPT_CMAKE_MSG "Yes") endif() # Find MPI @@ -473,13 +460,6 @@ if (WITH_LDMS) endif() endif() -# PGI 17.x has issues with some constexpr constructors -if(CMAKE_CXX_COMPILER_ID MATCHES PGI) - set(CALIPER_REDUCED_CONSTEXPR_USAGE TRUE) -else() - set(CALIPER_REDUCED_CONSTEXPR_USAGE FALSE) -endif() - if (BUILD_TESTING) set(CALIPER_BUILD_TESTING TRUE) endif() @@ -579,10 +559,8 @@ set(CALIPER_MODULES Libpfm Libunwind Sampler - SOSFlow MPI MPIWRAP - MPIT OMPT Nvtx CUpti diff --git a/caliper-config.h.in b/caliper-config.h.in index c5cef552d..b8a079765 100644 --- a/caliper-config.h.in +++ b/caliper-config.h.in @@ -34,12 +34,6 @@ #cmakedefine CALIPER_BUILD_TESTING -#ifdef CALIPER_REDUCED_CONSTEXPR_USAGE -#define CONSTEXPR_UNLESS_PGI -#else -#define CONSTEXPR_UNLESS_PGI constexpr -#endif - // Version information -- numerical and a version string #define CALIPER_MAJOR_VERSION @CALIPER_MAJOR_VERSION@ #define CALIPER_MINOR_VERSION @CALIPER_MINOR_VERSION@ diff --git a/cmake/FindSOSFlow.cmake b/cmake/FindSOSFlow.cmake deleted file mode 100644 index 98459401f..000000000 --- a/cmake/FindSOSFlow.cmake +++ /dev/null @@ -1,42 +0,0 @@ -# Try to find SOSFlow headers and libraries. -# -# Usage of this module as follows: -# -# find_package(ElfUtils) -# -# Variables used by this module, they can change the default behaviour and need -# to be set before calling find_package: -# -# SOS_PREFIX Set this variable to the root installation of -# libpapi if the module has problems finding the -# proper installation path. -# -# Variables defined by this module: -# -# SOSFlow_FOUND System has SOSFlow libraries and headers -# SOSFlow_LIBRARIES The SOSFlow library -# SOSFlow_INCLUDE_DIRS The location of SOSFlow headers - -if (SOSFlow_INCLUDE_DIR AND SOSFlow_LIBRARY) - set(SOSFlow_FIND_QUIETLY true) -endif() - -find_path(SOSFlow_INCLUDE_DIR sos.h - HINTS ${SOS_PREFIX}/include -) - -find_library(SOSFlow_LIBRARY - NAMES sos - HINTS ${SOS_PREFIX}/lib -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SOSFlow DEFAULT_MSG - SOSFlow_LIBRARY - SOSFlow_INCLUDE_DIR -) - -mark_as_advanced( - SOSFlow_INCLUDE_DIR - SOSFlow_LIBRARY -) diff --git a/include/caliper/cali_datatracker.h b/include/caliper/cali_datatracker.h index 4dce75d3e..2515b5982 100644 --- a/include/caliper/cali_datatracker.h +++ b/include/caliper/cali_datatracker.h @@ -2,8 +2,8 @@ * See top-level LICENSE file for details. */ -/** - * \file cali_datatracker.h +/** + * \file cali_datatracker.h * \brief C API for Caliper datatracking. */ @@ -20,65 +20,19 @@ extern "C" { * --- Data tracking functions ------------------------------------------------ */ -/** - * \addtogroup AnnotationAPI - * \{ - */ - -/** - * Allocate and track the resulting allocation in Caliper. - * - * \note Tracking information will be automatically removed if the allocation is freed - * - * \param label The unique label with which to track the allocation requested - * \param size The total size of the allocation requested - * \return A new allocation of size `size` - */ - -void* -cali_datatracker_allocate(const char *label, - size_t size); - -/** - * Allocate and track the resulting allocation, with dimensions, in Caliper. - * - * \note Tracking information will be automatically removed if the allocation is freed - * - * \param label The unique label with which to track the allocation requested - * \param elem_size The size of an individual element in the allocation requested - * \param dimensions An array of the dimensions of the allocation requested - * \param num_dimensions The number of dimensions in `dimensions` - * \return A new allocation of size `product(dimensions)*elem_size` - */ - -void* -cali_datatracker_allocate_dimensional(const char *label, - size_t elem_size, - const size_t *dimensions, - size_t num_dimensions); - -/** - * Free and untrack an allocation in Caliper. - * - * \param ptr The pointer to the beginning of the allocation to free/untrack - */ - -void -cali_datatracker_free(void *ptr); - /** * Track an existing allocation in Caliper. * - * \note This will track the entire allocation pointed to by ptr. + * \note This will track the entire allocation pointed to by ptr. * To track a subset of a larger allocation, use `cali_datatracker_track_dimensional`. * * \param ptr The pointer to the beginning of the allocation to track - * \param label The unique label with which to track the allocation + * \param label The unique label with which to track the allocation * \param size Size of the allocation */ -void -cali_datatracker_track(const void *ptr, +void +cali_datatracker_track(const void *ptr, const char *label, size_t size); @@ -86,14 +40,14 @@ cali_datatracker_track(const void *ptr, * Track an existing allocation in Caliper. * * \param ptr The pointer to the beginning of the allocation to track - * \param label The unique label with which to track the allocation - * \param elem_size The size of an individual element in the allocation - * \param dimensions An array of the dimensions of the allocation + * \param label The unique label with which to track the allocation + * \param elem_size The size of an individual element in the allocation + * \param dimensions An array of the dimensions of the allocation * \param num_dimensions The number of dimensions in `dimensions` */ -void -cali_datatracker_track_dimensional(const void *ptr, +void +cali_datatracker_track_dimensional(const void *ptr, const char *label, size_t elem_size, const size_t *dimensions, @@ -105,7 +59,7 @@ cali_datatracker_track_dimensional(const void *ptr, * \param ptr The pointer to the beginning of the allocation to untrack */ -void +void cali_datatracker_untrack(const void *ptr); /** @@ -116,15 +70,6 @@ cali_datatracker_untrack(const void *ptr); } // extern "C" #endif -/* Include high-level annotation macros. - */ - -#define CALI_DATATRACKER_ALLOCATE(label, elem_size, dimensions, num_dimensions) \ - cali_datatracker_allocate(label, elem_size, dimensions, num_dimensions) - -#define CALI_DATATRACKER_FREE(ptr) \ - cali_datatracker_free(ptr) - /** * \addtogroup AnnotationAPI * \{ @@ -144,7 +89,7 @@ cali_datatracker_untrack(const void *ptr); /** * \brief Label and track a multi-dimensional array. * - * Labels a multi-dimensional array with with the variable name of + * Labels a multi-dimensional array with with the variable name of * \a ptr. The array can then be tracked and resolved with the alloc service. * * \param elem_size Size of the array elements in bytes diff --git a/include/caliper/common/Entry.h b/include/caliper/common/Entry.h index f51712d46..e33e1e3ce 100644 --- a/include/caliper/common/Entry.h +++ b/include/caliper/common/Entry.h @@ -37,7 +37,7 @@ class Entry constexpr static size_t MAX_PACKED_SIZE = 30; - CONSTEXPR_UNLESS_PGI Entry() + constexpr Entry() : m_node(nullptr) { } diff --git a/include/caliper/common/Variant.h b/include/caliper/common/Variant.h index 2812eba1f..371289d28 100644 --- a/include/caliper/common/Variant.h +++ b/include/caliper/common/Variant.h @@ -34,7 +34,7 @@ class Variant public: - CONSTEXPR_UNLESS_PGI Variant() + constexpr Variant() : m_v { CALI_TYPE_INV, { static_cast(0) } } { } Variant(const cali_variant_t& v) diff --git a/include/caliper/common/cali_types.h b/include/caliper/common/cali_types.h index 0aef52f56..f295c86b5 100644 --- a/include/caliper/common/cali_types.h +++ b/include/caliper/common/cali_types.h @@ -69,10 +69,10 @@ typedef enum { */ CALI_ATTR_ASVALUE = 1, - /** \brief Create a separate context tree root node for this attribute. + /** \brief Create a separate context tree root node for this attribute (deprecated). * * Useful for attributes that form overlapping hierarchies separate from - * the main region stack. + * the main region stack. No longer used. */ CALI_ATTR_NOMERGE = 2, /** \brief Process-scope attribute. Shared between all threads. */ diff --git a/src/caliper/Caliper.cpp b/src/caliper/Caliper.cpp index 582aca84f..ea460ede5 100644 --- a/src/caliper/Caliper.cpp +++ b/src/caliper/Caliper.cpp @@ -546,7 +546,7 @@ constexpr cali_id_t UNALIGNED_KEY { 2 }; inline cali_id_t get_blackboard_key(cali_id_t attr_id, int prop) { - if ((prop & CALI_ATTR_ASVALUE) || (prop & CALI_ATTR_NOMERGE)) + if (prop & CALI_ATTR_ASVALUE) return attr_id; if (prop & CALI_ATTR_UNALIGNED) return UNALIGNED_KEY; @@ -554,18 +554,22 @@ get_blackboard_key(cali_id_t attr_id, int prop) return REGION_KEY; } +inline cali_id_t +get_blackboard_key_for_reference_entry(int prop) +{ + return prop & CALI_ATTR_UNALIGNED ? UNALIGNED_KEY : REGION_KEY; +} + inline void handle_begin(const Attribute& attr, const Variant& value, int prop, Blackboard& blackboard, MetadataTree& tree) { - cali_id_t key = get_blackboard_key(attr.id(), prop); - Entry entry; - - if (prop & CALI_ATTR_ASVALUE) - entry = Entry(attr, value); - else - entry = Entry(tree.get_child(attr, value, blackboard.get(key).node())); - - blackboard.set(key, entry, !(prop & CALI_ATTR_HIDDEN)); + if (prop & CALI_ATTR_ASVALUE) { + blackboard.set(attr.id(), Entry(attr, value), !(prop & CALI_ATTR_HIDDEN)); + } else { + cali_id_t key = get_blackboard_key_for_reference_entry(prop); + Entry entry = Entry(tree.get_child(attr, value, blackboard.get(key).node())); + blackboard.set(key, entry, !(prop & CALI_ATTR_HIDDEN)); + } } inline void @@ -586,11 +590,10 @@ handle_end(const Attribute& attr, int prop, Entry merged_entry, cali_id_t key, B inline void handle_set(const Attribute& attr, const Variant& value, int prop, Blackboard& blackboard, MetadataTree& tree) { - cali_id_t key = get_blackboard_key(attr.id(), prop); - if (prop & CALI_ATTR_ASVALUE) - blackboard.set(key, Entry(attr, value), !(prop & CALI_ATTR_HIDDEN)); + blackboard.set(attr.id(), Entry(attr, value), !(prop & CALI_ATTR_HIDDEN)); else { + cali_id_t key = get_blackboard_key_for_reference_entry(prop); Node* node = blackboard.get(key).node(); blackboard.set(key, tree.replace_first_in_path(node, attr, value), !(prop & CALI_ATTR_HIDDEN)); } diff --git a/src/caliper/cali_datatracker.cpp b/src/caliper/cali_datatracker.cpp index ccb22d8d3..c53c91523 100644 --- a/src/caliper/cali_datatracker.cpp +++ b/src/caliper/cali_datatracker.cpp @@ -11,59 +11,26 @@ using namespace cali; - -void* -cali_datatracker_allocate(const char *label, - const size_t size) -{ - void* ptr = malloc(size); - cali_datatracker_track(ptr, label, size); - - return ptr; -} - void -cali_datatracker_free(void *ptr) -{ - cali_datatracker_untrack(ptr); - free(ptr); -} - -void -cali_datatracker_track(const void *ptr, +cali_datatracker_track(const void *ptr, const char *label, - size_t size) + size_t size) { Caliper::instance().memory_region_begin(ptr, label, 1, 1, &size); } -void -cali_datatracker_track_dimensional(const void *ptr, +void +cali_datatracker_track_dimensional(const void *ptr, const char *label, size_t elem_size, const size_t *dimensions, - size_t ndims) + size_t ndims) { Caliper::instance().memory_region_begin(ptr, label, elem_size, ndims, dimensions); } -void* -cali_datatracker_allocate_dimensional(const char *label, - size_t elem_size, - const size_t *dimensions, - size_t ndims) -{ - void* ptr = - malloc( std::accumulate(dimensions, dimensions+ndims, elem_size, - std::multiplies()) ); - - cali_datatracker_track_dimensional(ptr, label, elem_size, dimensions, ndims); - - return ptr; -} - -void -cali_datatracker_untrack(const void *ptr) +void +cali_datatracker_untrack(const void *ptr) { Caliper::instance().memory_region_end(ptr); } diff --git a/src/caliper/controllers/SpotController.cpp b/src/caliper/controllers/SpotController.cpp index 4e796e798..f97a9c169 100644 --- a/src/caliper/controllers/SpotController.cpp +++ b/src/caliper/controllers/SpotController.cpp @@ -554,7 +554,11 @@ const char* spot_controller_spec = R"json( "CALI_TIMER_INCLUSIVE_DURATION" : "false", "CALI_TIMER_UNIT" : "sec" }, - "defaults" : { "node.order": "true" }, + "defaults" : + { + "node.order" : "true", + "region.count" : "true" + }, "options": [ { diff --git a/src/caliper/test/test_attribute.cpp b/src/caliper/test/test_attribute.cpp index 0dc652d16..768c48169 100644 --- a/src/caliper/test/test_attribute.cpp +++ b/src/caliper/test/test_attribute.cpp @@ -111,16 +111,11 @@ TEST(AttributeAPITest, NestedAttribute) { c.create_attribute("test.attr.nested.a", CALI_TYPE_INT, CALI_ATTR_NESTED); Attribute nested_b = c.create_attribute("test.attr.nested.b", CALI_TYPE_INT, CALI_ATTR_NESTED); - Attribute nomerge = - c.create_attribute("test.attr.nomerge", CALI_TYPE_INT, CALI_ATTR_NESTED | CALI_ATTR_NOMERGE); EXPECT_TRUE(nested_a.is_nested()); EXPECT_TRUE(nested_a.is_autocombineable()); - EXPECT_TRUE(nomerge.is_nested()); - EXPECT_FALSE(nomerge.is_autocombineable()); c.begin(nested_a, Variant(16)); - c.begin(nomerge, Variant(25)); c.begin(nested_b, Variant(36)); const Node* node = c.get(nested_b).node(); @@ -133,18 +128,6 @@ TEST(AttributeAPITest, NestedAttribute) { EXPECT_EQ(node->attribute(), nested_a.id()); EXPECT_EQ(node->data().to_int(), 16); - node = c.get(nomerge).node(); - - ASSERT_NE(node, nullptr); - EXPECT_EQ(node->attribute(), nomerge.id()); - EXPECT_EQ(node->data().to_int(), 25); - - // nomerge attribute should have hidden root node as parent even though it's nested - node = node->parent(); - ASSERT_NE(node, nullptr); - EXPECT_EQ(node->attribute(), CALI_INV_ID); - c.end(nested_b); - c.end(nomerge); c.end(nested_a); } diff --git a/src/services/CMakeLists.txt b/src/services/CMakeLists.txt index 99944840b..b8b82be9f 100644 --- a/src/services/CMakeLists.txt +++ b/src/services/CMakeLists.txt @@ -76,9 +76,6 @@ if (CALIPER_HAVE_GOTCHA) add_subdirectory(pthread) add_subdirectory(sysalloc) endif() -# if (CALIPER_HAVE_SOS) -# add_subdirectory(sos) -# endif() add_subdirectory(recorder) add_subdirectory(report) if (CALIPER_HAVE_SAMPLER) diff --git a/src/services/callpath/Callpath.cpp b/src/services/callpath/Callpath.cpp index b5577652d..7f6b70785 100644 --- a/src/services/callpath/Callpath.cpp +++ b/src/services/callpath/Callpath.cpp @@ -202,14 +202,12 @@ class Callpath callpath_addr_attr = c->create_attribute("callpath.address", CALI_TYPE_ADDR, CALI_ATTR_SCOPE_THREAD | - CALI_ATTR_SKIP_EVENTS | - CALI_ATTR_NOMERGE, + CALI_ATTR_SKIP_EVENTS, 1, &symbol_class_attr, &v_true); callpath_name_attr = c->create_attribute("callpath.regname", CALI_TYPE_STRING, CALI_ATTR_SCOPE_THREAD | - CALI_ATTR_SKIP_EVENTS | - CALI_ATTR_NOMERGE); + CALI_ATTR_SKIP_EVENTS); #ifdef CALIPER_HAVE_LIBDW if (skip_internal) diff --git a/src/services/event/EventTrigger.cpp b/src/services/event/EventTrigger.cpp index 35c31a150..d33434886 100644 --- a/src/services/event/EventTrigger.cpp +++ b/src/services/event/EventTrigger.cpp @@ -50,6 +50,7 @@ class EventTrigger Attribute marker_attr { Attribute::invalid }; Attribute region_count_attr { Attribute::invalid }; + Entry region_count_entry; std::vector trigger_attr_names; @@ -265,8 +266,7 @@ class EventTrigger c->make_record(3, attrs, vals, trigger_info.builder(), &event_root_node); c->push_snapshot(chn, trigger_info.view()); } else { - Entry rcount { region_count_attr, cali_make_variant_from_uint(1) }; - c->push_snapshot(chn, SnapshotView(1, &rcount)); + c->push_snapshot(chn, SnapshotView(region_count_entry)); } } @@ -290,6 +290,7 @@ class EventTrigger CALI_ATTR_SKIP_EVENTS | CALI_ATTR_ASVALUE | CALI_ATTR_AGGREGATABLE); + region_count_entry = Entry(region_count_attr, cali_make_variant_from_uint(1)); ConfigSet cfg = services::init_config_from_spec(channel->config(), s_spec); diff --git a/src/services/sos/CMakeLists.txt b/src/services/sos/CMakeLists.txt deleted file mode 100644 index 445379695..000000000 --- a/src/services/sos/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -include_directories(${SOSFlow_INCLUDE_DIR}) - -set(CALIPER_SOS_SOURCES - Sos.cpp) - -add_library(caliper-sos OBJECT ${CALIPER_SOS_SOURCES}) - -add_service_objlib("caliper-sos") -add_caliper_service("sos CALIPER_HAVE_SOS") diff --git a/src/services/sos/README.md b/src/services/sos/README.md deleted file mode 100644 index 54abd99ed..000000000 --- a/src/services/sos/README.md +++ /dev/null @@ -1,15 +0,0 @@ -SOS Service --------------------------------- - -The SOS service publishes Caliper trace or aggregation data into SOS_flow. -Data will be published on the end event for the attribute selected by -CALI_SOS_TRIGGER_ATTR. - -For example, with the following configuration, Caliper will export its -aggregation database after each iteration of cali-basic's main loop:: - -``` - $ CALI_SERVICES_ENABLE=aggregate:event:sos:timestamp \ - CALI_SOS_TRIGGER_ATTR="iteration#mainloop" \ - CALI_LOG_VERBOSITY=2 ./test/cali-basic -``` diff --git a/src/services/sos/Sos.cpp b/src/services/sos/Sos.cpp deleted file mode 100644 index af4545e43..000000000 --- a/src/services/sos/Sos.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Sos.cpp -// Caliper Sos Integration Service - -#include "caliper/CaliperService.h" - -#include "caliper/Caliper.h" -#include "caliper/SnapshotRecord.h" - -#include "caliper/common/Log.h" -#include "caliper/common/RuntimeConfig.h" -#include "caliper/common/SnapshotTextFormatter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace cali; -using namespace std; - -namespace -{ - -static std::atomic snapshot_id { 0 }; - -const ConfigSet::Entry configdata[] = { - { "trigger_attr", CALI_TYPE_STRING, "", - "Attribute that triggers flush & publish", - "Attribute that triggers flush & publish" - }, - ConfigSet::Terminator -}; - -// Takes an unpacked Caliper snapshot and publishes it in SOS -void pack_snapshot(SOS_pub* sos_pub, bool yn_publish, int snapshot_id, const std::map< Attribute, std::vector >& unpacked_snapshot) { - for (auto &p : unpacked_snapshot) { - switch (p.first.type()) { - case CALI_TYPE_STRING: - { - std::string pubstr; - - for (const Variant &val : p.second) - pubstr.append(val.to_string()).append(pubstr.empty() ? "" : "/"); - - SOS_pack_related(sos_pub, snapshot_id, p.first.name_c_str(), SOS_VAL_TYPE_STRING, pubstr.c_str()); - } - break; - case CALI_TYPE_ADDR: - case CALI_TYPE_INT: - case CALI_TYPE_UINT: - case CALI_TYPE_BOOL: - { - int64_t val = p.second.front().to_int(); - SOS_pack_related(sos_pub, snapshot_id, p.first.name_c_str(), SOS_VAL_TYPE_INT, &val); - } - break; - case CALI_TYPE_DOUBLE: - { - double val = p.second.front().to_double(); - SOS_pack_related(sos_pub, snapshot_id, p.first.name_c_str(), SOS_VAL_TYPE_DOUBLE, &val); - } - default: - ; - } - } - if (yn_publish == true) { - SOS_publish(sos_pub); - } - - return; -} - -class SosService -{ - ConfigSet config; - static unique_ptr - s_sos; - - SOS_runtime *sos_runtime; - SOS_pub *sos_publication_handle; - - Attribute trigger_attr; - - void flush_and_publish(Caliper* c) { - Log(2).stream() << "sos: Publishing Caliper data" << std::endl; - - c->flush(nullptr, [this,c](const SnapshotRecord* snapshot){ - pack_snapshot(sos_publication_handle, false, ++snapshot_id, snapshot->unpack(*c)); - return true; - }); - SOS_publish(sos_publication_handle); - c->clear(); //Avoids re-publishing snapshots. - } - - void create_attr(const Attribute& attr) { - if (attr.name() == config.get("trigger_attr").to_string()) - trigger_attr = attr; - } - - void process_snapshot(Caliper* c, const SnapshotRecord* trigger_info, const SnapshotRecord* snapshot) { - pack_snapshot(sos_publication_handle, false, ++snapshot_id, snapshot->unpack(*c)); - } - - void post_end(Caliper* c, const Attribute& attr) { - if (trigger_attr != Attribute::invalid && attr.id() == trigger_attr.id()) - flush_and_publish(c); - } - - // Initialize the SOS runtime, and create our publication handle - void post_init(Caliper* c) { - sos_runtime = NULL; - sos_publication_handle = NULL; - // - SOS_init(&sos_runtime, SOS_ROLE_CLIENT, SOS_RECEIVES_NO_FEEDBACK, NULL); - SOS_pub_init(sos_runtime, &sos_publication_handle, "caliper.data", SOS_NATURE_DEFAULT); - - // trigger_attr will be invalid if it's not found - still need to check attributes in create_attribute_cb - trigger_attr = c->get_attribute(config.get("trigger_attr").to_string()); - } - - // static callbacks - - static void create_attr_cb(Caliper*, const Attribute& attr) { - s_sos->create_attr(attr); - } - - static void process_snapshot_cb(Caliper* c, const SnapshotRecord* trigger_info, const SnapshotRecord* snapshot) { - s_sos->process_snapshot(c, trigger_info, snapshot); - } - - static void post_end_cb(Caliper* c, const Attribute& attr, const Variant& val) { - s_sos->post_end(c, attr); - } - - static void post_init_cb(Caliper* c) { - s_sos->post_init(c); - } - - SosService(Caliper* c) - : config(RuntimeConfig::init("sos", configdata)), - trigger_attr(Attribute::invalid) - { - - c->events().create_attr_evt.connect(&SosService::create_attr_cb); - c->events().post_init_evt.connect(&SosService::post_init_cb); - // c->events().process_snapshot.connect(&SosService::process_snapshot_cb); - c->events().post_end_evt.connect(&SosService::post_end_cb); - - Log(1).stream() << "Registered SOS service" << std::endl; - } - -public: - - static void sos_register(Caliper* c) { - s_sos.reset(new SosService(c)); - } - -}; // SosService - -unique_ptr SosService::s_sos { nullptr }; - -} // namespace - -namespace cali -{ - CaliperService sos_service = { "sos", ::SosService::sos_register }; -} // namespace cali diff --git a/test/ci_app_tests/ci_test_alloc.c b/test/ci_app_tests/ci_test_alloc.c index 38ddd5721..eafd59290 100644 --- a/test/ci_app_tests/ci_test_alloc.c +++ b/test/ci_app_tests/ci_test_alloc.c @@ -23,8 +23,8 @@ void ci_test_alloc() cali_create_attribute_with_metadata("ptr_out", CALI_TYPE_ADDR, CALI_ATTR_ASVALUE, 1, &cali_class_memoryaddress_attr_id, &v_true); - int *A = - cali_datatracker_allocate_dimensional("test_alloc_A", sizeof(int), (const size_t[]) { 42 }, 1); + int *A = (int*) malloc(42 * sizeof(int)); + cali_datatracker_track_dimensional(A, "test_alloc_A", sizeof(int), (const size_t[]) { 42 }, 1); cali_id_t attrs[2] = { ptr_in_attr, ptr_out_attr }; int scope = CALI_SCOPE_PROCESS | CALI_SCOPE_THREAD; @@ -52,7 +52,9 @@ void ci_test_alloc() cali_push_snapshot(scope, 2, attrs, (const cali_variant_t[]) { v_p_i, v_p_o }); cali_end_byname("test_alloc.allocated.1"); - cali_datatracker_free(A); + cali_datatracker_untrack(A); + free(A); + A = NULL; cali_begin_byname("test_alloc.freed"); cali_push_snapshot(scope, 2, attrs, (const cali_variant_t[]) { v_p_i, v_p_o }); diff --git a/test/ci_app_tests/ci_test_c_ann.c b/test/ci_app_tests/ci_test_c_ann.c index fcdcefc6b..8eeb80086 100644 --- a/test/ci_app_tests/ci_test_c_ann.c +++ b/test/ci_app_tests/ci_test_c_ann.c @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) cali_make_variant_from_int(47); cali_id_t test_attr = - cali_create_attribute_with_metadata("test-attr-with-metadata", CALI_TYPE_STRING, CALI_ATTR_NOMERGE, + cali_create_attribute_with_metadata("test-attr-with-metadata", CALI_TYPE_STRING, CALI_ATTR_UNALIGNED, 1, &meta_attr, &meta_val); cali_set_string(test_attr, "abracadabra");