From e13c1d0b801c2b01fa6796b9afe7e619ebe2e848 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Thu, 1 Aug 2024 18:03:31 -0700 Subject: [PATCH] Current reproducer for Caliper vs Variorum energy reporting --- examples/apps/CMakeLists.txt | 1 + examples/apps/patki-example.c | 50 ++++++++++++++++++++++++++++++ src/services/variorum/Variorum.cpp | 22 ++++++++----- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 examples/apps/patki-example.c diff --git a/examples/apps/CMakeLists.txt b/examples/apps/CMakeLists.txt index adb0548f8..9e561e249 100644 --- a/examples/apps/CMakeLists.txt +++ b/examples/apps/CMakeLists.txt @@ -13,6 +13,7 @@ set(CALIPER_MPI_EXAMPLE_APPS collective-output-channel) set(CALIPER_C_EXAMPLE_APPS c-example + patki-example cali-print-snapshot) set(CALIPER_Fortran_EXAMPLE_APPS fortran-example diff --git a/examples/apps/patki-example.c b/examples/apps/patki-example.c new file mode 100644 index 000000000..5f228fbec --- /dev/null +++ b/examples/apps/patki-example.c @@ -0,0 +1,50 @@ +// Copyright (c) 2015-2022, Lawrence Livermore National Security, LLC. +// See top-level LICENSE file for details. + +// A C Caliper instrumentation and ConfigManager example + +// Usage: $ cali-basic-annotations +// For example, "$ cali-basic-annotations runtime-report" will print a +// hierarchical runtime summary for all annotated regions. + +#include + +#include +#include +#include + +void bar() +{ + printf("I'm in BAR, I doze off for a second.\n"); + CALI_MARK_FUNCTION_BEGIN; + sleep(1); + CALI_MARK_FUNCTION_END; + printf("Exit BAR. \n"); +} + +void foo() +{ + // A function annotation. Opens region "function=foo" in Caliper, + // and automatically closes it at the end of the function. + printf("I'm in a FOO, I work hard!\n"); + CALI_MARK_FUNCTION_BEGIN; + long double res=0.1; + int i; + for (i=0;i<1000000;i++) + res += res * i; + CALI_MARK_FUNCTION_END; + printf("Exit FOO. \n"); +} + +int main(int argc, char* argv[]) +{ + // Mark begin of the current function. Must be manually closed. + // Opens region "function=main" in Caliper. + printf("Hello World\n"); + CALI_MARK_FUNCTION_BEGIN; + //foo(); + //bar(); + // Mark the end of the "function=main" region. + CALI_MARK_FUNCTION_END; + printf("Exit Main.\n"); +} diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 1f807a9d1..59ee31c9d 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -46,21 +46,27 @@ std::tuple measure(const std::string& name) return std::make_tuple(false, val); } - //Extract and print values from JSON object + //Extract the values from JSON object energy_obj = json_loads(s, JSON_DECODE_ANY, NULL); void *iter = json_object_iter(energy_obj); while (iter) { - node_obj = json_object_iter_value(iter); - if (node_obj == NULL) - { - printf("JSON object not found"); - exit(0); - } + node_obj = json_object_iter_value(iter); + if (node_obj == NULL) + { + printf("JSON object not found."); + exit(0); + } /* The following should return NULL after the first call per our object. */ iter = json_object_iter_next(energy_obj, iter); - } + + } + + puts(s); + // Parse the data from the JSON object. + energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); + printf("\n QQQ: Value is: %lu\n", energy_joules); //Deallocate the string free(s);