Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Variorum power API with energy API #567

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ext/gotcha/src/gotcha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ext/gotcha/src/gotcha_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
75 changes: 43 additions & 32 deletions src/services/variorum/Variorum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,50 @@ using namespace cali;
namespace
{

// Power measurement function
// Energy measurement function
std::tuple<bool, uint64_t> 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);
double energy_joules;
json_t *node_obj = NULL;
json_t *energy_obj = NULL;
char *s = NULL;

s = (char *) malloc(800 * sizeof(char));

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
energy_obj = json_loads(s, JSON_DECODE_ANY, NULL);
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;

//Deallocate the string
free(s);

//Deallocate JSON object
json_decref(energy_obj);

return std::make_tuple(true, val);
}

// The VariorumService class reads a list of domains from the
Expand Down Expand Up @@ -321,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
};
Expand Down