Skip to content

Commit

Permalink
Bug fixing metric collection, and adjusting previous server-based fun…
Browse files Browse the repository at this point in the history
…ctions such that they can be used independent of R
  • Loading branch information
DylanKierans committed Jul 10, 2024
1 parent 0b6933f commit f8d2dec
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 336 deletions.
2 changes: 1 addition & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param collect_metrics Collect HWPC metrics via pmpmeas
#' @param flag_print_pids True to print pids of parent and child procs
#' @return <0 if error, 0 if R master, else >0 if child
init_otf2_logger <- function(max_nprocs, archivePath = "./rTrace", archiveName = "rTrace", collect_metrics = FALSE, flag_print_pids = FALSE) {
init_otf2_logger <- function(max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids) {
.Call('_rTrace_init_otf2_logger', PACKAGE = 'rTrace', max_nprocs, archivePath, archiveName, collect_metrics, flag_print_pids)
}

Expand Down
16 changes: 4 additions & 12 deletions R/r_instrument_hl.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ is_instrumentation_enabled <- function() {
}


## YOU ARE HERE
#' instrumentation_init
#' @description Create otf2 objs for instrumentation, and initiate global vars
#' @param flag_user_functions Boolean - TRUE to include user functions in dataframe
Expand All @@ -68,15 +67,16 @@ instrumentation_init <- function(flag_user_functions=T, collect_metrics=F, verbo
pkg.env$PRINT_SKIPS <- verbose_wrapping
pkg.env$INSTRUMENTATION_INIT <- TRUE

### YOU ARE HERE
## Interface to pmpmeas
pkg.env$COLLECT_METRICS <- collect_metrics
if (pkg.env$COLLECT_METRICS){
r_pmpmeas_init();
}

## Initiate new proc - close R if not Master
ret <- init_otf2_logger(parallelly::availableCores(), collect_metrics=pkg.env$COLLECT_METRICS) # Master R proc returns 0
ret <- init_otf2_logger(parallelly::availableCores(), "rTrace", "rTrace",
collect_metrics=pkg.env$COLLECT_METRICS,
flag_print_pids=F) # Master R proc returns 0
if (ret != 0){ quit(save="no"); } # Unintended fork R proc for otf2 logger

## Assign array on logger proc for regionRef of each func
Expand All @@ -102,7 +102,6 @@ is_instrumentation_init <- function() {
}


# @TODO: zmq this
#' instrumentation_finalize
#' @description Close otf2 objs for instrumentation
#' @export
Expand All @@ -117,22 +116,15 @@ instrumentation_finalize <- function()

## Ensure instrumententation disabled
if (is_instrumentation_enabled()){
warning("WARNING: Instrumentation currently enabled, will force disable before finalizing.")
instrumentation_disable()
}

warning("DEBUG: finalize_EvtWriter_client")
finalize_EvtWriter_client()
warning("DEBUG: complete finalize_EvtWriter_client")
warning("DEBUG: finalize_otf2_client")
finalize_otf2_client() # Hanging here!
warning("DEBUG: complete finalize_otf2_client")
finalize_otf2_client()

if (pkg.env$COLLECT_METRICS){
warning("DEBUG: r_pmpmeas_stop _finish")
r_pmpmeas_stop(1.0) # Might not be necessary
r_pmpmeas_finish()
warning("DEBUG: complete r_pmpmeas_stop _finish")
}
return(invisible(NULL))
}
Expand Down
8 changes: 4 additions & 4 deletions man/init_otf2_logger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/meas.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class Meas
_get(0);
}

// YOU ARE HERE - TODO remove copy operator on return
//inline std::vector<long long> read()
inline long long* read()
{
_read();
Expand Down Expand Up @@ -186,6 +184,15 @@ class Meas
const char *ret;
switch (_type())
{
case MeasType::TIME_BOOT:
ret = "time_boot";
break;
case MeasType::TIME_CPU:
ret = "time_cpu";
break;
case MeasType::TIME_THRD:
ret = "time_thrd";
break;
case (MeasType::PAPI):
ret = _papi.ename(i);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/perfinf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void PerfInf::stop(void)
}
}

