From 75268cb70d656b96af03df1002b63a8b7abf5246 Mon Sep 17 00:00:00 2001 From: Tre' Jeter Date: Mon, 24 Jun 2024 14:20:57 -0700 Subject: [PATCH 01/17] Updated Variorum service with energy API --- src/services/variorum/Variorum.cpp | 80 +++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 05106cd79..d4d48f7db 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -30,41 +30,73 @@ using namespace cali; namespace { -// Power measurement function +// Energy measurement function std::tuple measure(const std::string& name) { - double power_watts; - json_t *power_obj = NULL; - char *s = NULL; + double energy_joules; + json_t *energy_obj = NULL; + char *s = NULL; - s = (char *) malloc(800 * sizeof(char)); + s = (char *) malloc(800 * sizeof(char)); - int ret = variorum_get_node_power_json(&s); - if (ret != 0) - { - std::cout << "Variorum JSON API failed" << std::endl; - uint64_t val; - return std::make_tuple(false, val); - } - - // TODO: Add error if name is an invalid JSON field - // TODO: Assume 1 rank/node for aggregation + int ret = variorum_get_energy_json(&s); + if (ret != 0) + { + std::cout << "Variorum Energy JSON API failed!" << std::endl; + uint64_t val; + return std::make_tuple(false, val); + } - // Extract and print values from JSON object - power_obj = json_loads(s, JSON_DECODE_ANY, NULL); - power_watts = json_real_value(json_object_get(power_obj, name.c_str())); + //Extract and print values from JSON object + energy_obj = json_loads(s, JSON_DECODE_ANY, NULL); + energy_joules = json_real_value(json_object_get(energy_obj, name.c_str())); - uint64_t val = (uint64_t)power_watts; + uint64_t val = (uint64_t)energy_joules; - // Deallocate the string - free(s); + //Deallocate the string + free(s); - // Deallocate JSON object - json_decref(power_obj); + //Deallocate JSON object + json_decref(energy_obj); - return std::make_tuple(true, val); + return std::make_tuple(true, val); } +//// Power measurement function +//std::tuple measure(const std::string& name) +//{ +// double power_watts; +// json_t *power_obj = NULL; +// char *s = NULL; +// +// s = (char *) malloc(800 * sizeof(char)); +// +// int ret = variorum_get_node_power_json(&s); +// if (ret != 0) +// { +// std::cout << "Variorum JSON API failed" << std::endl; +// uint64_t val; +// return std::make_tuple(false, val); +// } +// +// // TODO: Add error if name is an invalid JSON field +// // TODO: Assume 1 rank/node for aggregation +// +// // Extract and print values from JSON object +// power_obj = json_loads(s, JSON_DECODE_ANY, NULL); +// power_watts = json_real_value(json_object_get(power_obj, name.c_str())); +// +// uint64_t val = (uint64_t)power_watts; +// +// // Deallocate the string +// free(s); +// +// // Deallocate JSON object +// json_decref(power_obj); +// +// return std::make_tuple(true, val); +//} + // The VariorumService class reads a list of domains from the // CALI_VARIORUM_DOMAINS config variable. For each domain, it appends a // "measurement.val." entry (absolute value for a performance From a24de03d9f11e7c320ab312b511157c6973d348e Mon Sep 17 00:00:00 2001 From: Tre' Jeter Date: Wed, 26 Jun 2024 11:46:20 -0700 Subject: [PATCH 02/17] Updated "gotcha" files. Loaded proper compiler. --- ext/gotcha/src/gotcha.c | 6 ++++-- ext/gotcha/src/gotcha_dl.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/gotcha/src/gotcha.c b/ext/gotcha/src/gotcha.c index 480c1819f..da1c74783 100644 --- a/ext/gotcha/src/gotcha.c +++ b/ext/gotcha/src/gotcha.c @@ -239,7 +239,8 @@ struct Boundary { int find_relro_boundary(struct dl_phdr_info *info, size_t size, void *data) { struct Boundary *boundary = data; int found = 0; - for (int i = 0; i < info->dlpi_phnum; ++i) { + int i = 0; + for (i = 0; i < info->dlpi_phnum; ++i) { if (info->dlpi_phdr[i].p_type == PT_LOAD) { if (strcmp(boundary->l_name, info->dlpi_name) == 0 && boundary->load_addr == info->dlpi_addr) { @@ -249,7 +250,8 @@ int find_relro_boundary(struct dl_phdr_info *info, size_t size, void *data) { } } if (found) { - for (int i = 0; i < info->dlpi_phnum; ++i) { + int i = 0; + for (i = 0; i < info->dlpi_phnum; ++i) { if (info->dlpi_phdr[i].p_type == PT_GNU_RELRO) { boundary->start_addr = boundary->load_addr + info->dlpi_phdr[i].p_vaddr; boundary->end_addr = boundary->start_addr + info->dlpi_phdr[i].p_memsz; diff --git a/ext/gotcha/src/gotcha_dl.c b/ext/gotcha/src/gotcha_dl.c index 16e55b579..7f873b186 100644 --- a/ext/gotcha/src/gotcha_dl.c +++ b/ext/gotcha/src/gotcha_dl.c @@ -30,7 +30,8 @@ int lib_header_callback(struct dl_phdr_info *info, size_t size, void *data) { struct Addrs *addrs = data; const char *name = NULL; ElfW(Addr) load_address; - for (int i = 0; i < info->dlpi_phnum; ++i) { + int i = 0; + for (i = 0; i < info->dlpi_phnum; ++i) { if (info->dlpi_phdr[i].p_type == PT_LOAD) { ElfW(Addr) base_addr = info->dlpi_addr; ElfW(Addr) start_addr = base_addr + info->dlpi_phdr[i].p_vaddr; From 943b587040a613ab70516306be435563c266d48b Mon Sep 17 00:00:00 2001 From: Tre' Jeter Date: Wed, 26 Jun 2024 20:34:24 -0700 Subject: [PATCH 03/17] Removed original power measurement code --- src/services/variorum/Variorum.cpp | 35 ------------------------------ 1 file changed, 35 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index d4d48f7db..cbbc0fd3e 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -62,41 +62,6 @@ std::tuple measure(const std::string& name) return std::make_tuple(true, val); } -//// Power measurement function -//std::tuple measure(const std::string& name) -//{ -// double power_watts; -// json_t *power_obj = NULL; -// char *s = NULL; -// -// s = (char *) malloc(800 * sizeof(char)); -// -// int ret = variorum_get_node_power_json(&s); -// if (ret != 0) -// { -// std::cout << "Variorum JSON API failed" << std::endl; -// uint64_t val; -// return std::make_tuple(false, val); -// } -// -// // TODO: Add error if name is an invalid JSON field -// // TODO: Assume 1 rank/node for aggregation -// -// // Extract and print values from JSON object -// power_obj = json_loads(s, JSON_DECODE_ANY, NULL); -// power_watts = json_real_value(json_object_get(power_obj, name.c_str())); -// -// uint64_t val = (uint64_t)power_watts; -// -// // Deallocate the string -// free(s); -// -// // Deallocate JSON object -// json_decref(power_obj); -// -// return std::make_tuple(true, val); -//} - // The VariorumService class reads a list of domains from the // CALI_VARIORUM_DOMAINS config variable. For each domain, it appends a // "measurement.val." entry (absolute value for a performance From 10e0873f279b3e4839b10544dcad46e63b08993c Mon Sep 17 00:00:00 2001 From: Tre' Jeter Date: Mon, 29 Jul 2024 11:09:02 -0700 Subject: [PATCH 04/17] Aiming to reproduce errors --- src/services/variorum/Variorum.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index cbbc0fd3e..8a0ee12d4 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -34,6 +34,7 @@ namespace std::tuple measure(const std::string& name) { double energy_joules; + json_t *node_obj = NULL; json_t *energy_obj = NULL; char *s = NULL; @@ -49,7 +50,20 @@ std::tuple measure(const std::string& name) //Extract and print values from JSON object energy_obj = json_loads(s, JSON_DECODE_ANY, NULL); - energy_joules = json_real_value(json_object_get(energy_obj, name.c_str())); + void *iter = json_object_iter(energy_obj); + while (iter) + { + //hostname = json_object_iter_key(iter); + 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); + } + energy_joules = json_real_value(json_object_get(node_obj, name.c_str())); uint64_t val = (uint64_t)energy_joules; @@ -318,7 +332,7 @@ const ConfigSet::Entry VariorumService::s_configdata[] = { "List of domains to record", // short description // long description "List of domains to record (separated by ',')\n" - "Example: power_node_watts, power_socket_watts, power_gpu_watts, power_mem_watts" + "Example: energy_node_joules" }, ConfigSet::Terminator }; From d9f4041aecf2f0bb8181d6d2feaeeb3d839237d1 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Thu, 1 Aug 2024 15:07:18 -0700 Subject: [PATCH 05/17] Need to use JSON integer for parsing --- src/services/variorum/Variorum.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 8a0ee12d4..fd9ff086a 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -33,12 +33,15 @@ namespace // Energy measurement function std::tuple measure(const std::string& name) { - double energy_joules; + uint64_t energy_joules; json_t *node_obj = NULL; json_t *energy_obj = NULL; char *s = NULL; - s = (char *) malloc(800 * sizeof(char)); + s = (char *) malloc(10000 * sizeof(char)); + + if (s==NULL) + printf("\n Something wrong with malloc.\n"); int ret = variorum_get_energy_json(&s); if (ret != 0) @@ -63,9 +66,17 @@ std::tuple measure(const std::string& name) /* The following should return NULL after the first call per our object. */ iter = json_object_iter_next(energy_obj, iter); } - energy_joules = json_real_value(json_object_get(node_obj, name.c_str())); - uint64_t val = (uint64_t)energy_joules; + /*Patki dump values to screen */ + if (json_object_get(node_obj, "energy_node_watts") != NULL) + { + energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); + printf("Node Energy: %lu Joules\n", energy_joules); + } + else + { + energy_joules = 0; + } //Deallocate the string free(s); @@ -73,7 +84,7 @@ std::tuple measure(const std::string& name) //Deallocate JSON object json_decref(energy_obj); - return std::make_tuple(true, val); + return std::make_tuple(true, energy_joules); } // The VariorumService class reads a list of domains from the From a5ebb1def7909681b2c8c1151192cf1846f54ef0 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Thu, 1 Aug 2024 15:26:48 -0700 Subject: [PATCH 06/17] We don't need to malloc the string --- src/services/variorum/Variorum.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index fd9ff086a..032e9357e 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -38,11 +38,6 @@ std::tuple measure(const std::string& name) json_t *energy_obj = NULL; char *s = NULL; - s = (char *) malloc(10000 * sizeof(char)); - - if (s==NULL) - printf("\n Something wrong with malloc.\n"); - int ret = variorum_get_energy_json(&s); if (ret != 0) { From 5a956644a74979951b30d9a5f3156e9bd3d65df0 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Thu, 1 Aug 2024 15:59:50 -0700 Subject: [PATCH 07/17] Cleanup some debug printfs --- src/services/variorum/Variorum.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 032e9357e..1f807a9d1 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -51,28 +51,17 @@ std::tuple measure(const std::string& name) void *iter = json_object_iter(energy_obj); while (iter) { - //hostname = json_object_iter_key(iter); 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); } - /*Patki dump values to screen */ - if (json_object_get(node_obj, "energy_node_watts") != NULL) - { - energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); - printf("Node Energy: %lu Joules\n", energy_joules); - } - else - { - energy_joules = 0; - } - //Deallocate the string free(s); @@ -325,7 +314,7 @@ class VariorumService delete instance; }); - Log(1).stream() << channel->name() << ": Registered variorum service" + Log(1).stream() << channel->name() << ": Registered variorum service." << std::endl; } }; @@ -335,7 +324,7 @@ const ConfigSet::Entry VariorumService::s_configdata[] = { "domains", // config variable name CALI_TYPE_STRING, // datatype "", // default value - "List of domains to record", // short description + "List of domains to record.", // short description // long description "List of domains to record (separated by ',')\n" "Example: energy_node_joules" From 06ee911f4bcfa88481c6463d35f6ea6b5a4886e6 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Thu, 1 Aug 2024 18:30:59 -0700 Subject: [PATCH 08/17] Remove any debuggind related print statements. --- src/services/variorum/Variorum.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 1f807a9d1..468d1a071 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -46,21 +46,24 @@ 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); - } + + } + + energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); //Deallocate the string free(s); From f4ccc82f5f7edbb6b48ae67437c2413cb193378c Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 15:05:25 -0700 Subject: [PATCH 09/17] Add a new spinloop based example with function begin/end markers for testing. --- examples/apps/CMakeLists.txt | 1 + examples/apps/c-spinloop-example.c | 48 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 examples/apps/c-spinloop-example.c diff --git a/examples/apps/CMakeLists.txt b/examples/apps/CMakeLists.txt index adb0548f8..bc0fb84c8 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 + c-spinloop-example cali-print-snapshot) set(CALIPER_Fortran_EXAMPLE_APPS fortran-example diff --git a/examples/apps/c-spinloop-example.c b/examples/apps/c-spinloop-example.c new file mode 100644 index 000000000..6c48ef49f --- /dev/null +++ b/examples/apps/c-spinloop-example.c @@ -0,0 +1,48 @@ +// 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 + +#define LARGE_NUM 100000000 + +void bar() +{ + printf("Enter Bar. Sleep for a second.\n"); + CALI_MARK_FUNCTION_BEGIN; + sleep(1); + CALI_MARK_FUNCTION_END; + printf("Exit Bar. \n"); +} + +void foo() +{ + printf("Enter Foo. Run a long spinloop\n"); + CALI_MARK_FUNCTION_BEGIN; + long double res=0.1; + int i; + for (i=0;i<100000000;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. + CALI_MARK_FUNCTION_BEGIN; + printf("Hello World\n"); + foo(); + bar(); + // Mark the end of the current function + CALI_MARK_FUNCTION_END; +} From 9dca41d50153d3e392a172f6c7cdc4897cdd932b Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 15:43:21 -0700 Subject: [PATCH 10/17] Make the spinloop example simpler. --- examples/apps/c-spinloop-example.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/examples/apps/c-spinloop-example.c b/examples/apps/c-spinloop-example.c index 6c48ef49f..e82587ec0 100644 --- a/examples/apps/c-spinloop-example.c +++ b/examples/apps/c-spinloop-example.c @@ -15,22 +15,13 @@ #define LARGE_NUM 100000000 -void bar() -{ - printf("Enter Bar. Sleep for a second.\n"); - CALI_MARK_FUNCTION_BEGIN; - sleep(1); - CALI_MARK_FUNCTION_END; - printf("Exit Bar. \n"); -} - void foo() { printf("Enter Foo. Run a long spinloop\n"); CALI_MARK_FUNCTION_BEGIN; long double res=0.1; int i; - for (i=0;i<100000000;i++) + for (i=0;i<1000000000;i++) res += res * i; CALI_MARK_FUNCTION_END; printf("Exit Foo. \n"); @@ -42,7 +33,6 @@ int main(int argc, char* argv[]) CALI_MARK_FUNCTION_BEGIN; printf("Hello World\n"); foo(); - bar(); // Mark the end of the current function CALI_MARK_FUNCTION_END; } From 2b34192c3e31db4a745a7800adc4b4182ae8268c Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 15:43:36 -0700 Subject: [PATCH 11/17] Some minor edits to Readme. --- src/services/variorum/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/variorum/README.md b/src/services/variorum/README.md index 3fe1b371f..9d5b42bfb 100644 --- a/src/services/variorum/README.md +++ b/src/services/variorum/README.md @@ -1,14 +1,16 @@ Variorum Service ================ -The Variorum service implements a monitoring service of power usage at runtime. +The Variorum service implements a monitoring service of energy usage at runtime. It implements the `snapshot` callback for adding data to Caliper snapshot -records. +records. Minimum Variorum version is v0.8. With the following configuration, Caliper will export its data to a cali file: ``` $ CALI_SERVICES_ENABLE=aggregate,event,variorum,recorder \ - CALI_VARIORUM_DOMAINS=power_node_watts \ + CALI_VARIORUM_DOMAINS=energy_node_joules \ ``` + +Nesting of Caliper markers is not supported yet in this service. From 395c63d351e2d50c69cc5c6653d741cdf1987547 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 18:16:08 -0700 Subject: [PATCH 12/17] Remove nesting, that doesn't work yet. --- examples/apps/c-spinloop-example.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/apps/c-spinloop-example.c b/examples/apps/c-spinloop-example.c index e82587ec0..295db7721 100644 --- a/examples/apps/c-spinloop-example.c +++ b/examples/apps/c-spinloop-example.c @@ -13,17 +13,15 @@ #include #include -#define LARGE_NUM 100000000 +#define LARGE_NUM 10000000 void foo() { printf("Enter Foo. Run a long spinloop\n"); - CALI_MARK_FUNCTION_BEGIN; long double res=0.1; - int i; - for (i=0;i<1000000000;i++) + uint64_t i; + for (i=0;i Date: Tue, 13 Aug 2024 18:55:26 -0700 Subject: [PATCH 13/17] Make example a simple spinloop --- examples/apps/c-spinloop-example.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/apps/c-spinloop-example.c b/examples/apps/c-spinloop-example.c index 295db7721..f29a6ae4e 100644 --- a/examples/apps/c-spinloop-example.c +++ b/examples/apps/c-spinloop-example.c @@ -13,24 +13,25 @@ #include #include -#define LARGE_NUM 10000000 +#define LARGE_NUM 50000000 void foo() { - printf("Enter Foo. Run a long spinloop\n"); + // Mark begin of the current function. Must be manually closed. + CALI_MARK_FUNCTION_BEGIN; + printf("Enter foo. Run a long spinloop\n"); long double res=0.1; uint64_t i; for (i=0;i Date: Tue, 13 Aug 2024 18:55:43 -0700 Subject: [PATCH 14/17] Update readme and add a note that nesting is unsupported. --- src/services/variorum/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/variorum/README.md b/src/services/variorum/README.md index 9d5b42bfb..6f705b497 100644 --- a/src/services/variorum/README.md +++ b/src/services/variorum/README.md @@ -4,6 +4,10 @@ Variorum Service The Variorum service implements a monitoring service of energy usage at runtime. It implements the `snapshot` callback for adding data to Caliper snapshot records. Minimum Variorum version is v0.8. +Nesting of Caliper markers is not supported yet in this service. + +To build with the Variorum service, set WITH_VARIORUM=On and +VARIORUM_PREFIX=. With the following configuration, Caliper will export its data to a cali file: @@ -13,4 +17,3 @@ data to a cali file: CALI_VARIORUM_DOMAINS=energy_node_joules \ ``` -Nesting of Caliper markers is not supported yet in this service. From a0f7406395747534c005b4469f5e6b25fa79d13d Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 18:56:08 -0700 Subject: [PATCH 15/17] Remove delta and prev_val, as these do not make sense. --- src/services/variorum/Variorum.cpp | 44 +----------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 468d1a071..2d8e5783e 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -89,10 +89,6 @@ class VariorumService { std::string domain; // Measurement name / ID Attribute value_attr; // Attribute for the measurement value - Attribute delta_attr; // Attribute for the delta value (difference - // since last snapshot) - Attribute prval_attr; // A hidden attribute to store the previous - // measurement value on the Caliper blackboard }; // Data for the configured measurement variables @@ -133,17 +129,8 @@ class VariorumService // Append measurement value to the snapshot record Variant v_val(cali_make_variant_from_uint(val)); - rec.append(m.value_attr, val); - // We store the previous measurement value on the Caliper thread - // blackboard so we can compute the difference since the last - // snapshot. Here, c->exchange() stores the current and returns - // the previous value. Compute the difference and append it. - // TODO: For aggregation, we use average power instead of - // difference. - Variant v_prev = c->exchange(m.prval_attr, v_val); - rec.append(m.delta_attr, cali_make_variant_from_uint((val + v_prev.to_uint())/2)); } } @@ -201,36 +188,7 @@ class VariorumService CALI_ATTR_ASVALUE | CALI_ATTR_SKIP_EVENTS | CALI_ATTR_AGGREGATABLE); - - // The delta attribute stores the difference of the measurement - // value since the last snapshot. We add the "aggregatable" - // property here, which lets Caliper aggregate these values - // automatically. - m.delta_attr = - c->create_attribute(std::string("variorum.") + domain, - CALI_TYPE_UINT, - CALI_ATTR_SCOPE_THREAD | - CALI_ATTR_ASVALUE | - CALI_ATTR_SKIP_EVENTS | - CALI_ATTR_AGGREGATABLE); - - // We use a hidden attribute to store the previous measurement - // for on Caliper's per-thread blackboard. This is a - // channel-specific attribute, so we encode the channel ID in the - // name. - // - // In case more thread-specific information must be stored, it is - // better to combine them in a structure and create a CALI_TYPE_PTR - // attribute for this thread info in the service instance. - m.prval_attr = - c->create_attribute(std::string("variorum.pv.") + std::to_string(channel->id()) + domain, - CALI_TYPE_UINT, - CALI_ATTR_SCOPE_THREAD | - CALI_ATTR_ASVALUE | - CALI_ATTR_HIDDEN | - CALI_ATTR_SKIP_EVENTS); - } - + } return m; } From c8c0b0df2e02e86ed9365624294f348ee3f0438a Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 19:05:57 -0700 Subject: [PATCH 16/17] Format with astyle. --- src/services/variorum/Variorum.cpp | 163 +++++++++++++++-------------- 1 file changed, 86 insertions(+), 77 deletions(-) diff --git a/src/services/variorum/Variorum.cpp b/src/services/variorum/Variorum.cpp index 2d8e5783e..bc4ccd08c 100644 --- a/src/services/variorum/Variorum.cpp +++ b/src/services/variorum/Variorum.cpp @@ -31,47 +31,47 @@ namespace { // Energy measurement function -std::tuple measure(const std::string& name) +std::tuple measure(const std::string &name) { - uint64_t energy_joules; - json_t *node_obj = NULL; - json_t *energy_obj = NULL; - char *s = NULL; - - int ret = variorum_get_energy_json(&s); - if (ret != 0) - { - std::cout << "Variorum Energy JSON API failed!" << std::endl; - uint64_t val; - return std::make_tuple(false, val); - } - - //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); - } - - /* The following should return NULL after the first call per our object. */ - iter = json_object_iter_next(energy_obj, iter); - - } - - energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); - - //Deallocate the string - free(s); - - //Deallocate JSON object - json_decref(energy_obj); - - return std::make_tuple(true, energy_joules); + uint64_t energy_joules; + json_t *node_obj = NULL; + json_t *energy_obj = NULL; + char *s = NULL; + + int ret = variorum_get_energy_json(&s); + if (ret != 0) + { + std::cout << "Variorum Energy JSON API failed!" << std::endl; + uint64_t val; + return std::make_tuple(false, val); + } + + //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); + } + + /* The following should return NULL after the first call per our object. */ + iter = json_object_iter_next(energy_obj, iter); + + } + + energy_joules = json_integer_value(json_object_get(node_obj, name.c_str())); + + //Deallocate the string + free(s); + + //Deallocate JSON object + json_decref(energy_obj); + + return std::make_tuple(true, energy_joules); } // The VariorumService class reads a list of domains from the @@ -97,10 +97,10 @@ class VariorumService // Number of measurement errors encountered at runtime unsigned m_num_errors; - void snapshot_cb(Caliper* c, - Channel* /*channel*/, + void snapshot_cb(Caliper *c, + Channel * /*channel*/, SnapshotView /*trigger_info*/, - SnapshotBuilder& rec) + SnapshotBuilder &rec) { // The snapshot callback triggers performance measurements. // Measurement services should make measurements and add them to the @@ -112,7 +112,7 @@ class VariorumService // handler. // Make measurements for all configured variables - for (const MeasurementInfo& m : m_info) + for (const MeasurementInfo &m : m_info) { bool success; uint64_t val; @@ -134,14 +134,14 @@ class VariorumService } } - void post_init_cb(Caliper* /*c*/, Channel* /*channel*/) + void post_init_cb(Caliper * /*c*/, Channel * /*channel*/) { // This callback is invoked when the channel is fully initialized // and ready to make measurements. This is a good place to initialize // measurement values, if needed. } - void finish_cb(Caliper* c, Channel* channel) + void finish_cb(Caliper *c, Channel *channel) { // This callback is invoked when the channel is being destroyed. // This is a good place to shut down underlying measurement libraries @@ -157,7 +157,8 @@ class VariorumService } } - MeasurementInfo create_measurement_info(Caliper* c, Channel* channel, const std::string& domain) + MeasurementInfo create_measurement_info(Caliper *c, Channel *channel, + const std::string &domain) { MeasurementInfo m; m.domain = domain; @@ -177,7 +178,8 @@ class VariorumService // events when using set/begin/end on this attribute. This attribute // is for absolute measurement values for . auto domainList = - channel->config().init("variorum", s_configdata).get("domains").to_stringlist(","); + channel->config().init("variorum", + s_configdata).get("domains").to_stringlist(","); for (auto &domain : domainList) { @@ -188,11 +190,11 @@ class VariorumService CALI_ATTR_ASVALUE | CALI_ATTR_SKIP_EVENTS | CALI_ATTR_AGGREGATABLE); - } + } return m; } - VariorumService(Caliper* c, Channel* channel) + VariorumService(Caliper *c, Channel *channel) : m_num_errors(0) { // Get the service configuration. This reads the configuration @@ -217,9 +219,9 @@ class VariorumService // Create a MeasurementInfo entry for each of the "measurement // variables" in the configuration. - for (const std::string& domain : domainList) + for (const std::string &domain : domainList) { - m_info.push_back( create_measurement_info(c, channel, domain) ); + m_info.push_back(create_measurement_info(c, channel, domain)); } } @@ -241,10 +243,11 @@ class VariorumService // any necessary objects like Caliper attributes, and register callback // functions. - static void register_variorum(Caliper* c, Channel* channel) + static void register_variorum(Caliper *c, Channel *channel) { auto domainList = - channel->config().init("variorum", s_configdata).get("domains").to_stringlist(","); + channel->config().init("variorum", + s_configdata).get("domains").to_stringlist(","); if (domainList.empty()) { @@ -255,40 +258,45 @@ class VariorumService } // Create a new service instance for this channel - VariorumService* instance = new VariorumService(c, channel); + VariorumService *instance = new VariorumService(c, channel); // Register callback functions using lambdas channel->events().post_init_evt.connect( - [instance](Caliper* c, Channel* channel){ - instance->post_init_cb(c, channel); - }); + [instance](Caliper * c, Channel * channel) + { + instance->post_init_cb(c, channel); + }); channel->events().snapshot.connect( - [instance](Caliper* c, Channel* channel, SnapshotView trigger_info, SnapshotBuilder& rec){ - instance->snapshot_cb(c, channel, trigger_info, rec); - }); + [instance](Caliper * c, Channel * channel, SnapshotView trigger_info, + SnapshotBuilder & rec) + { + instance->snapshot_cb(c, channel, trigger_info, rec); + }); channel->events().finish_evt.connect( - [instance](Caliper* c, Channel* channel){ - // This callback is invoked when the channel is destroyed. - // No other callback will be invoked afterwards. - // Delete the channel's service instance here! - instance->finish_cb(c, channel); - delete instance; - }); + [instance](Caliper * c, Channel * channel) + { + // This callback is invoked when the channel is destroyed. + // No other callback will be invoked afterwards. + // Delete the channel's service instance here! + instance->finish_cb(c, channel); + delete instance; + }); Log(1).stream() << channel->name() << ": Registered variorum service." << std::endl; } }; -const ConfigSet::Entry VariorumService::s_configdata[] = { +const ConfigSet::Entry VariorumService::s_configdata[] = +{ { - "domains", // config variable name - CALI_TYPE_STRING, // datatype - "", // default value - "List of domains to record.", // short description - // long description - "List of domains to record (separated by ',')\n" - "Example: energy_node_joules" + "domains", // config variable name + CALI_TYPE_STRING, // datatype + "", // default value + "List of domains to record.", // short description + // long description + "List of domains to record (separated by ',')\n" + "Example: energy_node_joules" }, ConfigSet::Terminator }; @@ -298,7 +306,8 @@ const ConfigSet::Entry VariorumService::s_configdata[] = { namespace cali { -CaliperService variorum_service = { +CaliperService variorum_service = +{ "variorum", ::VariorumService::register_variorum }; From f500569737ea6df85fddd4794a1600a9e751c9a9 Mon Sep 17 00:00:00 2001 From: Tapasya Patki Date: Tue, 13 Aug 2024 19:11:17 -0700 Subject: [PATCH 17/17] Format the example with astyle. --- examples/apps/c-spinloop-example.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/apps/c-spinloop-example.c b/examples/apps/c-spinloop-example.c index f29a6ae4e..7ebc88f95 100644 --- a/examples/apps/c-spinloop-example.c +++ b/examples/apps/c-spinloop-example.c @@ -20,16 +20,18 @@ void foo() // Mark begin of the current function. Must be manually closed. CALI_MARK_FUNCTION_BEGIN; printf("Enter foo. Run a long spinloop\n"); - long double res=0.1; + long double res = 0.1; uint64_t i; - for (i=0;i