Skip to content

Commit

Permalink
Current reproducer for Caliper vs Variorum energy reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
tpatki committed Aug 2, 2024
1 parent 5a95664 commit e13c1d0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions examples/apps/patki-example.c
Original file line number Diff line number Diff line change
@@ -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 <configuration-string>
// For example, "$ cali-basic-annotations runtime-report" will print a
// hierarchical runtime summary for all annotated regions.

#include <caliper/cali.h>

#include <stdio.h>
#include <unistd.h>
#include <string.h>

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");
}
22 changes: 14 additions & 8 deletions src/services/variorum/Variorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,27 @@ std::tuple<bool, uint64_t> 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);
Expand Down

0 comments on commit e13c1d0

Please sign in to comment.