// YOU ARE HERE
// YOU ARE HERE - NEW FUNCTION: Pause, read values, resume
// Compile with -DRTRACE_SUPPORT to replace writes to stderr
void PerfInf::pread(void)
{
if (_nevent > 0) {
Expand Down
14 changes: 2 additions & 12 deletions src/pmpmeas-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,9 @@ void pmpmeas_start(const char* tag)
pmpmeas__start(tag);
}

void pmpmeas_read_init(long long **vals, int *n)
Pmpmeas_vals pmpmeas_read()
{
pmpmeas__read_init(vals, n);
}

void pmpmeas_read(long long *vals)
{
pmpmeas__read(vals);
}

void pmpmeas_read_finalize()
{
pmpmeas__read_finalize();
return(pmpmeas__read());
}

void pmpmeas_stop(float weight)
Expand Down
6 changes: 3 additions & 3 deletions src/pmpmeas-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
#ifndef PMPMEAS_API_H
#define PMPMEAS_API_H

#include "pmpmeas.h"

#ifdef __cplusplus
extern "C" {
#endif

void pmpmeas_init();
void pmpmeas_start(const char*);
void pmpmeas_read_init(long long**, int*);
void pmpmeas_read(long long*);
void pmpmeas_read_finalize();
Pmpmeas_vals pmpmeas_read();
void pmpmeas_stop(float);
void pmpmeas_stop_fortran(float*);
void pmpmeas_finish();
Expand Down
52 changes: 10 additions & 42 deletions src/pmpmeas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
#include "pmpmeas.h"
#include "meas.h"
#include "utils.h"
//#include "rTrace.h"

using namespace std;
using namespace PMPMEAS;

// YOU ARE HERE
static list<MeasType*> pmpmeas_type_lst;
static list<Meas*> pmpmeas_meas_lst;
static list<Meas*> pmpmeas_match_lst;
list<MeasType*> pmpmeas_type_lst;
list<Meas*> pmpmeas_meas_lst;
list<Meas*> pmpmeas_match_lst;

int pmpmeas_meas_cnt_total;
long long *pmpmeas_meas_vals;
Expand Down Expand Up @@ -121,50 +121,18 @@ void pmpmeas__start(const char *tag)

}


// YOU ARE HERE
void pmpmeas__read_init(long long **vals, int *n)
{
bool tmp = pmpmeas_match_lst.empty();

if (pmpmeas_match_lst.empty())
for (list<MeasType*>::iterator mt = pmpmeas_type_lst.begin(); mt != pmpmeas_type_lst.end(); mt++)
{
Meas *m = new Meas("PLACEHOLDER", *(*mt));
pmpmeas_match_lst.push_back(m);
}

pmpmeas_meas_cnt_total=0;
for (list<Meas*>::iterator m = pmpmeas_match_lst.begin(); m != pmpmeas_match_lst.end(); m++)
pmpmeas_meas_cnt_total += (*m)->cnt();
pmpmeas_meas_vals = (long long *) malloc(pmpmeas_meas_cnt_total*sizeof(*pmpmeas_meas_vals));

*vals = pmpmeas_meas_vals;
*n = pmpmeas_meas_cnt_total;

if (tmp)
pmpmeas_match_lst.clear();

//printf("ncnt = %d\n", pmpmeas_meas_cnt_total); // DEBUGGING
}

// YOU ARE HERE
void pmpmeas__read(long long *vals)
// NEW FUNCTION: Read (without stopping if possible) metric values
Pmpmeas_vals pmpmeas__read()
{
Pmpmeas_vals vals;
int index = 0;
if (vals==NULL) // Default to global
vals = pmpmeas_meas_vals;

for (list<Meas*>::iterator m = pmpmeas_meas_lst.begin(); m != pmpmeas_meas_lst.end(); m++){
memcpy( &vals[index], (*m)->read(), (*m)->cnt()*sizeof(*pmpmeas_meas_vals));
memcpy( &(vals.data[index]), (*m)->read(), (*m)->cnt()*sizeof(long long));
index += (*m)->cnt();
}
}

// YOU ARE HERE
void pmpmeas__read_finalize()
{
free(pmpmeas_meas_vals);
vals.n = index;
return vals;
}

void pmpmeas__stop(float weight)
Expand Down
10 changes: 7 additions & 3 deletions src/pmpmeas.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
extern "C" {
#endif

// Struct used for storing temporary pmpmeas vals
typedef struct Pmpmeas_vals {
long long data[PAPICNTMAX+1];
int n;
} Pmpmeas_vals;

void pmpmeas__init();
void pmpmeas__start(const char*);
void pmpmeas__read_init(long long**, int*);
void pmpmeas__read(long long*);
void pmpmeas__read_finalize();
Pmpmeas_vals pmpmeas__read();
void pmpmeas__stop(float);
void pmpmeas__finish();

Expand Down
Loading

0 comments on commit f8d2dec

Please sign in to comment.